Source Code
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
const int mod = 1e9 + 7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n , k;
    cin >>  n >> k;
    int arr[n];
    long long sum = 0;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    long long ans = 1e18;
    for(int i = 0; i < n; i++){
        long long s = 0;
        int pos = i;
        while(pos < n){
            s += arr[pos];
            pos += k;
        }
        ans = min(ans  , sum - s);
    }  
    cout << ans << "\n";
    return 0;
}  
Copy
Offer AbduSaber
GNU G++17
9 ms
320 KB
Accepted