113712024-08-27 22:33:16kukkermanÚthasználati díj (75 pont)cpp17Accepted 75/7523ms1032 KiB
#include <iostream>
#include <vector>

void beolvas(std::istream &be, std::vector<int> &v, int &k) {
    int n;
    be >> n >> k;

    v.resize(n);
    for (auto &x : v) {
        be >> x;
    }
}

void feldolgoz(const std::vector<int> &v, int k) {
    const auto n = static_cast<int>(v.size());

    unsigned long long utvonal_db = 0;
    int bal;
    for (bal = 0; bal < n && v[bal] == 0; bal++) { }

    unsigned long long dijkoteles_db = 1;
    int jobb = bal;
    while (jobb < n) {
        if (dijkoteles_db <= k) {
            if (dijkoteles_db >= 2 && v[jobb] == 1) {
                utvonal_db += dijkoteles_db - 1;
            }

            jobb++;
            if (jobb < n && v[jobb] == 1) {
                dijkoteles_db++;
            }

        } else {
            if (v[bal] == 1) {
                dijkoteles_db--;
            }
            bal++;
        }
    }

    std::cout << utvonal_db << '\n';
}

int main() {
    std::vector<int> v;
    int k;
    beolvas(std::cin, v, k);

    feldolgoz(v, k);

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms496 KiB
2Accepted0/02ms396 KiB
3Accepted0/020ms944 KiB
4Accepted5/53ms504 KiB
5Accepted5/53ms432 KiB
6Accepted5/53ms532 KiB
7Accepted5/53ms536 KiB
8Accepted5/53ms420 KiB
9Accepted5/53ms632 KiB
10Accepted5/53ms424 KiB
11Accepted5/53ms376 KiB
12Accepted5/53ms380 KiB
13Accepted5/53ms504 KiB
14Accepted5/523ms872 KiB
15Accepted5/521ms1000 KiB
16Accepted5/521ms1032 KiB
17Accepted5/521ms1000 KiB
18Accepted5/520ms1016 KiB