#include <iostream>
#include <stack>
using namespace std;
int main(){
int32_t N, Q, level, volume;
cin >> N >> Q;
int32_t capacitys[N], diametrs[N], ng[N] {};
stack <int32_t> meowmeow;
for (int i = 0; i < N; i++){
cin >> diametrs[i] >> capacitys[i];
while (!meowmeow.empty() && diametrs[meowmeow.top()] < diametrs[i]){
ng[meowmeow.top()] = i;
meowmeow.pop();
}
meowmeow.push(i);
}
for (int32_t i = 0; i < Q; i++){
cin >> level >> volume;
level--;
do{
if (volume < capacitys[level] + 1){
level++;
break;
}
volume -= capacitys[level];
level = ng[level];
} while (level);
cout << level << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
8 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
204 KB |
Output is correct |
7 |
Correct |
8 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1582 ms |
1560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
8 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
204 KB |
Output is correct |
7 |
Correct |
8 ms |
308 KB |
Output is correct |
8 |
Execution timed out |
1582 ms |
1560 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |