제출 #463481

#제출 시각아이디문제언어결과실행 시간메모리
463481QuentolosseFountain (eJOI20_fountain)C++14
0 / 100
346 ms1016 KiB
//sous-tache 2 #include <iostream> #include <vector> #include <algorithm> using namespace std; int dichotomie (int litres, int max, int min, vector<int>& reservoirs) { if (max - 1 == min) { return max; } else if (reservoirs[(max + min) / 2] > litres) { return dichotomie (litres, (max + min) / 2, min, reservoirs); } else { return dichotomie (litres, max, (max + min) / 2, reservoirs); } } int main () { int nbReservoirs, nbQuestions; pair<int,int> entree; vector<int> reservoirs; cin >> nbReservoirs >> nbQuestions; for (int i = 0; i < nbReservoirs; i++) { cin >> entree.first >> entree.second; reservoirs.push_back(entree.second); } for (int i = 0; i < nbReservoirs; i++) { reservoirs[i] += reservoirs[i+1]; } for (int question = 0; question < nbQuestions; question++) { int resultat; cin >> entree.first >> entree.second; if (entree.first != 1) { if (reservoirs[entree.first - 2] + entree.second <= reservoirs [nbReservoirs - 1]) { resultat = dichotomie (reservoirs[entree.first - 2] + entree.second, reservoirs.size() - 1, 0, reservoirs) + 1; } else { resultat = 0; } } else { if (entree.second <= reservoirs [nbReservoirs - 1]) { resultat = dichotomie (entree.second, reservoirs.size() - 1, 0, reservoirs) + 1; } else { resultat = 0; } } cout << resultat << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...