#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, p[N], 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;
tr = 1;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
if(y[i] >= y[i + 1])tr = 0;
}
if(tr == 1){
for(int i = 1; i <= n; i++){
p[i] = p[i - 1] + y[i];
}
while(q--){
cin >> c >> d;
h = 0;
int l = c, r = n;
while(l <= r){
int md = (l + r) / 2;
if(p[md] - p[c - 1] > d)r = md - 1;
else{
l = md + 1;;
h = md;
}
}
if(d > p[n] - p[c - 1])cout << 0 << '\n';
else cout << h << '\n';
}
return 0;
}
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... |