# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99921 | MohamedAhmed0 | K blocks (IZhO14_blocks) | C++14 | 18 ms | 16896 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5 ;
const int MAXK = 1e2+5 ;
pair<long long , long long>dp[MAXN][MAXK] ;
int n , k ;
long long arr[MAXN] ;
int main()
{
scanf("%d %d" , &n , &k) ;
for(int i = 1 ; i <= n ; ++i)
scanf("%lld" , &arr[i]) ;
for(int i = 0 ; i <= n ; ++i)
{
for(int j = 0 ; j <= k ; ++j)
dp[i][j].first = dp[i][j].second = 1e18 ;
}
dp[0][0].first = dp[0][0].second = 0 ;
for(int i = 1 ; i <= n ; ++i)
{
for(int j = 1 ; j <= k ; ++j)
{
long long MAX = dp[i-1][j].second ;
long long a = arr[i] + dp[i-1][j-1].first ;
long long b = dp[i-1][j].first - MAX + max(MAX , arr[i]) ;
if(a < b)
{
dp[i][j].first = arr[i] + dp[i-1][j-1].first ;
dp[i][j].second = arr[i] ;
}
else
{
dp[i][j].first = dp[i-1][j].first - MAX + max(MAX , arr[i]) ;
dp[i][j].second = max(MAX , arr[i]) ;
}
}
}
return cout<<dp[n][k].first<<"\n" , 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |