#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
using namespace std;
const int mx = 1e6 + 15;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,q;
cin >> n >> q;
vector<pair<int,int>> a(n);//fist diamter , second is water
for (int i=0;i<n;i++){
cin >> a[i].first >> a[i].second;
}
if (n<=1000&&q<=2000){
while (q--){
int d,v;
cin >> d >> v;
d--;
int mx=a[d].first;
v-=a[d].second;
d++;
while(d<n&&v>0){
if (a[d].first > mx){
v-=a[d].second;
}
d++;
}
d<n?cout << d << endl:cout << 0 << endl;
}
}
else {
vector<ll> pref(n+1);
for (int i=1;i<=n;i++){
pref[i] = pref[i-1]+a[i-1].second;
}
while (q--){
int d,v;
cin >> d >> v;
ll num = pref[d-1];
int up = lower_bound(all(pref),num+v)-pref.begin();
up <= n ? cout << up <<endl : cout << 0 << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
2540 KB |
Output is correct |
2 |
Correct |
84 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |