40022023-03-08 08:19:091478Sípálya (55 pont)cpp17Wrong answer 29/55119ms24432 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    //ifstream cin("in.txt");
    long long n;
    cin >> n;
    long long k;
    cin >> k;
    vector<long long> heights(n + 2);
    vector<long long> ps(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> heights[i];
        ps[i] = ps[i - 1] + heights[i];
    }

    multiset<long long> s;
    for(int i = 1; i <= k; i++){
        s.insert(heights[i] + i);
    }

    long long ans = INT_MAX;
    for(long long i = k; i <= n; i++){
        long long actualsum = ps[i] - ps[i - k];
        long long neededsum = (*s.rbegin()- i) * k + (k - 1)*k/2;
        //cout << i << " " << heights[i] << " " << *s.rbegin() - i << " " << neededsum - actualsum << '\n';
        ans = min(ans, neededsum - actualsum);
        s.erase(s.lower_bound(heights[i - k + 1] + i - k + 1));
        s.insert(heights[i + 1] + i + 1);
    }
    cout << ans;



    return 0;
}
SubtaskSumTestVerdictTimeMemory
base29/55
1Accepted0/03ms1812 KiB
2Accepted0/02ms2004 KiB
3Accepted2/23ms2232 KiB
4Accepted2/23ms2440 KiB
5Accepted2/23ms2660 KiB
6Accepted2/23ms2752 KiB
7Accepted3/33ms2832 KiB
8Accepted1/18ms3108 KiB
9Accepted1/18ms3120 KiB
10Accepted1/18ms3440 KiB
11Accepted1/18ms3356 KiB
12Accepted1/18ms3552 KiB
13Accepted1/18ms3956 KiB
14Accepted2/28ms3956 KiB
15Accepted2/28ms3944 KiB
16Accepted2/2111ms10652 KiB
17Wrong answer0/2119ms19412 KiB
18Wrong answer0/2115ms20528 KiB
19Wrong answer0/3119ms24432 KiB
20Accepted2/2115ms11816 KiB
21Wrong answer0/2112ms11688 KiB
22Wrong answer0/2114ms12000 KiB
23Accepted2/2114ms11288 KiB
24Wrong answer0/2118ms11636 KiB
25Accepted2/2115ms12492 KiB
26Wrong answer0/2115ms12656 KiB
27Wrong answer0/2115ms13228 KiB
28Wrong answer0/3115ms13192 KiB
29Wrong answer0/3115ms13648 KiB
30Wrong answer0/3115ms14120 KiB