Source Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

    ios_base::sync_with_stdio(0);
    cout.tie(0); cout.tie(0);

    int n , k;
    cin >> n >> k;
    vector<int> a(n);

    ll sum = 0 ,ans = 2e18;
    for(int &x : a){
        cin >> x;
        sum += x;
    }

    for(int i = 0 ; i < n ; i++){
        ll cur = 0;
        for(int j = i ; j < n ; j += k){
            cur += a[j];
        }
        ans = min(sum - cur , ans);
    }
    cout << ans;
    return 0;
}
Copy
Offer Greedious
GNU G++17
1 ms
324 KB
Accepted