답안 #14805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14805 2015-06-26T15:33:11 Z erdemkiraz K개의 묶음 (IZhO14_blocks) C++
100 / 100
182 ms 3672 KB
#include <iostream>

using namespace std;

const int inf = 1e9 + 5;
const int N = 1e5 + 5;

int n, k, a[N], dp[N], bef[N];
pair < int, int > p[N];

int main () {
    
    cin >> n >> k;
    
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        bef[i] = max(bef[i - 1], a[i]);
    }
    
    for(int j = 2; j <= k; j++) {
        int sz = 0;
        for(int i = 1; i <= n; i++) {
            int ans = j <= i ? bef[i - 1] : inf;
            bef[i - 1] = dp[i - 1];
            while(sz and a[i] >= p[sz - 1].first)
                ans = min(ans, p[--sz].second);
            if(!sz or a[i] + ans < p[sz - 1].first + p[sz - 1].second)
                p[sz++] = make_pair(a[i], ans);
            dp[i] = p[sz - 1].first + p[sz - 1].second;
        }
        bef[n] = dp[n];
    }
    
    cout << bef[n] << endl;
    
    return 0;
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3672 KB Output is correct
2 Correct 0 ms 3672 KB Output is correct
3 Correct 0 ms 3672 KB Output is correct
4 Correct 0 ms 3672 KB Output is correct
5 Correct 0 ms 3672 KB Output is correct
6 Correct 0 ms 3672 KB Output is correct
7 Correct 0 ms 3672 KB Output is correct
8 Correct 0 ms 3672 KB Output is correct
9 Correct 0 ms 3672 KB Output is correct
10 Correct 0 ms 3672 KB Output is correct
11 Correct 0 ms 3672 KB Output is correct
12 Correct 0 ms 3672 KB Output is correct
13 Correct 0 ms 3672 KB Output is correct
14 Correct 0 ms 3672 KB Output is correct
15 Correct 0 ms 3672 KB Output is correct
16 Correct 0 ms 3672 KB Output is correct
17 Correct 0 ms 3672 KB Output is correct
18 Correct 0 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 0 ms 3672 KB Output is correct
3 Correct 0 ms 3672 KB Output is correct
4 Correct 0 ms 3672 KB Output is correct
5 Correct 0 ms 3672 KB Output is correct
6 Correct 0 ms 3672 KB Output is correct
7 Correct 0 ms 3672 KB Output is correct
8 Correct 0 ms 3672 KB Output is correct
9 Correct 0 ms 3672 KB Output is correct
10 Correct 0 ms 3672 KB Output is correct
11 Correct 0 ms 3672 KB Output is correct
12 Correct 0 ms 3672 KB Output is correct
13 Correct 0 ms 3672 KB Output is correct
14 Correct 0 ms 3672 KB Output is correct
15 Correct 0 ms 3672 KB Output is correct
16 Correct 0 ms 3672 KB Output is correct
17 Correct 0 ms 3672 KB Output is correct
18 Correct 0 ms 3672 KB Output is correct
19 Correct 0 ms 3672 KB Output is correct
20 Correct 0 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3672 KB Output is correct
2 Correct 0 ms 3672 KB Output is correct
3 Correct 0 ms 3672 KB Output is correct
4 Correct 0 ms 3672 KB Output is correct
5 Correct 0 ms 3672 KB Output is correct
6 Correct 0 ms 3672 KB Output is correct
7 Correct 0 ms 3672 KB Output is correct
8 Correct 0 ms 3672 KB Output is correct
9 Correct 0 ms 3672 KB Output is correct
10 Correct 0 ms 3672 KB Output is correct
11 Correct 0 ms 3672 KB Output is correct
12 Correct 0 ms 3672 KB Output is correct
13 Correct 0 ms 3672 KB Output is correct
14 Correct 0 ms 3672 KB Output is correct
15 Correct 0 ms 3672 KB Output is correct
16 Correct 0 ms 3672 KB Output is correct
17 Correct 0 ms 3672 KB Output is correct
18 Correct 0 ms 3672 KB Output is correct
19 Correct 0 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3672 KB Output is correct
2 Correct 19 ms 3672 KB Output is correct
3 Correct 23 ms 3672 KB Output is correct
4 Correct 56 ms 3672 KB Output is correct
5 Correct 149 ms 3672 KB Output is correct
6 Correct 39 ms 3672 KB Output is correct
7 Correct 88 ms 3672 KB Output is correct
8 Correct 0 ms 3672 KB Output is correct
9 Correct 0 ms 3672 KB Output is correct
10 Correct 0 ms 3672 KB Output is correct
11 Correct 0 ms 3672 KB Output is correct
12 Correct 0 ms 3672 KB Output is correct
13 Correct 0 ms 3672 KB Output is correct
14 Correct 10 ms 3672 KB Output is correct
15 Correct 4 ms 3672 KB Output is correct
16 Correct 8 ms 3672 KB Output is correct
17 Correct 22 ms 3672 KB Output is correct
18 Correct 18 ms 3672 KB Output is correct
19 Correct 53 ms 3672 KB Output is correct
20 Correct 150 ms 3672 KB Output is correct
21 Correct 54 ms 3672 KB Output is correct
22 Correct 91 ms 3672 KB Output is correct
23 Correct 40 ms 3672 KB Output is correct
24 Correct 54 ms 3672 KB Output is correct
25 Correct 144 ms 3672 KB Output is correct
26 Correct 0 ms 3672 KB Output is correct
27 Correct 0 ms 3672 KB Output is correct
28 Correct 20 ms 3672 KB Output is correct
29 Correct 3 ms 3672 KB Output is correct
30 Correct 5 ms 3672 KB Output is correct
31 Correct 20 ms 3672 KB Output is correct
32 Correct 24 ms 3672 KB Output is correct
33 Correct 64 ms 3672 KB Output is correct
34 Correct 182 ms 3672 KB Output is correct
35 Correct 37 ms 3672 KB Output is correct
36 Correct 108 ms 3672 KB Output is correct
37 Correct 4 ms 3672 KB Output is correct
38 Correct 16 ms 3672 KB Output is correct
39 Correct 0 ms 3672 KB Output is correct
40 Correct 1 ms 3672 KB Output is correct
41 Correct 0 ms 3672 KB Output is correct
42 Correct 0 ms 3672 KB Output is correct