#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define sz size()
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pt pop_back
#define M 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
ll a[N], b, q, mx, mn, x[N], y[N], c, d, t, n, m, k, h, tr;
string s, g;
vector <ll> v;
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
}
while(q--){
cin >> c >> d;
h = 0;
b = 0;
for(int i = c; i <= n; i++){
if(x[i] >= h){
d -= y[i];
h = x[i];
b = i;
if(d <= 0)break;
}
}
if(d > 0)cout << 0 << '\n';
else cout << b << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |