#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define all(x) x.begin(),x.end()
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,q;
cin >> n >> q;
vector<ll> d(n+1,0),c(n+1,0),x(n+1,0);
for(int i=1;i<=n;i++) cin >> d[i] >> c[i];
x=c;
for(int i=1;i<n+1;i++) x[i]+=x[i-1];
if(n > 1000 || q > 2000){
while(q--){
int r,v;
cin >> r >> v;
v+=x[r-1];
int ans=lower_bound(x.begin()+1,x.end(),v)-x.begin();
cout << (ans > n ? 0:ans) << endl;
}
}
else{
while(q--){
int r,v;
cin >> r >> v;
int ans=0,idx=0;
for(int i=r;i<=n;i++){
ans++;
if(i != r){
if(d[i] <= d[idx]) continue;
}
idx=i;
v-=c[i];
//cout << v << endl;
if(v <= 0)break;
}
if(v > 0) ans++;
ans+=r-1;
cout << (ans > n ? 0:ans) << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
3312 KB |
Output is correct |
2 |
Correct |
68 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
61 ms |
3312 KB |
Output is correct |
9 |
Correct |
68 ms |
3192 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |