Algoogle

Algorithm for Programming Contest

PKU 2459 Feed Accounting

Category: PKU Tag: implementation

Feed Accounting

問題概要


解法


D日目からさかのぼって餌の消費量の和がF1-F2になる日を探せば良い

コード


(2459.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdio>

using namespace std;

int C, F1, F2, D, diff;
int cows[2048];

int main(){
    scanf("%d%d%d%d", &C, &F1, &F2, &D);
    diff = F1 - F2;
    for(int i = 0; i < C; i++){
        int s, t;
        scanf("%d%d", &s, &t);
        for(int j = s; j <= t; j++) cows[j]++;
    }
    int cur = D, sum = 0;
    while(1){
        sum += cows[cur];
        if(sum == diff) break;
        cur--;
    }
    printf("%d\n",cur);
    return 0;
}

Comments