77302024-01-10 18:48:39gyjazminSípálya (55 pont)cpp17Accepted 55/55115ms19788 KiB
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> hegyek(n);
    for (int i = 0; i < n; i++) {
        cin >> hegyek[i];
        hegyek[i] += i;
    }
    multiset<int> jelenlegi;
    long long sum = 0;
    for (int i = 0; i < k; i++) {
        sum += hegyek[i];
        jelenlegi.insert(hegyek[i]);
    }
    ll legk = INT64_MAX;
    for (int i = k - 1; i < n; i++) {
        if (i >= k) {
            sum -= hegyek[i - k];
            sum += hegyek[i];
            jelenlegi.erase(jelenlegi.find(hegyek[i - k]));
            jelenlegi.insert(hegyek[i]);
        }
        auto it = jelenlegi.end();//-1;
        it--;
        ll lokalismaximum = *it;
        ll ar = k * lokalismaximum - sum;
        if (ar < legk) {
            legk = ar;
        }
    }
    cout << legk;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1812 KiB
2Accepted0/03ms2056 KiB
3Accepted2/23ms2268 KiB
4Accepted2/23ms2512 KiB
5Accepted2/23ms2728 KiB
6Accepted2/24ms3028 KiB
7Accepted3/33ms3104 KiB
8Accepted1/18ms3484 KiB
9Accepted1/18ms3700 KiB
10Accepted1/18ms3936 KiB
11Accepted1/18ms4156 KiB
12Accepted1/18ms4260 KiB
13Accepted1/18ms4452 KiB
14Accepted2/28ms4576 KiB
15Accepted2/28ms4212 KiB
16Accepted2/2108ms6516 KiB
17Accepted2/2111ms14976 KiB
18Accepted2/2112ms16020 KiB
19Accepted3/3111ms19788 KiB
20Accepted2/2115ms7656 KiB
21Accepted2/2108ms7388 KiB
22Accepted2/2109ms7520 KiB
23Accepted2/2111ms6972 KiB
24Accepted2/2115ms7212 KiB
25Accepted2/2112ms8120 KiB
26Accepted2/2114ms8644 KiB
27Accepted2/2109ms8832 KiB
28Accepted3/3112ms8928 KiB
29Accepted3/3112ms9448 KiB
30Accepted3/3115ms9856 KiB