105912024-04-06 11:02:12MagyarKendeSZLGLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5014ms13900 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N, P;
    cin >> N >> P;
    vector<int> v(N);
    cinv(v);

    int result = INT_MAX, sum = 0;

    for (int l = 0, r = 0; l < N; l++) {
        while (sum < P && r < N) {
            sum += v[r];
            r++;
        }

        if (sum >= P) {
            result = min(result, r - l);
        }

        sum -= v[l];
    }

    cout << result;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1952 KiB
2Accepted0/014ms3388 KiB
3Accepted2/23ms2880 KiB
4Accepted2/23ms3100 KiB
5Accepted2/23ms3428 KiB
6Accepted2/24ms3416 KiB
7Accepted2/24ms3716 KiB
8Accepted2/24ms4052 KiB
9Accepted2/24ms3968 KiB
10Accepted2/24ms3828 KiB
11Accepted2/214ms5168 KiB
12Accepted2/214ms5640 KiB
13Accepted2/214ms6364 KiB
14Accepted2/213ms6812 KiB
15Accepted2/214ms7424 KiB
16Accepted2/214ms8116 KiB
17Accepted2/214ms8680 KiB
18Accepted2/214ms9156 KiB
19Accepted2/214ms9736 KiB
20Accepted2/214ms10328 KiB
21Accepted2/214ms10808 KiB
22Accepted2/214ms11284 KiB
23Accepted2/214ms11768 KiB
24Accepted2/214ms12308 KiB
25Accepted2/214ms12788 KiB
26Accepted2/214ms13268 KiB
27Accepted2/214ms13900 KiB