#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,m,n) for(ll i=m; i<=n; i++)
#define reb(i,m,n) for(ll i=m; i>=n; i--)
#define ii pair<ll,ll>
#define fs first
#define se second
#define pb push_back
#define sz(v) (ll)v.size()
#define ALL(v) v.begin(), v.end()
#define bit(msk, i) ((msk >> i) & 1)
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
using namespace std;
//#ifndef ONLINE_JUDGE
// #include "debug.h"
//#else
// #define deb(...) 23
// #define __
// #define n____
//#endif
mt19937 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand (ll l, ll r) {
return l + rd()%(r - l + 1);
}
const ll N = 1e5 + 7;
const ll Mod = 1e9 + 7;
const ll bse = 137;
const ll INF = 1e18;
ll n, K;
ll a[N];
ll dp[105][N];
void chloe_solution () {
cin >> n >> K;
rep (i, 1, n) cin >> a[i];
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
rep (i, 1, K) {
stack<pair<ll,int>> op;
rep (j, 1, n) {
ll mnV = dp[i - 1][j - 1];
while (!op.empty() && a[op.top().se] <= a[j]) {
mnV = min(mnV, op.top().fs);
op.pop();
}
dp[i][j] = min(dp[i][(op.empty() == 1) ? 0 : op.top().se], mnV + a[j]);
op.push({mnV, j});
}
}
cout << dp[K][n] <<"\n";
}
int main() {
//file("c");
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll num_test = 1;
// cin >> num_test;
while (num_test--)
chloe_solution();
}
/*
hbjcyibtycdi!ttcotodf
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
82516 KB |
Output is correct |
2 |
Correct |
25 ms |
82472 KB |
Output is correct |
3 |
Correct |
26 ms |
82484 KB |
Output is correct |
4 |
Correct |
26 ms |
82516 KB |
Output is correct |
5 |
Correct |
27 ms |
82464 KB |
Output is correct |
6 |
Correct |
28 ms |
82420 KB |
Output is correct |
7 |
Correct |
26 ms |
82476 KB |
Output is correct |
8 |
Correct |
26 ms |
82512 KB |
Output is correct |
9 |
Correct |
27 ms |
82436 KB |
Output is correct |
10 |
Correct |
27 ms |
82468 KB |
Output is correct |
11 |
Correct |
26 ms |
82492 KB |
Output is correct |
12 |
Correct |
27 ms |
82468 KB |
Output is correct |
13 |
Correct |
27 ms |
82520 KB |
Output is correct |
14 |
Correct |
28 ms |
82520 KB |
Output is correct |
15 |
Correct |
27 ms |
82504 KB |
Output is correct |
16 |
Correct |
28 ms |
82516 KB |
Output is correct |
17 |
Correct |
36 ms |
82452 KB |
Output is correct |
18 |
Correct |
31 ms |
82468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
82516 KB |
Output is correct |
2 |
Correct |
27 ms |
82516 KB |
Output is correct |
3 |
Correct |
26 ms |
82512 KB |
Output is correct |
4 |
Correct |
27 ms |
82456 KB |
Output is correct |
5 |
Correct |
27 ms |
82512 KB |
Output is correct |
6 |
Correct |
27 ms |
82416 KB |
Output is correct |
7 |
Correct |
31 ms |
82516 KB |
Output is correct |
8 |
Correct |
27 ms |
82448 KB |
Output is correct |
9 |
Correct |
28 ms |
82420 KB |
Output is correct |
10 |
Correct |
27 ms |
82400 KB |
Output is correct |
11 |
Correct |
33 ms |
82512 KB |
Output is correct |
12 |
Correct |
28 ms |
82400 KB |
Output is correct |
13 |
Correct |
29 ms |
82440 KB |
Output is correct |
14 |
Correct |
28 ms |
82512 KB |
Output is correct |
15 |
Correct |
27 ms |
82516 KB |
Output is correct |
16 |
Correct |
27 ms |
82424 KB |
Output is correct |
17 |
Correct |
27 ms |
82396 KB |
Output is correct |
18 |
Correct |
27 ms |
82496 KB |
Output is correct |
19 |
Correct |
28 ms |
82516 KB |
Output is correct |
20 |
Correct |
28 ms |
82468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
82516 KB |
Output is correct |
2 |
Correct |
25 ms |
82472 KB |
Output is correct |
3 |
Correct |
26 ms |
82484 KB |
Output is correct |
4 |
Correct |
26 ms |
82516 KB |
Output is correct |
5 |
Correct |
27 ms |
82464 KB |
Output is correct |
6 |
Correct |
28 ms |
82420 KB |
Output is correct |
7 |
Correct |
26 ms |
82476 KB |
Output is correct |
8 |
Correct |
26 ms |
82512 KB |
Output is correct |
9 |
Correct |
27 ms |
82436 KB |
Output is correct |
10 |
Correct |
27 ms |
82468 KB |
Output is correct |
11 |
Correct |
26 ms |
82492 KB |
Output is correct |
12 |
Correct |
27 ms |
82468 KB |
Output is correct |
13 |
Correct |
27 ms |
82520 KB |
Output is correct |
14 |
Correct |
28 ms |
82520 KB |
Output is correct |
15 |
Correct |
27 ms |
82504 KB |
Output is correct |
16 |
Correct |
28 ms |
82516 KB |
Output is correct |
17 |
Correct |
36 ms |
82452 KB |
Output is correct |
18 |
Correct |
31 ms |
82468 KB |
Output is correct |
19 |
Correct |
27 ms |
82516 KB |
Output is correct |
20 |
Correct |
27 ms |
82516 KB |
Output is correct |
21 |
Correct |
26 ms |
82512 KB |
Output is correct |
22 |
Correct |
27 ms |
82456 KB |
Output is correct |
23 |
Correct |
27 ms |
82512 KB |
Output is correct |
24 |
Correct |
27 ms |
82416 KB |
Output is correct |
25 |
Correct |
31 ms |
82516 KB |
Output is correct |
26 |
Correct |
27 ms |
82448 KB |
Output is correct |
27 |
Correct |
28 ms |
82420 KB |
Output is correct |
28 |
Correct |
27 ms |
82400 KB |
Output is correct |
29 |
Correct |
33 ms |
82512 KB |
Output is correct |
30 |
Correct |
28 ms |
82400 KB |
Output is correct |
31 |
Correct |
29 ms |
82440 KB |
Output is correct |
32 |
Correct |
28 ms |
82512 KB |
Output is correct |
33 |
Correct |
27 ms |
82516 KB |
Output is correct |
34 |
Correct |
27 ms |
82424 KB |
Output is correct |
35 |
Correct |
27 ms |
82396 KB |
Output is correct |
36 |
Correct |
27 ms |
82496 KB |
Output is correct |
37 |
Correct |
28 ms |
82516 KB |
Output is correct |
38 |
Correct |
28 ms |
82468 KB |
Output is correct |
39 |
Correct |
28 ms |
82500 KB |
Output is correct |
40 |
Correct |
27 ms |
82504 KB |
Output is correct |
41 |
Correct |
28 ms |
82500 KB |
Output is correct |
42 |
Correct |
28 ms |
82424 KB |
Output is correct |
43 |
Correct |
28 ms |
82472 KB |
Output is correct |
44 |
Correct |
28 ms |
82396 KB |
Output is correct |
45 |
Correct |
27 ms |
82424 KB |
Output is correct |
46 |
Correct |
27 ms |
82448 KB |
Output is correct |
47 |
Correct |
27 ms |
82508 KB |
Output is correct |
48 |
Correct |
27 ms |
82428 KB |
Output is correct |
49 |
Correct |
28 ms |
82432 KB |
Output is correct |
50 |
Correct |
27 ms |
82516 KB |
Output is correct |
51 |
Correct |
27 ms |
82488 KB |
Output is correct |
52 |
Correct |
28 ms |
82396 KB |
Output is correct |
53 |
Correct |
27 ms |
82472 KB |
Output is correct |
54 |
Correct |
27 ms |
82508 KB |
Output is correct |
55 |
Correct |
27 ms |
82392 KB |
Output is correct |
56 |
Correct |
27 ms |
82408 KB |
Output is correct |
57 |
Correct |
29 ms |
82456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
82516 KB |
Output is correct |
2 |
Correct |
25 ms |
82472 KB |
Output is correct |
3 |
Correct |
26 ms |
82484 KB |
Output is correct |
4 |
Correct |
26 ms |
82516 KB |
Output is correct |
5 |
Correct |
27 ms |
82464 KB |
Output is correct |
6 |
Correct |
28 ms |
82420 KB |
Output is correct |
7 |
Correct |
26 ms |
82476 KB |
Output is correct |
8 |
Correct |
26 ms |
82512 KB |
Output is correct |
9 |
Correct |
27 ms |
82436 KB |
Output is correct |
10 |
Correct |
27 ms |
82468 KB |
Output is correct |
11 |
Correct |
26 ms |
82492 KB |
Output is correct |
12 |
Correct |
27 ms |
82468 KB |
Output is correct |
13 |
Correct |
27 ms |
82520 KB |
Output is correct |
14 |
Correct |
28 ms |
82520 KB |
Output is correct |
15 |
Correct |
27 ms |
82504 KB |
Output is correct |
16 |
Correct |
28 ms |
82516 KB |
Output is correct |
17 |
Correct |
36 ms |
82452 KB |
Output is correct |
18 |
Correct |
31 ms |
82468 KB |
Output is correct |
19 |
Correct |
27 ms |
82516 KB |
Output is correct |
20 |
Correct |
27 ms |
82516 KB |
Output is correct |
21 |
Correct |
26 ms |
82512 KB |
Output is correct |
22 |
Correct |
27 ms |
82456 KB |
Output is correct |
23 |
Correct |
27 ms |
82512 KB |
Output is correct |
24 |
Correct |
27 ms |
82416 KB |
Output is correct |
25 |
Correct |
31 ms |
82516 KB |
Output is correct |
26 |
Correct |
27 ms |
82448 KB |
Output is correct |
27 |
Correct |
28 ms |
82420 KB |
Output is correct |
28 |
Correct |
27 ms |
82400 KB |
Output is correct |
29 |
Correct |
33 ms |
82512 KB |
Output is correct |
30 |
Correct |
28 ms |
82400 KB |
Output is correct |
31 |
Correct |
29 ms |
82440 KB |
Output is correct |
32 |
Correct |
28 ms |
82512 KB |
Output is correct |
33 |
Correct |
27 ms |
82516 KB |
Output is correct |
34 |
Correct |
27 ms |
82424 KB |
Output is correct |
35 |
Correct |
27 ms |
82396 KB |
Output is correct |
36 |
Correct |
27 ms |
82496 KB |
Output is correct |
37 |
Correct |
28 ms |
82516 KB |
Output is correct |
38 |
Correct |
28 ms |
82468 KB |
Output is correct |
39 |
Correct |
28 ms |
82500 KB |
Output is correct |
40 |
Correct |
27 ms |
82504 KB |
Output is correct |
41 |
Correct |
28 ms |
82500 KB |
Output is correct |
42 |
Correct |
28 ms |
82424 KB |
Output is correct |
43 |
Correct |
28 ms |
82472 KB |
Output is correct |
44 |
Correct |
28 ms |
82396 KB |
Output is correct |
45 |
Correct |
27 ms |
82424 KB |
Output is correct |
46 |
Correct |
27 ms |
82448 KB |
Output is correct |
47 |
Correct |
27 ms |
82508 KB |
Output is correct |
48 |
Correct |
27 ms |
82428 KB |
Output is correct |
49 |
Correct |
28 ms |
82432 KB |
Output is correct |
50 |
Correct |
27 ms |
82516 KB |
Output is correct |
51 |
Correct |
27 ms |
82488 KB |
Output is correct |
52 |
Correct |
28 ms |
82396 KB |
Output is correct |
53 |
Correct |
27 ms |
82472 KB |
Output is correct |
54 |
Correct |
27 ms |
82508 KB |
Output is correct |
55 |
Correct |
27 ms |
82392 KB |
Output is correct |
56 |
Correct |
27 ms |
82408 KB |
Output is correct |
57 |
Correct |
29 ms |
82456 KB |
Output is correct |
58 |
Correct |
29 ms |
82600 KB |
Output is correct |
59 |
Correct |
36 ms |
83056 KB |
Output is correct |
60 |
Correct |
34 ms |
83088 KB |
Output is correct |
61 |
Correct |
60 ms |
83128 KB |
Output is correct |
62 |
Correct |
117 ms |
83980 KB |
Output is correct |
63 |
Correct |
36 ms |
83896 KB |
Output is correct |
64 |
Correct |
70 ms |
83916 KB |
Output is correct |
65 |
Correct |
27 ms |
82504 KB |
Output is correct |
66 |
Correct |
26 ms |
82516 KB |
Output is correct |
67 |
Correct |
28 ms |
82516 KB |
Output is correct |
68 |
Correct |
27 ms |
82408 KB |
Output is correct |
69 |
Correct |
27 ms |
82520 KB |
Output is correct |
70 |
Correct |
27 ms |
82528 KB |
Output is correct |
71 |
Correct |
39 ms |
82612 KB |
Output is correct |
72 |
Correct |
28 ms |
82644 KB |
Output is correct |
73 |
Correct |
32 ms |
82656 KB |
Output is correct |
74 |
Correct |
31 ms |
83148 KB |
Output is correct |
75 |
Correct |
34 ms |
83060 KB |
Output is correct |
76 |
Correct |
70 ms |
83040 KB |
Output is correct |
77 |
Correct |
148 ms |
83840 KB |
Output is correct |
78 |
Correct |
38 ms |
84048 KB |
Output is correct |
79 |
Correct |
85 ms |
83964 KB |
Output is correct |
80 |
Correct |
35 ms |
83872 KB |
Output is correct |
81 |
Correct |
45 ms |
83880 KB |
Output is correct |
82 |
Correct |
169 ms |
83924 KB |
Output is correct |
83 |
Correct |
28 ms |
82520 KB |
Output is correct |
84 |
Correct |
28 ms |
82508 KB |
Output is correct |
85 |
Correct |
38 ms |
82672 KB |
Output is correct |
86 |
Correct |
33 ms |
82616 KB |
Output is correct |
87 |
Correct |
31 ms |
82712 KB |
Output is correct |
88 |
Correct |
32 ms |
83316 KB |
Output is correct |
89 |
Correct |
35 ms |
83392 KB |
Output is correct |
90 |
Correct |
66 ms |
83420 KB |
Output is correct |
91 |
Correct |
140 ms |
84556 KB |
Output is correct |
92 |
Correct |
39 ms |
84524 KB |
Output is correct |
93 |
Correct |
94 ms |
84548 KB |
Output is correct |
94 |
Correct |
29 ms |
82572 KB |
Output is correct |
95 |
Correct |
36 ms |
82664 KB |
Output is correct |
96 |
Correct |
29 ms |
82528 KB |
Output is correct |
97 |
Correct |
28 ms |
82500 KB |
Output is correct |
98 |
Correct |
28 ms |
82432 KB |
Output is correct |
99 |
Correct |
29 ms |
82508 KB |
Output is correct |