44952023-03-29 10:31:36semmiLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5035ms5992 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, p;
    cin >> n >> p;
    vector<int> k(n+1), prefi(n+1, 0);
    for(int i = 1;i <=n;i++ ) {
        cin >> k[i];
    }
    prefi[1] = k[1];
    for(int i = 2;i<=n;i++ ) {
        prefi[i] = prefi[i-1] + k[i];
    }
    int b = 1;
    int ans = INT_MAX;

    for(int i = 1;i<=n;i++) {
        if(prefi[i] - prefi[b-1] < p) {
            continue;
        }
        ans = min(ans, i-b+1);
        for(int z = b;z < i;z++) {
            if(prefi[i] - prefi[z] >= p) {
                b = z+1;
            } else {
                break;
            }
        }
        ans = min(ans, i-b+1);
    }
    
    cout << ans << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/032ms3404 KiB
3Accepted2/23ms2264 KiB
4Accepted2/23ms2472 KiB
5Accepted2/23ms2640 KiB
6Accepted2/26ms3052 KiB
7Accepted2/26ms3500 KiB
8Accepted2/26ms3468 KiB
9Accepted2/24ms3436 KiB
10Accepted2/24ms3436 KiB
11Accepted2/232ms4796 KiB
12Accepted2/232ms5108 KiB
13Accepted2/232ms5056 KiB
14Accepted2/232ms5168 KiB
15Accepted2/232ms5372 KiB
16Accepted2/232ms5460 KiB
17Accepted2/232ms5520 KiB
18Accepted2/232ms5524 KiB
19Accepted2/232ms5524 KiB
20Accepted2/232ms5524 KiB
21Accepted2/232ms5528 KiB
22Accepted2/235ms5896 KiB
23Accepted2/232ms5884 KiB
24Accepted2/232ms5992 KiB
25Accepted2/232ms5948 KiB
26Accepted2/232ms5948 KiB
27Accepted2/232ms5948 KiB