Submission #855180

#TimeUsernameProblemLanguageResultExecution timeMemory
855180ooscodeStove (JOI18_stove)C++17
50 / 100
2276 ms262148 KiB
// IN THE NAME OF ALLAH
// YA IMAM REZA

#include<bits/stdc++.h>
 
using namespace std;
 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define wall cerr << "------------------------------------" << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define all(x) x.begin() , x.end()
#define int ll
#define kids int tm = (tl + tr)>>1; int cl = v<<1; int cr = v<<1|1
#define test int n;cin >> n;while(n--)
#define file freopen("input.txt" , "r" , stdin); freopen("output.txt" , "w" , stdout)
#define debug while(1) cout << "TEST\n"

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#pragma GCC optimize("Ofast")
 
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll , ll> pll;
typedef pair<pii,int> piii;
typedef pair<pll , ll> plll;
 
const int N = 5e3+10;
const int K = 400+10;
const ll mod = 1e9+7;
const ll INF = 1e9+10;
const int P = 31;
const int lg = 25;

const int delta = 30103; 

int dp[N][N];
int t[N];
int n , k;
void solve() {
    for(int i = 0 ; i < N ; i++)
        for(int j = 0 ; j < N ; j++)
            dp[i][j] = INF;
    dp[1][1] = 1;

    cin >> n >> k;
    for(int i = 1 ; i <= n ; i++)
        cin >> t[i];
    for(int i = 2 ; i <= n ; i++) {
        // wall;
        dp[i][1] = dp[i-1][1] + t[i] - t[i-1];
        // cout << i << " " << 1 << " " << dp[i][1] << "\n";
        for(int j = 2 ; j <= min(i , k) ; j++) {
            dp[i][j] = min(dp[i-1][j-1] + 1 , dp[i-1][j] + (t[i] - t[i-1]));
            // cout << i << " " << j << " " << dp[i][j] << " deb\n";
        }
    }

    cout << dp[n][k] << "\n";
}

signed main()
{   
    fast;
    solve();
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...