Submission #827404

#TimeUsernameProblemLanguageResultExecution timeMemory
827404Rayyan1108Fountain (eJOI20_fountain)C++17
30 / 100
516 ms524288 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> void print(ll Z) { cout << Z << endl; } struct threeVar { ll first, second, third; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll N, Q; cin >> N >> Q; pll arr[N+4]; vector<threeVar> V[N+2]; for(int i=1; i<=N; i++) { cin >> arr[i].first >> arr[i].second; V[i].push_back({arr[i].first, arr[i].second, i}); for(int j=1; j<i; j++) { if(arr[i].first > V[j].back().first) { if(!V[j].empty()) { V[j].push_back({arr[i].first, V[j].back().second + arr[i].second, i}); } } } } while(Q--) { ll X, Y; cin >> X >> Y; if(!V[X].empty()) { ll Z = V[X].back().second; if(Y > Z) { print(0); } else { ll ans = V[X][0].third; bool firstTime = 1; for(auto i: V[X]) { if(i.second < Y) { ans = i.third; } else if(i.second == Y) { ans = i.third; break; } else { if(firstTime) { firstTime = 0; ans = i.third; } else {break;} } } print(ans); } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...