Submission #155533

# Submission time Handle Problem Language Result Execution time Memory
155533 2019-09-29T01:26:12 Z Learner99 K blocks (IZhO14_blocks) C++14
0 / 100
26 ms 16184 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define N 100006
int inf =10000000000006;

int dp[N][101];
int ind[N][101];


int32_t main()
{
    int n, k;
    cin>>n>>k;

    vector < int > a(n+1);
    for(int i=1;i<=n;i++)
        cin>>a[i];

    a[0] = inf;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            dp[i][j] = inf;
            ind[i][j] = 0;
        }
    }

    dp[1][1] = a[1];
    ind[1][1] = 1;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if( a[ind[i-1][j]] < a[i])
            {
                dp[i][j] = dp[i-1][j] + a[i] - a[ind[i-1][j]];
                ind[i][j] = i;
            }
            else
            {
                dp[i][j] = dp[i-1][j];
                ind[i][j] = ind[i-1][j];
            }

            if( dp[i-1][j-1] + a[i] < dp[i][j])
            {
                dp[i][j] = dp[i-1][j-1] + a[i];
                ind[i][j] = i;
            }
        }
    }

    cout<<dp[n][k]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 14 ms 376 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 16184 KB Output isn't correct
2 Halted 0 ms 0 KB -