This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long N, Q; cin >> N >> Q;
vector<pair<long long, long long>> Fountain;
for(int i = 0; i < N; i++){
long long Di, Ci; cin >> Di >> Ci;
Fountain.push_back({Di, Ci});
}
for(int i = 0; i < Q; i++){
long long Ri, Vi; cin >> Ri >> Vi;
long long LastD = 0;
for(int j = Ri-1; j < N; j++){
if(Ri == N){
cout << (Vi > Fountain[j].second ? 0 : j) << '\n';
break;
}
if(Fountain[j].first > LastD){
Vi -= Fountain[j].second;
LastD = Fountain[j].first;
}
if(Vi < 1){
cout << j + 1 << '\n';
break;
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |