#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
4392 KB |
Output is correct |
2 |
Correct |
82 ms |
4492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |