#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});
}
while(q--){
int st, ca; cin >> st >> ca;
int mx = 0;
int ans = 0;
for(int i = st ; i <= n ; i++){
if(v[i].fi > mx){
mx = v[i].fi;
ca -= v[i].se;
if(ca <= 0){
ans = i;
break;
}
}
}
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... |