#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
#define fi first
#define se second
#define pb push_back
const int MOD = 1e9 + 7;
const int MAX = 2e5 + 5;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
#define int ll
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q; cin >> n >> q;
vector <pii> v;v.pb({0, 0});
for(int i = 1 ; i <= n ; i++){
int d, c; cin >> d >> c;
v.pb({d, c});
}
int pref[n + 5];pref[0] = 0;
for(int i = 1 ; i <= n ; i++)pref[i] = pref[i - 1] + v[i].se;
while(q--){
int st, ca; cin >> st >> ca;
// - pref[st - 1]
int l = st, r = n;
int ans = 0;
while(l <= r){
int mid = (l + r) >> 1;
if(ca <=pref[mid] - pref[st - 1]){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << ans << '\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |