#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;
}
Compilation message
fountain.cpp: In function 'int a(std::vector<int>&, int, int&, std::vector<int>&, std::vector<int>&)':
fountain.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
61 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
10 ms |
332 KB |
Output is correct |
6 |
Correct |
8 ms |
332 KB |
Output is correct |
7 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1581 ms |
5888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
10 ms |
332 KB |
Output is correct |
6 |
Correct |
8 ms |
332 KB |
Output is correct |
7 |
Correct |
5 ms |
332 KB |
Output is correct |
8 |
Execution timed out |
1581 ms |
5888 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |