제출 #329810

#제출 시각아이디문제언어결과실행 시간메모리
329810Vladth11Stove (JOI18_stove)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;

const ll NMAX = 100001;
const ll INF = (1 << 16) - 1;
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 20;

int dp[2][NMAX];

int main() {
    //ifstream cin("multigraph.in");
    //ofstream cout("multigraph.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i, j, last = 0, maxim = 2e9, k;
    cin >> n >> k;
    for(i = 0; i <= k; i++)
        dp[0][i] = dp[1][i] = 2e9;
    for(i = 1; i <= n; i++){
        int x;
        cin >> x;
        if(i == 1){
            dp[1][1] = 1;
        }else{
            for(j = 1; j <= k; j++){
                dp[i % 2][j] = dp[(i - 1) % 2][j] + (x - last);
                dp[i % 2][j] = min(dp[(i - 1) % 2][j - 1] + 1, dp[i % 2][j]);
                if(i == n)
                maxim = min(maxim, dp[i % 2][j]);
            }
        }
        last = x;
    }
    cout << maxim;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...