43492023-03-26 10:50:44Erik_GepardSípálya (55 pont)cpp17Accepted 55/5585ms10652 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int n, k;


signed main() {
	cin>>n>>k;
  vector<long long> a(n+1);
  vector<long long> s(n+1);
  map<int, int> m;
  long long eredmeny=LLONG_MAX/2;
  for(int i=1; i<=n; i++) {
    cin>>a[i];
    a[i]+=i;
    s[i]=s[i-1]+a[i];
    if(i<k) {
      m[a[i]]+=1;
    }
  }
  cout<<endl;
  for(int vege=k; vege<=n; vege++) {
    m[a[vege]]+=1;
    
    auto it=m.rbegin();
    eredmeny=min(eredmeny, (it->first)*k-(s[vege]-s[vege-k]));
    m[a[vege-k+1]]-=1;
    if(m[a[vege-k+1]]==0) {
      m.erase(a[vege-k+1]);
    }
  }
  cout<<eredmeny<<endl;
  
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1816 KiB
2Accepted0/03ms2008 KiB
3Accepted2/23ms2360 KiB
4Accepted2/23ms2600 KiB
5Accepted2/23ms2676 KiB
6Accepted2/23ms2896 KiB
7Accepted3/33ms3056 KiB
8Accepted1/18ms3516 KiB
9Accepted1/18ms3476 KiB
10Accepted1/18ms3480 KiB
11Accepted1/16ms3576 KiB
12Accepted1/16ms3660 KiB
13Accepted1/16ms3668 KiB
14Accepted2/26ms3876 KiB
15Accepted2/26ms3876 KiB
16Accepted2/279ms9624 KiB
17Accepted2/279ms9920 KiB
18Accepted2/278ms9880 KiB
19Accepted3/379ms10008 KiB
20Accepted2/282ms10008 KiB
21Accepted2/278ms9976 KiB
22Accepted2/279ms10148 KiB
23Accepted2/282ms10196 KiB
24Accepted2/285ms10228 KiB
25Accepted2/282ms10404 KiB
26Accepted2/282ms10364 KiB
27Accepted2/279ms10360 KiB
28Accepted3/379ms10652 KiB
29Accepted3/379ms10576 KiB
30Accepted3/382ms10532 KiB