#include<bits/stdc++.h>
using namespace std;
long find_next(vector<long> d, long i){
long orig = d[i];
for(int j = i + 1; j < d.size(); j++) if(d[j] > orig) return j;
return -1;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long n, q;
cin >> n >> q;
vector<long> d(n);
vector<int> c(n);
for(long i = 0; i < n; i++) cin >> d[i] >> c[i];
vector<vector<pair<long, long>>> paths(n, vector<pair<long, long>>());
long tmp;
for(long i = 0; i < n; i++){
tmp = i;
while(tmp != -1){
paths[i].push_back(pair<long, long>(c[tmp], tmp));
tmp = find_next(d, tmp);
}
paths[i].push_back(pair<long, long>(LONG_MAX, -1));
}
for(long i = 0; i < n; i++){
for(long j = 1; j < paths[i].size() - 1; j++){
paths[i][j].first += paths[i][j - 1].first;
}
}
long res, v;
long l, r, m;
for(long i = 0; i < q; i++){
cin >> res >> v;
res--;
l = 0;
r = paths[res].size() - 1;
while(l < r){
m = (l + r) / 2;
if(paths[res][m].first >= v) r = m;
else l = m + 1;
}
cout << paths[res][r].second + 1 << '\n';
}
return 0;
}
Compilation message
fountain.cpp: In function 'long int find_next(std::vector<long int>, long int)':
fountain.cpp:7:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | for(int j = i + 1; j < d.size(); j++) if(d[j] > orig) return j;
| ~~^~~~~~~~~~
fountain.cpp: In function 'int main()':
fountain.cpp:31:27: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(long j = 1; j < paths[i].size() - 1; j++){
| ~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
3 ms |
732 KB |
Output is correct |
5 |
Correct |
67 ms |
10608 KB |
Output is correct |
6 |
Correct |
27 ms |
4344 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1552 ms |
7808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
3 ms |
732 KB |
Output is correct |
5 |
Correct |
67 ms |
10608 KB |
Output is correct |
6 |
Correct |
27 ms |
4344 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Execution timed out |
1552 ms |
7808 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |