Source Code
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n + 1);
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}

	ll mx = 0;
	for (int p = 1; p <= n; p++)
	{
		ll y = 0;
		for (int j = 0; p + j * k <= n; j++)
			y += a[p + j * k];
		mx = max(mx, y);
	}

	cout << sum - mx;

	return 0;
}
Copy
Offer Yamanabdullah1
GNU G++17
8 ms
364 KB
Accepted