# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
841826 | konber | Fountain (eJOI20_fountain) | C++14 | 70 ms | 5460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
vector<int> pref_sum;
int prefix_sum(int a, int b){
return pref_sum[b] - pref_sum[a-1];
}
int main()
{
//freopen("data.in", "r", stdin);
int N, Q, r, c, last, i;
scanf("%d%d", &N, &Q);
int d[N+1], v[N+1];
pref_sum.resize(N+1, 0);
bool order=true;
for(int j=1; j <= N; j++){
scanf("%d%d", &d[j], &v[j]);
pref_sum[j] = pref_sum[j-1] + v[j];
if(j>1 && d[j] <= d[j-1]) order=false;
}
if (N <= 1000 && Q <= 2000){
while(Q--){
scanf("%d%d", &r, &c);
last = r;
c -= v[r];
for(i=r; i <= N && c > 0; i++){
if(d[i] > d[last]){
c -= v[i];
last = i;
}
}
printf("%d\n", (c <= 0) ? last : 0);
}
}
else if(order){
while(Q--){
scanf("%d%d", &r, &c);
int first=r, last=N, mid, ans=0;
while(first <= last){
mid = (first+last)/2;
if(prefix_sum(r, mid) >= c){
ans=mid;
last=mid-1;
}
else first = mid+1;
}
printf("%d\n", ans);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |