18712022-12-06 20:28:52TomaSajtLeggyorsabb pénzkeresés (50)cpp17Wrong answer 46/5013ms4924 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main() {
    speed;
    int n, p;
    cin >> n >> p;
    vector<int> v(n);
    for (auto& a : v) cin >> a;
    int l = 0, r = -1;
    int best = INT_MAX;
    int s = 0;
    while (r < n) {
        if (s >= p) {
            s -= v[l];
            l++;
            if (s >= p) best = min(best, r - l + 1);
        }
        else {
            r++;
            if (r == n) break;
            s += v[r];
        }
    }
    cout << best;
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/03ms1700 KiB
2Accepted0/012ms2552 KiB
3Accepted2/22ms2068 KiB
4Accepted2/22ms2276 KiB
5Wrong answer0/22ms2496 KiB
6Accepted2/23ms2848 KiB
7Accepted2/23ms3056 KiB
8Accepted2/23ms3264 KiB
9Accepted2/23ms3316 KiB
10Accepted2/23ms3516 KiB
11Accepted2/212ms4344 KiB
12Accepted2/213ms4548 KiB
13Accepted2/212ms4520 KiB
14Accepted2/213ms4644 KiB
15Accepted2/212ms4844 KiB
16Accepted2/213ms4844 KiB
17Accepted2/212ms4844 KiB
18Accepted2/212ms4848 KiB
19Accepted2/212ms4848 KiB
20Accepted2/212ms4844 KiB
21Accepted2/212ms4924 KiB
22Accepted2/212ms4848 KiB
23Wrong answer0/212ms4848 KiB
24Accepted2/213ms4668 KiB
25Accepted2/212ms4668 KiB
26Accepted2/213ms4668 KiB
27Accepted2/213ms4804 KiB