88392024-02-01 12:31:42hackemonLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5034ms7228 KiB
#include <bits/stdc++.h>
using namespace std;



int main() {
    //freopen("be2.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    
    vector<int> f(n); 
    for(int i = 0;i < n;i++) cin >> f[i];

    int sum = 0;
    int pos = 0;
    
    for(int i = 0;i < n;i++ ) {
    sum += f[i];
    if(sum >= k) {
        pos = i + 1;
        break;
    }
    }
    int ans = pos;
    int left = 0; 


    for(;pos < n;pos++ ) {
        sum+= f[pos];
        for(;left < pos;left++ ) {
            if(sum - f[left] >= k) {
                sum -= f[left];
            } else {
                break;
            }
        }
        ans = min(ans, pos - left + 1); 
    }

    cout << ans << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/034ms3268 KiB
3Accepted2/23ms2792 KiB
4Accepted2/23ms2828 KiB
5Accepted2/23ms2968 KiB
6Accepted2/26ms3172 KiB
7Accepted2/26ms3200 KiB
8Accepted2/26ms3500 KiB
9Accepted2/26ms3828 KiB
10Accepted2/26ms4092 KiB
11Accepted2/234ms5272 KiB
12Accepted2/234ms5880 KiB
13Accepted2/234ms6576 KiB
14Accepted2/234ms6752 KiB
15Accepted2/234ms6732 KiB
16Accepted2/234ms6884 KiB
17Accepted2/234ms6844 KiB
18Accepted2/234ms6864 KiB
19Accepted2/234ms6952 KiB
20Accepted2/234ms6952 KiB
21Accepted2/234ms6952 KiB
22Accepted2/234ms7040 KiB
23Accepted2/234ms7044 KiB
24Accepted2/234ms7192 KiB
25Accepted2/234ms7036 KiB
26Accepted2/234ms7092 KiB
27Accepted2/234ms7228 KiB