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;
int f (int p, int n, vector<int> & s, int l) {
int x = s[p-1];
int lo = p, mid, hi = n, res = 0;
while (lo <= hi) {
mid = lo + (hi-lo) / 2;
if (s[mid] - x - l >= 0) {
hi = mid-1;
res = mid;
} else {
lo = mid+1;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, q, a, b, p, l, sum = 0;
cin >> n >> q;
vector<int> s(n+1);
s[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
sum += b;
s[i] = sum;
}
while (q--) {
cin >> p >> l;
cout << f(p, n, s, l) << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |