Source Code
#include <iostream>
using namespace std;

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

    long long ar[n];
    cin>>ar[0]>>ar[1];
    long long zero=0,one=0;
    long long sum=ar[0]+ar[1];
    zero+=ar[0];
    one+=ar[1];

    for(int i=2;i<n;i++){
        cin>>ar[i];
        if(i%k==0)
            zero+=ar[i];
        if(i+1%k==0)
            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
1 ms
184 KB
Wrong Answer