126722024-12-27 20:19:23BucsMateSípálya (55 pont)cpp17Wrong answer 26/5581ms4404 KiB
#include <iostream>
#include <deque>

using namespace std;

struct Csucs
{
    long long magassag;
    int index;
};

int main()
{
    int N, K;
    cin >> N >> K;
    long long csucsok[200001];
    long long reszosszeg[200001] = {};
    for(int i = 1; i <= N; i++){
        cin >> csucsok[i];
        reszosszeg[i] = reszosszeg[i-1] + csucsok[i];
    }

    deque<Csucs> d;
    for(int i = 1; i <= K; i++){
        while(!d.empty() && d.front().magassag + d.front().index <= csucsok[i] + i){
            d.pop_back();
        }
        d.push_back({csucsok[i], i});
    }
    long long curr, magassag;
    magassag = d.front().magassag + d.front().index - 1;
    curr = (2*magassag-K+1)*K/2;
    long long res = curr - reszosszeg[K];

    for(int i = K+1; i <= N; i++){

        if(d.front().index == i - K){
            d.pop_front();
        }
        while(!d.empty() && d.front().magassag + d.front().index <= csucsok[i] + i){
            d.pop_front();
        }
        d.push_back({csucsok[i], i});
        magassag = d.front().magassag + (d.front().index - i + K - 1);
        curr = (2*magassag-K+1)*K/2;

        res = min(res, curr - (reszosszeg[i] - reszosszeg[i-K]));
    }
    cout << res << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base26/55
1Accepted0/02ms2028 KiB
2Wrong answer0/02ms2036 KiB
3Wrong answer0/23ms1848 KiB
4Wrong answer0/23ms1848 KiB
5Wrong answer0/23ms1876 KiB
6Wrong answer0/23ms1848 KiB
7Wrong answer0/33ms1980 KiB
8Accepted1/16ms1848 KiB
9Accepted1/16ms1848 KiB
10Accepted1/16ms1856 KiB
11Accepted1/16ms2000 KiB
12Accepted1/16ms2152 KiB
13Accepted1/16ms2120 KiB
14Wrong answer0/26ms2104 KiB
15Accepted2/26ms1848 KiB
16Wrong answer0/275ms3640 KiB
17Accepted2/275ms4200 KiB
18Accepted2/275ms4404 KiB
19Accepted3/376ms3944 KiB
20Wrong answer0/276ms3776 KiB
21Wrong answer0/275ms3652 KiB
22Wrong answer0/275ms3640 KiB
23Wrong answer0/278ms3640 KiB
24Wrong answer0/281ms3736 KiB
25Wrong answer0/275ms3624 KiB
26Wrong answer0/276ms3924 KiB
27Accepted2/276ms3920 KiB
28Accepted3/375ms3980 KiB
29Accepted3/375ms3896 KiB
30Accepted3/376ms3896 KiB