202112026-01-04 23:42:50hunzombiLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5032ms1296 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, target;
    cin >> n >> target;
    vector<int> vec(n, 0);
    for (int i=0; i < n; i++) {
        cin >> vec[i];
    }

    int low = 0, high = -1;
    int t = 0;
    int res = n + 1;

    while (high < n) {
        if (t < target) {
            high++;
            if (high < n) {
                t += vec[high];
            }
        } else {
            t -= vec[low];
            low++;
        }
        if (t >= target) {
            if (high - low + 1 < res) {
                res = high - low + 1;
            }
        }
    }

    if (res == n + 1) {
        cout << -1 << '\n';
    } else {
        cout << res << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms508 KiB
2Accepted0/030ms1280 KiB
3Accepted2/21ms548 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms508 KiB
6Accepted2/24ms316 KiB
7Accepted2/24ms316 KiB
8Accepted2/24ms316 KiB
9Accepted2/24ms440 KiB
10Accepted2/24ms316 KiB
11Accepted2/232ms1296 KiB
12Accepted2/230ms756 KiB
13Accepted2/230ms1076 KiB
14Accepted2/230ms564 KiB
15Accepted2/230ms1168 KiB
16Accepted2/230ms1076 KiB
17Accepted2/230ms1048 KiB
18Accepted2/230ms1172 KiB
19Accepted2/232ms1160 KiB
20Accepted2/230ms564 KiB
21Accepted2/230ms1044 KiB
22Accepted2/230ms1276 KiB
23Accepted2/232ms1272 KiB
24Accepted2/232ms1272 KiB
25Accepted2/232ms1076 KiB
26Accepted2/230ms1076 KiB
27Accepted2/232ms1076 KiB