249352026-02-16 23:13:26999Sípálya (55 pont)cpp17Time limit exceeded 21/55500ms2036 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")


signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int n,x;cin>>n>>x;
    vector<int> v(n);
    for(int i = 0;i<n;i++){
        cin>>v[i];
    }
    int mn=1e15;
    for(int i = 0;i<=n-x;i++){
        int cost=0;
        int currh=v[i];
        //cout<<i<<':'<<endl;
        for(int j = i+1;j<i+x;j++){
            if(v[j]==currh-1){
                currh--;
            }
            else if(v[j]<currh-1){
                currh--;
                cost+=currh-v[j];
            }
            else{
                int diff=v[j]-(currh-1);
                cost+=diff*(j-i);
                currh=v[j];
            }
            //cout<<j<<' '<<cost<<endl;
        }
        mn=min(mn,cost);
    }
    cout<<mn<<endl;
}
SubtaskSumTestVerdictTimeMemory
base21/55
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted3/31ms316 KiB
8Accepted1/18ms496 KiB
9Accepted1/110ms500 KiB
10Accepted1/112ms316 KiB
11Accepted1/114ms556 KiB
12Accepted1/114ms504 KiB
13Accepted1/135ms500 KiB
14Accepted2/239ms508 KiB
15Accepted2/214ms528 KiB
16Time limit exceeded0/2500ms1844 KiB
17Time limit exceeded0/2499ms1844 KiB
18Time limit exceeded0/2500ms1844 KiB
19Time limit exceeded0/3499ms1888 KiB
20Time limit exceeded0/2481ms1844 KiB
21Time limit exceeded0/2499ms1844 KiB
22Time limit exceeded0/2500ms2004 KiB
23Time limit exceeded0/2500ms1844 KiB
24Time limit exceeded0/2485ms2036 KiB
25Time limit exceeded0/2499ms1844 KiB
26Time limit exceeded0/2500ms1844 KiB
27Time limit exceeded0/2499ms1988 KiB
28Time limit exceeded0/3476ms1844 KiB
29Time limit exceeded0/3500ms1844 KiB
30Time limit exceeded0/3500ms1848 KiB