#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
struct P1{
int start, extra;
};
struct P{
int volume, index;
};
vector<vector<P> > routes(1, vector<P> ());
int N, Q, v, d;
bool operator < (const P &a, int val){
return a.volume < val;
}
int main(){
cin >> N >> Q;
vector<P1> x(N + 1, {0, 0});
vector<int> diameters(N + 1, 0);
cin >> diameters[1] >> v;
x[1] = {1, 0};
routes.push_back(vector<P>());
routes[1].push_back({v, 1});
for(int i = 2; i <= N; ++i){
cin >> diameters[i] >> v;
bool ok = false;
for(int j = 1; j < routes.size(); ++j){
auto [V, s] = routes[j].back();
if(diameters[s] < diameters[i]){
ok = true;
if(x[i].start == 0)
x[i] = {j, V};
V += v;
routes[j].push_back({V, i});
}
}
if(!ok){
int p = routes.size();
x[i] = {p, 0};
routes.push_back(vector<P>(1, {v, i}));
}
}
int from, volume;
while(Q--){
cin >> from >> volume;
volume += x[from].extra;
from = x[from].start;
auto it = lower_bound(routes[from].begin(), routes[from].end(), volume);
cout << (it == routes[from].end() ? 0 : it -> index) << '\n';
}
return 0;
}
Compilation message
fountain.cpp: In function 'int main()':
fountain.cpp:37:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<P> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int j = 1; j < routes.size(); ++j){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
312 KB |
Output is correct |
6 |
Correct |
6 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
301 ms |
5808 KB |
Output is correct |
2 |
Correct |
325 ms |
6092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
312 KB |
Output is correct |
6 |
Correct |
6 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
340 KB |
Output is correct |
8 |
Correct |
301 ms |
5808 KB |
Output is correct |
9 |
Correct |
325 ms |
6092 KB |
Output is correct |
10 |
Correct |
5 ms |
304 KB |
Output is correct |
11 |
Execution timed out |
1566 ms |
256756 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |