Submission #7149

# Submission time Handle Problem Language Result Execution time Memory
7149 2014-07-26T14:58:26 Z baneling100 K blocks (IZhO14_blocks) C++
0 / 100
0 ms 2376 KB
#include <stdio.h>
#include <vector>
#define INF 0x7fffffff

using namespace std;

typedef pair <int,int> ppair;
vector <ppair> S;
int N, K, A[100001], D[2][100001];

void input(void)
{
    int i;

    scanf("%d %d",&N,&K);
    for(i=1 ; i<=N ; i++)
        scanf("%d",&A[i]);
}

void process(void)
{
    int i, j, x, y;

    for(i=1 ; i<=K ; i++)
    {
        S.clear();
        for(j=i ; j<=N ; j++)
        {
            y=D[1-(i%2)][j-1];
            while(!S.empty() && S.back().first<=A[j])
            {
                if(y>S.back().second)
                    y=S.back().second;
                S.pop_back();
            }
            if(S.empty())
                x=INF;
            else
                x=S.back().first+S.back().second;
            if(x>A[j]+y)
            {
                x=A[j]+y;
                S.push_back(make_pair(A[j],y));
            }
            D[i%2][j]=x;
        }
    }
}

void output(void)
{
    printf("%d",D[K%2][N]);
}

int main(void)
{
    input();
    process();
    output();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2376 KB Output is correct
2 Incorrect 0 ms 2376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -