#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define MAX 1e18
#define per(i,a,b) for(ll int i=a;i<b;i++)
#define rep(i,a,b) for(ll int i=b;i>=a;i--)
#define scan(v,n) per(i,0,n){cin>>v[i];}
#define print(v,n) per(i,0,n){cout<<v[i]<<" ";}cout<<endl;
#define pb push_back
int main() {
int n,q;
cin>>n>>q;
vector<int>dia(n),cap(n);
per(i,0,n){cin>>dia[i]>>cap[i];}
vector<vector<int>>table(n,vector<int>(ceil(log2(n))));
per(i,0,n)table[i][0]=i;
for(int j=1;j<=ceil(log2(n));j++){
for(int i=0;i+(1<<j)<n;i++){
if(dia[table[i+(1<<(j-1))][j-1]]<dia[table[i][j-1]])table[i][j]=table[i][j-1];
else table[i][j] = table[i+(1<<(j-1))][j-1];
}
}
while(q--){
int from, c;
cin>>from>>c;
from--;
int curr = from;
while(c>0 && curr<n){
c-=cap[curr];
if(c>0){
int i= curr, j=0;
while(dia[i]==dia[curr]){
j++;
i = table[curr][j];
}
for(int k = curr+(1<<(j-1));k<=i;k++){
if(dia[curr]<dia[k]){curr = k;break;}
}
}
}
if(c<=0)cout<<curr+1<<endl;
else cout<<0<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1590 ms |
11208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |