답안 #463593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463593 2021-08-11T10:48:07 Z Quentolosse Fountain (eJOI20_fountain) C++14
0 / 100
416 ms 1964 KB
//sous-tache 2
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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 = 1; i < nbReservoirs; i++)
    {
        reservoirs[i] += reservoirs[i-1];
    }
    for (int question = 0; question < nbQuestions; question++)
    {
        int resultat, numReservoir, volumeReservoir, min = 0, max = nbReservoirs - 1;
        cin >> numReservoir >> volumeReservoir;
        if (reservoirs[nbReservoirs - 1] - reservoirs[numReservoir - 2] < volumeReservoir)
        {
            cout << 0 << endl;
            continue;
        }
        while (min <= max)
        {
            if (reservoirs[(max + min) / 2] - reservoirs[numReservoir - 2] > volumeReservoir)
            {
                resultat = (max + min) / 2;
                max = ((max + min) / 2) - 1;
            }
            else
            {
                min = ((max + min) / 2) + 1;
            }
        }
        cout << resultat + 1<< endl;
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:44:28: warning: 'resultat' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |         cout << resultat + 1<< endl;
      |                            ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 416 ms 1964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -