81942024-01-12 17:48:29MagyarKendeSZLGSípálya (55 pont)cpp17Hibás válasz 53/5534ms13572 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <numeric>
using namespace std;

using ll = unsigned long long;
#define speed cin.tie(0); ios::sync_with_stdio(0)

vector<ll> heightS;
int N, K;

int main() {
    speed;

    cin >> N >> K;

    heightS.resize(N);

    for (int i = 0; i < N; i++) {
        cin >> heightS[i];
        heightS[i] += i;
    }

    deque<pair<int, int>> q;
    vector<ll> window_mx(N - K + 1);
    
    for (int right = 0; right < K; right++) {
        while (!q.empty() && q.back().first < heightS[right]) q.pop_back();
        q.push_back({heightS[right], right});
    }

    window_mx[0] = q.front().first;
    int p = 0;

    int left = 1, right = K;
    while (left < N - K + 1) {
        while (!q.empty() && q.front().second < left) q.pop_front();

        while (!q.empty() && q.back().first < heightS[right]) q.pop_back();

        q.push_back({heightS[right], right});

        left++;
        right++;

        window_mx[++p] = q.front().first;
    }

    ll result = ULLONG_MAX;

    vector<ll> prefix(N);
    partial_sum(heightS.begin(), heightS.end(), prefix.begin() + 1);

    for (int i = 0; i < N - K; i++) {
        result = min(
            result, 
            (window_mx[i] * K) - 
            (prefix[i + K] - prefix[i])
        );
    }

    cout << result;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base53/55
1Elfogadva0/03ms1828 KiB
2Elfogadva0/03ms2020 KiB
3Elfogadva2/23ms2388 KiB
4Elfogadva2/23ms2472 KiB
5Elfogadva2/23ms2800 KiB
6Elfogadva2/23ms2760 KiB
7Elfogadva3/33ms2976 KiB
8Elfogadva1/14ms3376 KiB
9Elfogadva1/14ms3376 KiB
10Elfogadva1/14ms3244 KiB
11Elfogadva1/14ms3536 KiB
12Elfogadva1/14ms3608 KiB
13Elfogadva1/14ms3744 KiB
14Elfogadva2/24ms3832 KiB
15Elfogadva2/24ms3828 KiB
16Elfogadva2/232ms12600 KiB
17Hibás válasz0/230ms11296 KiB
18Elfogadva2/230ms11464 KiB
19Elfogadva3/330ms11000 KiB
20Elfogadva2/232ms12964 KiB
21Elfogadva2/232ms13112 KiB
22Elfogadva2/232ms13224 KiB
23Elfogadva2/232ms13308 KiB
24Elfogadva2/234ms13572 KiB
25Elfogadva2/232ms13424 KiB
26Elfogadva2/232ms13120 KiB
27Elfogadva2/232ms12936 KiB
28Elfogadva3/332ms13084 KiB
29Elfogadva3/332ms12932 KiB
30Elfogadva3/332ms12932 KiB