246812026-02-13 14:34:36MarcÚthasználati díj (75 pont)cpp17Wrong answer 15/7518ms804 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,k;
    cin >> n >> k;
    vector<int>a(n+1);
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    int kii=0;
    int l=1;
    int jelen=1;
    int ind=1;
    while(a[ind]==0){
        ind++;
    }
    l=ind;
    for(int r=ind+1; r<=n; r++ ){
        if(a[r]==1){
            jelen++;
            if(jelen>k){
                
                l++;
                while(a[l]==0){
                    l++;
                }
                jelen--;
                
                l++;
                while(a[l]==0){
                    l++;
                }
                jelen--;
            }
            kii++;
            if(jelen ==k && k!=2){
                l++;
                while(a[l]==0){
                    l++;
                }
                jelen--;
                kii++;
            }
            //cout << l << " " <<r << " " << jelen << '\n';
            }  
    }
    cout << kii;
}
SubtaskSumTestVerdictTimeMemory
base15/75
1Accepted0/01ms316 KiB
2Accepted0/01ms500 KiB
3Wrong answer0/018ms564 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms316 KiB
6Wrong answer0/51ms316 KiB
7Accepted5/51ms316 KiB
8Wrong answer0/51ms316 KiB
9Wrong answer0/51ms364 KiB
10Wrong answer0/51ms576 KiB
11Wrong answer0/51ms556 KiB
12Wrong answer0/51ms316 KiB
13Wrong answer0/51ms316 KiB
14Wrong answer0/518ms804 KiB
15Wrong answer0/518ms568 KiB
16Wrong answer0/518ms564 KiB
17Wrong answer0/518ms564 KiB
18Wrong answer0/518ms564 KiB