81972024-01-12 18:12:57gergomiszoriSípálya (55 pont)cpp17Wrong answer 18/55486ms4392 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl "\n"
#define pll pair<ll,ll>
#define fs first
#define sc second

const ll MOD = 1e9+7;

void solve()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    
    for(ll i = 0; i < n; i++) cin >> a[i];
    
    if(k == 1)
    {
        cout << 0 << endl;
        return;
    }

    ll ans = LLONG_MAX-1;

    for(ll i = 0; i < n-k+1; i++)
    {
        ll maxe = -1;
        ll maxl = 0;
        for(ll j = 0; j < k; j++)
        {
            if(a[i+j] > maxe)
            {
                maxe = a[i+j];
                maxl = j;
            }
        }

        ll ans2 = 0;
        
        for(ll j = 0; j < k; j++)
        {
            ll magas = maxl-j + maxe;
            ans2 += magas - a[i+j];
        }
        ans = min(ans, ans2);
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/03ms1976 KiB
2Accepted0/03ms2124 KiB
3Accepted2/23ms2080 KiB
4Accepted2/23ms2084 KiB
5Accepted2/23ms2080 KiB
6Accepted2/23ms2208 KiB
7Accepted3/33ms2432 KiB
8Wrong answer0/114ms2756 KiB
9Wrong answer0/117ms2716 KiB
10Wrong answer0/118ms2712 KiB
11Accepted1/128ms2984 KiB
12Accepted1/127ms3004 KiB
13Accepted1/159ms2736 KiB
14Accepted2/268ms2996 KiB
15Accepted2/228ms3204 KiB
16Time limit exceeded0/2451ms3880 KiB
17Time limit exceeded0/2462ms4132 KiB
18Time limit exceeded0/2465ms4004 KiB
19Time limit exceeded0/3486ms4060 KiB
20Time limit exceeded0/2453ms4080 KiB
21Time limit exceeded0/2469ms4012 KiB
22Time limit exceeded0/2462ms4076 KiB
23Time limit exceeded0/2460ms4120 KiB
24Time limit exceeded0/2477ms4080 KiB
25Time limit exceeded0/2453ms4012 KiB
26Time limit exceeded0/2456ms4068 KiB
27Time limit exceeded0/2476ms4196 KiB
28Time limit exceeded0/3449ms4072 KiB
29Time limit exceeded0/3474ms4224 KiB
30Time limit exceeded0/3465ms4392 KiB