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 <iostream>
#include <string>
#include <vector>
using namespace std;
int N, Q;
vector<long long int> d(N);
vector<long long int> c(N);
int a (vector <int>& litros, int k, int r, int v) {
for (int k=r+1; k<=N; k++) {
if (litros[k]>c[k]) {
for (int l=k+1; l<=N; l++) {
if (l==N) {
return 0;
}
if (d[l]>d[k]) {
v -= c[k];
litros[l]=v;
k = a (litros, l, r, v);
}
else {
return k;
}
}
}
}
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> Q;
cin >> d[0] >> c[0];
for(int i=1; i<N; i++){
cin >> d[i] >> c[i];
}
for (int j=0; j<Q; j++) {
int r, v;
cin >> r >> v;
vector <int> litros (N, 0);
litros[r-1]=v;
int k = r;
int resp = a (litros, k, r, v);
cout << resp << endl;
}
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... |