61702023-11-04 23:29:41MrChipserSípálya (55 pont)cpp11Accepted 55/55118ms21428 KiB
#include <bits/stdc++.h>
using namespace std;
int n,k;

int main()
{
    cin >> n >>k;
    vector<long long>cs(n);
    for(int i = 0; i < n; i++)
    {
        cin >> cs[i];
        cs[i]+=i;
    }
    long long sum = 0;
    multiset<long long>akt;
    for(int i = 0; i < k; i++)
    {
        akt.insert(cs[i]);
        sum+=cs[i];
    }
    long long minim = INT64_MAX;
    for(int i = k-1; i < n; i++)
    {
        if(i >= k)
        {
            sum-=cs[i-k];
            sum+=cs[i];
            akt.erase(akt.find(cs[i-k]));
            akt.insert(cs[i]);
        }
        auto veg = akt.end();
        veg--;
        long long localmax = *veg;
        long long localmin = k * localmax - sum;
        if(localmin < minim)
            minim = localmin;

    }
    cout << minim;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms2088 KiB
2Accepted0/03ms2136 KiB
3Accepted2/23ms2308 KiB
4Accepted2/23ms2308 KiB
5Accepted2/23ms2440 KiB
6Accepted2/23ms2524 KiB
7Accepted3/33ms2808 KiB
8Accepted1/18ms2884 KiB
9Accepted1/18ms3152 KiB
10Accepted1/18ms3368 KiB
11Accepted1/18ms3660 KiB
12Accepted1/18ms3804 KiB
13Accepted1/18ms4244 KiB
14Accepted2/28ms4380 KiB
15Accepted2/28ms4108 KiB
16Accepted2/2111ms7808 KiB
17Accepted2/2115ms16464 KiB
18Accepted2/2115ms17380 KiB
19Accepted3/3115ms21428 KiB
20Accepted2/2115ms8992 KiB
21Accepted2/2112ms8860 KiB
22Accepted2/2112ms8860 KiB
23Accepted2/2114ms8332 KiB
24Accepted2/2118ms8704 KiB
25Accepted2/2115ms9484 KiB
26Accepted2/2115ms10032 KiB
27Accepted2/2114ms10140 KiB
28Accepted3/3114ms10356 KiB
29Accepted3/3114ms10728 KiB
30Accepted3/3115ms11344 KiB