# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388744 | Alexandra | Fountain (eJOI20_fountain) | Cpython 3 | 0 ms | 0 KiB |
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;
bool romper;
int resp;
int a (vector <int>& litros, int r, int& v, vector<int>& d, vector<int>& c) {
if (romper==true) {
return resp;
}
for (int k=r; k<=N; k++) {
if (romper==true) {
if (resp==r) {
resp = 0;
}
return resp;
break;
}
else {
if (litros[k]>c[k]) {
if (k==N-1) {
romper=true;
return 0;
break;
}
for (int l=k+1; l<=N; l++) {
if (l==N) {
break;
return 0;
}
else if (d[l]>d[k]) {
v -= c[k];
litros[l] = v;
k = a (litros, l, v, d, c);
break;
}
}
}
else {
romper=true;
resp = k+1;
if (resp==r) {
resp = 0;
}
return resp;
break;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> Q;
vector<int> d (N);
vector<int> c (N);
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;
romper = false;
cout << a (litros, r-1, v, d, c) << endl;
}
return 0;
}