Submission #393353

#TimeUsernameProblemLanguageResultExecution timeMemory
393353vanicK blocks (IZhO14_blocks)C++14
0 / 100
1 ms332 KiB
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <cstdio> using namespace std; const int maxk=105, maxn=1e5+5; const int inf=1e9; vector < pair < int, int > > v[maxk]; int dp[maxn][maxk]; int a[maxn]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for(int i=0; i<n; i++){ cin >> a[i]; } int sum=0; for(int i=0; i<k; i++){ v[i].push_back({sum, a[i]}); sum+=a[i]; dp[i][i]=sum; } int mindp; int val; for(int i=0; i<n; i++){ for(int j=0; j<min(k, i); j++){ mindp=dp[i-1][j-1]; val=a[i]; while(v[j].back().second<=val){ mindp=min(mindp, v[j].back().first); v[j].pop_back(); } dp[i][j]=val+mindp; v[j].push_back({mindp, val}); } } cout << dp[n-1][k-1] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...