126712024-12-27 20:18:34BucsMateSípálya (55 pont)cpp17Wrong answer 0/553ms568 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[2001];
    long long reszosszeg[2001] = {};
    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
base0/55
1Accepted0/01ms500 KiB
2Wrong answer0/01ms320 KiB
3Wrong answer0/21ms320 KiB
4Wrong answer0/22ms320 KiB
5Wrong answer0/21ms320 KiB
6Wrong answer0/21ms320 KiB
7Wrong answer0/31ms336 KiB
8Runtime error0/12ms436 KiB
9Runtime error0/12ms320 KiB
10Runtime error0/12ms320 KiB
11Runtime error0/12ms340 KiB
12Runtime error0/12ms320 KiB
13Runtime error0/12ms320 KiB
14Runtime error0/22ms320 KiB
15Runtime error0/22ms320 KiB
16Runtime error0/22ms508 KiB
17Runtime error0/22ms320 KiB
18Runtime error0/22ms432 KiB
19Runtime error0/32ms320 KiB
20Runtime error0/22ms512 KiB
21Runtime error0/22ms560 KiB
22Runtime error0/22ms420 KiB
23Runtime error0/22ms568 KiB
24Runtime error0/23ms320 KiB
25Runtime error0/23ms320 KiB
26Runtime error0/23ms320 KiB
27Runtime error0/22ms320 KiB
28Runtime error0/32ms320 KiB
29Runtime error0/32ms320 KiB
30Runtime error0/31ms568 KiB