82522024-01-13 20:38:57szilVirágos rét (50 pont)cpp17Accepted 50/5013ms5724 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 200'001;

int a[MAXN], pref[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
        pref[i] = pref[i-1] + a[i];
    }
    ll ans = 0; int l = 0;
    for (int i = 1; i <= n; i++) {
        while (l <= i && pref[l] + k <= pref[i]) {
            l++;
        }
        if (a[i])
            ans += pref[l];
    }
    cout << ans << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1960 KiB
2Accepted0/03ms2104 KiB
3Accepted0/012ms4008 KiB
4Accepted2/23ms2480 KiB
5Accepted2/23ms2788 KiB
6Accepted2/23ms2864 KiB
7Accepted3/33ms3068 KiB
8Accepted3/33ms3268 KiB
9Accepted3/32ms3280 KiB
10Accepted2/22ms3276 KiB
11Accepted3/33ms3376 KiB
12Accepted2/23ms3360 KiB
13Accepted3/33ms3280 KiB
14Accepted2/210ms4904 KiB
15Accepted2/29ms5004 KiB
16Accepted3/313ms5016 KiB
17Accepted3/310ms5000 KiB
18Accepted3/312ms5144 KiB
19Accepted3/310ms5320 KiB
20Accepted3/310ms5256 KiB
21Accepted3/313ms5512 KiB
22Accepted3/310ms5724 KiB