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>
using namespace std;
int main()
{
int n, q;
cin >> n >> q;
vector<int> d(n+1), c(n);
d[n] = 1000000001;
for(int i = 0; i < n; i++){
cin >> d[i] >> c[i];
}
if(n <= 1000 && q <= 2000){
int r, v;
for(int i = 0; i < q; i++){
cin >> r >> v;
int k = r-1, m = r-1;
v -= c[m];
while(v > 0 && m <= n && k < n){
if(d[m] > d[k]){
v -= c[m];
k = m;
}
m++;
}
if(k == n) cout << 0 << "\n";
else cout << k+1 << "\n";
}
}
else{
for(int i = n-2; i >= 0; i--){
c[i] += c[i+1];
}
for(int i = 0; i < q; i++){
int r, v;
cin >> r >> v;
if(c[r-1]-v >= 0 && c[r-1]-v < c[n-1]) cout << n << "\n";
else if(c[r-1]-v < 0) cout << 0 << "\n";
else{
int a = 0, b = n;
while(b - a > 1){
int m = (a+b)/2;
if(c[r-1]-v < c[m]) a = m;
else b = m;
}
cout << b << "\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... |