20532022-12-15 23:47:43kovacs.peter.18fLeggyorsabb pénzkeresés (50)cpp11Accepted 50/5012ms5264 KiB
#include <iostream>
#include <vector>

using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N, P;
    cin >> N >> P;
    vector<int> payS(N);
    for (auto &e : payS) {
        cin >> e;
    }
    int minimum = -1;
    for (int l = 0, r = 0, current = 0; l < N; l++) {
        while (r < N && current < P) {
            current += payS[r++];
        }
        if (current >= P && (minimum == -1 || r - l < minimum)) {
            minimum = r - l;
        }
        current -= payS[l];
    }
    cout << minimum << '\n';
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/012ms2748 KiB
3Accepted2/22ms2260 KiB
4Accepted2/22ms2484 KiB
5Accepted2/22ms2664 KiB
6Accepted2/23ms3048 KiB
7Accepted2/23ms3352 KiB
8Accepted2/23ms3560 KiB
9Accepted2/23ms3508 KiB
10Accepted2/23ms3760 KiB
11Accepted2/212ms4252 KiB
12Accepted2/212ms4248 KiB
13Accepted2/212ms4252 KiB
14Accepted2/212ms4252 KiB
15Accepted2/212ms4348 KiB
16Accepted2/212ms4452 KiB
17Accepted2/212ms4524 KiB
18Accepted2/212ms4528 KiB
19Accepted2/212ms4656 KiB
20Accepted2/212ms4860 KiB
21Accepted2/212ms4936 KiB
22Accepted2/212ms4936 KiB
23Accepted2/212ms4936 KiB
24Accepted2/212ms5060 KiB
25Accepted2/212ms5140 KiB
26Accepted2/212ms5140 KiB
27Accepted2/212ms5264 KiB