73882024-01-08 13:14:28gkataSípálya (55 pont)cpp17Wrong answer 0/5593ms12076 KiB
// sipalya.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>

using namespace std;

int n, k, i, m=1000000000, s, ns, u, e;
vector<int>x,pf;
vector<pair<int, int>>v;
priority_queue < pair<int, int>>pq;

int main()
{
    cin >> n >> k;

    x.resize(n + 1);
    pf.resize(n + 1);

    for (i = 1; i <= n; ++i)
    {
        cin >> x[i];
        pq.push({ x[i],i });
        pf[i] = x[i] + pf[i - 1];
    }

    for (i = k; i <= n; ++i)
    {
        s = pf[i] - pf[i - k];
        v.clear();
        while (pq.top().second < (i - k + 1) && pq.top().second > i)
        {
            v.push_back(pq.top());
            pq.pop();
        }
        
        e = pq.top().first + (pq.top().second - (i - k + 1));
        u = e - k + 1;
        ns = ((e + u) * k) / 2;
        for (auto& e : v) pq.push(e);

        if ((ns - s) < m) m = ns - s;
    }

    cout << m;
}

/*
5 3
5 5 6 3 1
*/

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base0/55
1Accepted0/03ms1872 KiB
2Wrong answer0/03ms2064 KiB
3Wrong answer0/23ms2296 KiB
4Wrong answer0/23ms2512 KiB
5Wrong answer0/23ms2692 KiB
6Wrong answer0/23ms2920 KiB
7Wrong answer0/33ms3052 KiB
8Wrong answer0/17ms3580 KiB
9Wrong answer0/17ms4072 KiB
10Wrong answer0/17ms3924 KiB
11Wrong answer0/16ms3924 KiB
12Wrong answer0/16ms3952 KiB
13Wrong answer0/17ms3804 KiB
14Wrong answer0/27ms3888 KiB
15Wrong answer0/27ms4052 KiB
16Wrong answer0/285ms11016 KiB
17Wrong answer0/285ms11080 KiB
18Wrong answer0/285ms11356 KiB
19Wrong answer0/385ms11564 KiB
20Wrong answer0/286ms11772 KiB
21Wrong answer0/285ms11836 KiB
22Wrong answer0/286ms11964 KiB
23Wrong answer0/286ms11892 KiB
24Wrong answer0/293ms12056 KiB
25Wrong answer0/286ms12076 KiB
26Wrong answer0/286ms12000 KiB
27Wrong answer0/286ms11908 KiB
28Wrong answer0/385ms12076 KiB
29Wrong answer0/385ms11912 KiB
30Wrong answer0/386ms11904 KiB