제출 #463540

#제출 시각아이디문제언어결과실행 시간메모리
463540QuentolosseFountain (eJOI20_fountain)C++14
0 / 100
376 ms1524 KiB
//sous-tache 2 #include <iostream> #include <vector> #include <algorithm> using namespace std; int dichotomie (int litres, int max, int min, int reservoirDebut, vector<int>& reservoirs) { if (max - 1 == min) { return max; } else if (reservoirs[(max + min) / 2] - reservoirs[reservoirDebut] > litres) { return dichotomie (litres, (max + min) / 2, min, reservoirDebut, reservoirs); } else { return dichotomie (litres, max, (max + min) / 2, reservoirDebut, 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.second <= reservoirs [nbReservoirs - 1] - reservoirs[entree.first - 1]) { resultat = dichotomie (entree.second, reservoirs.size() - 1, 0, entree.first - 2, 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...