8672022-01-21 20:28:52Valaki2Leggyorsabb pénzkeresés (50)cpp14Accepted 50/5014ms11588 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int maxn = 1e5;

int n, p;
int v[1 + maxn];

void solve() {
    cin >> n >> p;
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    int l = 1, r = 1, sum = 0, ans = n;
    while(l <= n) {
        while(r <= n && sum < p) {
            sum += v[r];
            r++;
        }
        if(sum >= p) ans = min(ans, r - l);
        sum -= v[l];
        l++;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1888 KiB
2Accepted0/014ms3236 KiB
3Accepted2/22ms2480 KiB
4Accepted2/21ms2488 KiB
5Accepted2/21ms2492 KiB
6Accepted2/22ms2540 KiB
7Accepted2/22ms2588 KiB
8Accepted2/22ms2636 KiB
9Accepted2/22ms2680 KiB
10Accepted2/22ms2736 KiB
11Accepted2/29ms4024 KiB
12Accepted2/210ms4380 KiB
13Accepted2/210ms4852 KiB
14Accepted2/210ms5336 KiB
15Accepted2/212ms5812 KiB
16Accepted2/210ms6300 KiB
17Accepted2/212ms6904 KiB
18Accepted2/29ms7384 KiB
19Accepted2/29ms7868 KiB
20Accepted2/210ms8344 KiB
21Accepted2/210ms8836 KiB
22Accepted2/210ms9180 KiB
23Accepted2/210ms9800 KiB
24Accepted2/212ms10276 KiB
25Accepted2/210ms10760 KiB
26Accepted2/210ms11108 KiB
27Accepted2/210ms11588 KiB