#include<iostream>
using namespace std;
int d[100005];
int c[100005];
int ci[100005];
bool check(int r,int v,int x){
if(ci[x]-ci[r]<v) return true;
return false;
}
int main(){
int n,q;
cin>>n>>q;
for(int i=1;i<n+1;i++) cin>>d[i]>>c[i];
ci[1] = 0;
for(int i=2;i<=n;i++){
ci[i] = c[i-1]+ci[i-1];
}
ci[0] = ci[n-1]+c[n];
for(int e = 0;e<q;e++){
int r,v;
cin>>r>>v;
if(ci[0]-ci[r]<v) cout<<0<<endl;
else{
int l = r;
int r1 = n;
int cr = 0 ;
while(r1>=l){
int mid = (r1+l)/2;
if((r1+l)%2==1) mid++;
if(check(r,v,mid)){
l = mid+1;
cr = mid;
}
else{
r1 = mid-1;
}
}
cout<<cr<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
287 ms |
2120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |