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<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize("Ofast")
int32_t main () {
int n, q;
cin >> n >> q;
vector<int> d;
vector<int> c;
for(int i = 0;i<n;i++) {
int a, b;
cin >> a >> b;
d.push_back(a);
c.push_back(b);
}
while(q--) {
int i, v;
cin >> i >> v;
i--;
int prev = i;
while(v > 0 and i < n) {
if(prev == i)v-=c[i];
else if(d[i] >= d[prev]) {
v-=c[i];
prev = i;
}
i++;
}
if(v > 0)cout<<0<<endl;
else cout<<i<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |