이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |