Source Code
#include <iostream>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    

    long long ar[n];
    long long zero=0,one=0;
    long long sum=0;

    for(int i=0;i<n;i++){
        cin>>ar[i];
        if(i%k==0||i==0){
            zero+=ar[i];
        }
        if(i+1%k==0||i==1){
            one+=ar[i];
        }
        sum+=ar[i];
    }
    if(zero>one){
        cout<<sum-zero<<endl;
    }
    else{
        cout<<sum-one<<endl;
    }


    return 0;
}

Copy
Offer YousefShaheen
GNU G++17
2 ms
240 KB
Wrong Answer