This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//I Sawed the Demons
using ll = long long;
using ld = long double;
using ordered_set = tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>;
#define pb push_back
#define oo 1000000000000000000
#define ff first
#define ss second
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,q; cin >> n >> q;
vector<ll> d(n+1),c(n+1),pre(n+1);
for(int i=1;i<=n;++i) {
cin >> d[i] >> c[i];
}
pre[0]=0;
for(int i=1;i<=n;++i) {
pre[i]=pre[i-1]+c[i];
}
while(q--) {
ll r,v; cin >> r >> v;
if(v<=c[r]) {
cout << r << "\n"; continue;
}
v+=pre[r-1];
if(v>pre[n]) {
cout << "0\n"; continue;
}
auto it=(--upper_bound(pre.begin(),pre.end(),v));
if(*it == v) {
cout << it-pre.begin();
} else {
cout << it-pre.begin()+1;
}
cout << "\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... |