Source Code
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
typedef long long ll;



int main(){

	ll T,n,k, t,a,b;

        cin>>n>>k;
       vector<ll>v;
       ll sum=0;
       for(t=0;t<n;t++){
        cin>>a;
        v.pb(a);
        sum+=a;
       }
        ll ans=0,c=0;
        for(int i=0;i<k;i++){
          c=0;
          for(t=i;t<n;t+=k){
            c+=v[t];
         }
         ans=max(ans,c);

        }


       cout<<sum-ans<<"\n";

}
Copy
Offer mohammed_mraish
GNU G++17
2 ms
384 KB
Accepted