#include <iostream>
#include <vector>
using namespace std;
struct reservoir{
int diameter = 0;
int capacity = 0;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int numReservoirs, numQueries;
cin >> numReservoirs >> numQueries;
vector<reservoir> fountain(numReservoirs);
for (int i = 0; i < numReservoirs; i++) {
cin >> fountain[i].diameter >> fountain[i].capacity;
}
int iReservoir, numLiters, iLastReservoir;
bool overflow = false;
for (int i = 0; i < numQueries; i++) {
overflow = false;
cin >> iReservoir >> numLiters;
iReservoir--;
iLastReservoir = iReservoir;
numLiters -= fountain[iReservoir].capacity;
iReservoir++;
if (numLiters <= 0) {
iReservoir--;
}
while (numLiters > 0) {
//cout << "iReservoir: " << iReservoir << " " << "numLiters: " << numLiters << " ";
if (iReservoir == numReservoirs) {
overflow = true;
break;
}
else if (fountain[iReservoir].diameter > fountain[iLastReservoir].diameter) {
//cout << fountain[iReservoir].diameter << "bigger than " << fountain[iLastReservoir].diameter << " ";
numLiters -= fountain[iReservoir].capacity;
if (numLiters <= 0) {
break;
}
iLastReservoir = iReservoir;
}
iReservoir++;
}
if (overflow) {
cout << 0 << "\n";
}
else cout << ++iReservoir << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1592 ms |
3352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Execution timed out |
1592 ms |
3352 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |