77212024-01-10 17:49:33tamasmarkSípálya (55 pont)cpp17Wrong answer 0/55105ms18008 KiB
// sipalya'.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

int main()
{
    long long n, k;
    cin >> n >> k;
    vector<pair<long long,long long>>x(n + 1);
    priority_queue<pair<long long, long long>>p,p2;
    long long s1,s2,s3,mini=LONG_MAX,kulombseg;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x[i].first;

        x[i].second = x[i - 1].second + x[i].first;
        p.push({ x[i].first,i });
        while (!p.empty() && p.top().second <= i - k)
        {
            p.pop();
        }
        if (p.top().first-x[i].first<i-p.top().first)
        {
            p2.push({ x[i].first,i });
            while (!p2.empty() && p2.top().second <= i - k)
            {
                p2.pop();
            }
        }
        if (i >= k)
        {
            x[i].second -= x[i - k].second;
            s1 = (p.top().second - (i - k + 1)) + p.top().first;
            if(!p2.empty()) s2 = p.top().first - ((p2.top().second-1) - p.top().second);
            else s2 = p.top().first - (i - p.top().second);
            if (!p2.empty())
            {
                kulombseg = p2.top().first - (p.top().first - ((i-1) - p.top().second))+1;
                s2 = p2.top().first - (i - p2.top().second);
                s1 += kulombseg;
                s3 = (((s1 + s2) * k) / 2)-x[i].second;
            }
            else s3 = (((s1 + s2)*k)/2)-x[i].second;
            mini = min(mini, s3);
        }
    }
    cout << mini;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Accepted0/03ms2092 KiB
2Wrong answer0/03ms2216 KiB
3Wrong answer0/23ms2160 KiB
4Wrong answer0/23ms2172 KiB
5Wrong answer0/23ms2304 KiB
6Wrong answer0/24ms2476 KiB
7Wrong answer0/33ms2668 KiB
8Wrong answer0/17ms3536 KiB
9Wrong answer0/17ms3564 KiB
10Wrong answer0/17ms3792 KiB
11Wrong answer0/17ms3544 KiB
12Wrong answer0/17ms3636 KiB
13Wrong answer0/17ms3768 KiB
14Wrong answer0/27ms3860 KiB
15Wrong answer0/27ms3644 KiB
16Wrong answer0/2100ms13428 KiB
17Wrong answer0/292ms17744 KiB
18Wrong answer0/290ms17704 KiB
19Wrong answer0/390ms17816 KiB
20Wrong answer0/293ms17804 KiB
21Wrong answer0/297ms17936 KiB
22Wrong answer0/2100ms17700 KiB
23Wrong answer0/298ms17700 KiB
24Wrong answer0/2105ms17704 KiB
25Wrong answer0/294ms17940 KiB
26Wrong answer0/296ms17772 KiB
27Wrong answer0/296ms17700 KiB
28Wrong answer0/392ms17700 KiB
29Wrong answer0/393ms17980 KiB
30Wrong answer0/393ms18008 KiB