#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<random>
#include<cmath>
#include<stack>
#include<map>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<ll>v,vis;
vector<vector<ll>>gp;
void solve(){
ll n,q; cin >> n >> q;
vector<ll>d(n),c(n),pref(n);
for(ll i=0;i<n;i++)cin >> d[i] >> c[i];
pref[0]=c[0];
for(ll i=1;i<n;i++){
pref[i]=pref[i-1]+c[i];
}
// for(ll i=0;i<n;i++){
// cout<<pref[i]<<" ";
// }
// cout<<endl;
for(ll i=0;i<q;i++){
ll a,b; cin >> a >> b;
--a;
if(a!=0){
a--;
ll k=lower_bound(pref.begin(),pref.end(),pref[a]+b)-pref.begin();
if(k==n)cout<<0<<endl;
else cout<<k+1<<endl;
}
else{
ll k=lower_bound(pref.begin(),pref.end(),b)-pref.begin();
if(k==n)cout<<0<<endl;
else cout<<k+1<<endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cin.tie(nullptr);
// ll _; cin >> _;
// while (_--){
solve();
// }
}
# |
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 |
186 ms |
3256 KB |
Output is correct |
2 |
Correct |
210 ms |
6368 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 |
- |