#include<bits/stdc++.h>
using namespace std;
int main()
{
long long N, Q; cin >> N >> Q;
vector<pair<long long, long long>> Fountain = {{0, 0}};
for(int i = 0; i < N; i++){
long long Di, Ci; cin >> Di >> Ci;
Fountain.push_back({Di, Ci});
}
for(int i = 1; i <= N; i++){
Fountain[i].second += Fountain[i-1].second;
}
for(int i = 0; i < Q; i++){
long long Ri, Vi; cin >> Ri >> Vi;
int L = Ri - 1, R = N;
if(Vi > Fountain[N].second){
cout << 0 << '\n';
break;
}
while(L <= R){
long long Mid = (L + R) / 2;
if(Fountain[Mid].second - Fountain[Ri-1].second == Vi){
R = Mid - 1; L = Mid;
}
else if(Fountain[Mid].second - Fountain[Ri-1].second > Vi){
R = Mid - 1;
}
else{
L = Mid + 1;
}
}
cout << L << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
278 ms |
3708 KB |
Output is correct |
2 |
Correct |
309 ms |
5748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |