Source Code
#include <iostream>
#include<algorithm>


using namespace std;
int main() {
  int n , k  , total = 0  ,minn = 1900099999;
  cin>>n>>k;
  int a[n];
  for(int i =0 ; i<n ; i++)cin>>a[i];
  
  for(int j = 0 ; j<n ; j++)
    {
     int  sum =j ; 
      total = 0 ; 
  for(int i = 0 ; i<n ; i++)
    {
      if(i != sum) total +=a[i];
      else sum +=k;
    }
      
      minn = min(minn , total );
      }
  
  cout<<minn;
}
Copy
Offer Tala_Ibraheem
GNU G++17
3 ms
340 KB
Accepted