//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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
346 ms |
1016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |