Submission #1257550

#TimeUsernameProblemLanguageResultExecution timeMemory
1257550mardaStove (JOI18_stove)C++20
50 / 100
1096 ms584 KiB
#include<bits/stdc++.h> #define endl "\n" #define int long long int #define pb push_back #define mp make_pair #define Bound 2e5 + 1 #define mid (l+r+1)/2 using namespace std; void solve() { int n,k; cin >> n >> k; int* fuel = new int[k+1]; for(int i = 0; i < k+1; i++) fuel[i] = 0; int prev; cin >> prev; fuel[1] = 1; int nw; for(int i = 1; i < n; i++) { cin >> nw; for(int j = min(i+1,k); j > max(1LL,i+k-n); j--) { if (fuel[j] != 0) fuel[j] = min(fuel[j-1]+1, fuel[j]+nw-prev); else fuel[j] = fuel[j-1]+1; } /* for(int j = 1; j <= k; j++) { cout << fuel[j] << " "; } cout << endl; */ fuel[1] += nw-prev; prev = nw; } cout << fuel[k]; } int32_t main() { cin.tie(0); cout.tie(0); //ios::sync_with_stdio(false); int t = 1; //cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...