제출 #1205997

#제출 시각아이디문제언어결과실행 시간메모리
1205997agrim_09오렌지 출하 (JOI16_ho_t1)C++20
100 / 100
44 ms756 KiB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define py cout << "YES" << endl;
#define pn cout << "NO" << endl;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define int long long
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 1e18;
const ll mod = 1e9+7;


// #ifndef ONLINE_JUDGE
// #include "algo/Standard_Stuff/debug.cpp"
// #else
// #define debug(...) 42
// // #endif

// void judge(){
//     srand(time(NULL));
//     #ifndef ONLINE_JUDGE
//     freopen("1.txt","r",stdin);
//     freopen("2.txt","w",stdout);
//     #endif
// }

// Look for edge cases!!!
signed main(){
    fastio; //judge();
    int n,m,k; cin >> n >> m >> k;
    vector<int>dp(n,inf);
    vector<int>a(n);
    for(auto &x : a) cin >> x;

    dp[0] = k;
    for(int i = 1;i<n;i++){
        int curr_max = a[i], curr_min = a[i];
        for(int len = 1;len<=m;len++){
            if((i-len+1)<0){
                break;
            }
            curr_max = max(curr_max,a[i-len+1]);
            curr_min = min(curr_min,a[i-len+1]);
            if((i-len+1)==0){
                dp[i] = min(dp[i],k + len*(curr_max-curr_min));
            }
            else{
                dp[i] = min(dp[i],k + len*(curr_max-curr_min)+dp[i-len]);
            }
        }
    }
    cout << dp[n-1] << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...