Source Code
// {In the Name of Allah, the Most Beneficent, the Most Merciful }

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define mp make_pair
#define pb push_back
#define pf push_front
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);
#define no cout<<"NO\n"
#define yes cout<<"YES\n"
#define el "\n"

long long a , b , sum;

int main()
{
//	cout<<fixed<<setprecision(0);
    /**/IOS/**/

int n , k , x;
cin>>n>>k;
for(int i=0 ; i<n ; i++)
{
	cin>>x;
	sum+=x;
	if((i%k==0))
	a+=x;
	else if(((i-1)%k==0))
	b+=x;
}

long long m = min(sum-a,sum-b);
cout<<m;


}//mai
Copy
Offer aram
GNU G++17
2 ms
184 KB
Wrong Answer