#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 5;
const int maxK = 1e2 + 1;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, k, a[maxN];
int f[maxN][maxK];
void ReadInput()
{
cin >> n >> k;
for(int i=1; i<=n; i++) cin >> a[i];
}
void Solve()
{
memset(f, 3, sizeof f);
f[0][0] = 0;
for(int j=1; j<=k; j++)
{
vector<pair<int, int>> vc;
for(int i=j; i<=n; i++)
{
int _min = f[i - 1][j - 1];
while(!vc.empty() && a[vc.back().fi] <= a[i])
{
_min = min(_min, vc.back().se);
vc.pop_back();
}
if(!vc.empty()) f[i][j] = f[vc.back().fi][j];
f[i][j] = min(f[i][j], _min + a[i]);
vc.pb({i, _min});
}
}
cout << f[n][k];
}
int32_t main()
{
// freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
79268 KB |
Output is correct |
2 |
Correct |
29 ms |
79308 KB |
Output is correct |
3 |
Correct |
31 ms |
79316 KB |
Output is correct |
4 |
Correct |
33 ms |
79248 KB |
Output is correct |
5 |
Correct |
30 ms |
79300 KB |
Output is correct |
6 |
Correct |
29 ms |
79308 KB |
Output is correct |
7 |
Correct |
34 ms |
79368 KB |
Output is correct |
8 |
Correct |
29 ms |
79364 KB |
Output is correct |
9 |
Correct |
30 ms |
79244 KB |
Output is correct |
10 |
Correct |
29 ms |
79336 KB |
Output is correct |
11 |
Correct |
30 ms |
79368 KB |
Output is correct |
12 |
Correct |
31 ms |
79444 KB |
Output is correct |
13 |
Correct |
32 ms |
79284 KB |
Output is correct |
14 |
Correct |
33 ms |
79336 KB |
Output is correct |
15 |
Correct |
32 ms |
79356 KB |
Output is correct |
16 |
Correct |
32 ms |
79296 KB |
Output is correct |
17 |
Correct |
36 ms |
79372 KB |
Output is correct |
18 |
Correct |
35 ms |
79316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
79252 KB |
Output is correct |
2 |
Correct |
30 ms |
79344 KB |
Output is correct |
3 |
Correct |
31 ms |
79300 KB |
Output is correct |
4 |
Correct |
32 ms |
79308 KB |
Output is correct |
5 |
Correct |
31 ms |
79316 KB |
Output is correct |
6 |
Correct |
31 ms |
79352 KB |
Output is correct |
7 |
Correct |
34 ms |
79316 KB |
Output is correct |
8 |
Correct |
30 ms |
79316 KB |
Output is correct |
9 |
Correct |
30 ms |
79312 KB |
Output is correct |
10 |
Correct |
31 ms |
79368 KB |
Output is correct |
11 |
Correct |
31 ms |
79308 KB |
Output is correct |
12 |
Correct |
32 ms |
79368 KB |
Output is correct |
13 |
Correct |
36 ms |
79300 KB |
Output is correct |
14 |
Correct |
32 ms |
79256 KB |
Output is correct |
15 |
Correct |
31 ms |
79316 KB |
Output is correct |
16 |
Correct |
30 ms |
79268 KB |
Output is correct |
17 |
Correct |
31 ms |
79320 KB |
Output is correct |
18 |
Correct |
31 ms |
79276 KB |
Output is correct |
19 |
Correct |
30 ms |
79312 KB |
Output is correct |
20 |
Correct |
32 ms |
79376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
79268 KB |
Output is correct |
2 |
Correct |
29 ms |
79308 KB |
Output is correct |
3 |
Correct |
31 ms |
79316 KB |
Output is correct |
4 |
Correct |
33 ms |
79248 KB |
Output is correct |
5 |
Correct |
30 ms |
79300 KB |
Output is correct |
6 |
Correct |
29 ms |
79308 KB |
Output is correct |
7 |
Correct |
34 ms |
79368 KB |
Output is correct |
8 |
Correct |
29 ms |
79364 KB |
Output is correct |
9 |
Correct |
30 ms |
79244 KB |
Output is correct |
10 |
Correct |
29 ms |
79336 KB |
Output is correct |
11 |
Correct |
30 ms |
79368 KB |
Output is correct |
12 |
Correct |
31 ms |
79444 KB |
Output is correct |
13 |
Correct |
32 ms |
79284 KB |
Output is correct |
14 |
Correct |
33 ms |
79336 KB |
Output is correct |
15 |
Correct |
32 ms |
79356 KB |
Output is correct |
16 |
Correct |
32 ms |
79296 KB |
Output is correct |
17 |
Correct |
36 ms |
79372 KB |
Output is correct |
18 |
Correct |
35 ms |
79316 KB |
Output is correct |
19 |
Correct |
31 ms |
79252 KB |
Output is correct |
20 |
Correct |
30 ms |
79344 KB |
Output is correct |
21 |
Correct |
31 ms |
79300 KB |
Output is correct |
22 |
Correct |
32 ms |
79308 KB |
Output is correct |
23 |
Correct |
31 ms |
79316 KB |
Output is correct |
24 |
Correct |
31 ms |
79352 KB |
Output is correct |
25 |
Correct |
34 ms |
79316 KB |
Output is correct |
26 |
Correct |
30 ms |
79316 KB |
Output is correct |
27 |
Correct |
30 ms |
79312 KB |
Output is correct |
28 |
Correct |
31 ms |
79368 KB |
Output is correct |
29 |
Correct |
31 ms |
79308 KB |
Output is correct |
30 |
Correct |
32 ms |
79368 KB |
Output is correct |
31 |
Correct |
36 ms |
79300 KB |
Output is correct |
32 |
Correct |
32 ms |
79256 KB |
Output is correct |
33 |
Correct |
31 ms |
79316 KB |
Output is correct |
34 |
Correct |
30 ms |
79268 KB |
Output is correct |
35 |
Correct |
31 ms |
79320 KB |
Output is correct |
36 |
Correct |
31 ms |
79276 KB |
Output is correct |
37 |
Correct |
30 ms |
79312 KB |
Output is correct |
38 |
Correct |
32 ms |
79376 KB |
Output is correct |
39 |
Correct |
31 ms |
79276 KB |
Output is correct |
40 |
Correct |
32 ms |
79308 KB |
Output is correct |
41 |
Correct |
32 ms |
79336 KB |
Output is correct |
42 |
Correct |
36 ms |
79320 KB |
Output is correct |
43 |
Correct |
30 ms |
79280 KB |
Output is correct |
44 |
Correct |
32 ms |
79260 KB |
Output is correct |
45 |
Correct |
31 ms |
79392 KB |
Output is correct |
46 |
Correct |
29 ms |
79264 KB |
Output is correct |
47 |
Correct |
30 ms |
79308 KB |
Output is correct |
48 |
Correct |
30 ms |
79300 KB |
Output is correct |
49 |
Correct |
34 ms |
79368 KB |
Output is correct |
50 |
Correct |
31 ms |
79308 KB |
Output is correct |
51 |
Correct |
31 ms |
79292 KB |
Output is correct |
52 |
Correct |
32 ms |
79308 KB |
Output is correct |
53 |
Correct |
31 ms |
79300 KB |
Output is correct |
54 |
Correct |
31 ms |
79376 KB |
Output is correct |
55 |
Correct |
31 ms |
79308 KB |
Output is correct |
56 |
Correct |
33 ms |
79276 KB |
Output is correct |
57 |
Correct |
33 ms |
79308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
79268 KB |
Output is correct |
2 |
Correct |
29 ms |
79308 KB |
Output is correct |
3 |
Correct |
31 ms |
79316 KB |
Output is correct |
4 |
Correct |
33 ms |
79248 KB |
Output is correct |
5 |
Correct |
30 ms |
79300 KB |
Output is correct |
6 |
Correct |
29 ms |
79308 KB |
Output is correct |
7 |
Correct |
34 ms |
79368 KB |
Output is correct |
8 |
Correct |
29 ms |
79364 KB |
Output is correct |
9 |
Correct |
30 ms |
79244 KB |
Output is correct |
10 |
Correct |
29 ms |
79336 KB |
Output is correct |
11 |
Correct |
30 ms |
79368 KB |
Output is correct |
12 |
Correct |
31 ms |
79444 KB |
Output is correct |
13 |
Correct |
32 ms |
79284 KB |
Output is correct |
14 |
Correct |
33 ms |
79336 KB |
Output is correct |
15 |
Correct |
32 ms |
79356 KB |
Output is correct |
16 |
Correct |
32 ms |
79296 KB |
Output is correct |
17 |
Correct |
36 ms |
79372 KB |
Output is correct |
18 |
Correct |
35 ms |
79316 KB |
Output is correct |
19 |
Correct |
31 ms |
79252 KB |
Output is correct |
20 |
Correct |
30 ms |
79344 KB |
Output is correct |
21 |
Correct |
31 ms |
79300 KB |
Output is correct |
22 |
Correct |
32 ms |
79308 KB |
Output is correct |
23 |
Correct |
31 ms |
79316 KB |
Output is correct |
24 |
Correct |
31 ms |
79352 KB |
Output is correct |
25 |
Correct |
34 ms |
79316 KB |
Output is correct |
26 |
Correct |
30 ms |
79316 KB |
Output is correct |
27 |
Correct |
30 ms |
79312 KB |
Output is correct |
28 |
Correct |
31 ms |
79368 KB |
Output is correct |
29 |
Correct |
31 ms |
79308 KB |
Output is correct |
30 |
Correct |
32 ms |
79368 KB |
Output is correct |
31 |
Correct |
36 ms |
79300 KB |
Output is correct |
32 |
Correct |
32 ms |
79256 KB |
Output is correct |
33 |
Correct |
31 ms |
79316 KB |
Output is correct |
34 |
Correct |
30 ms |
79268 KB |
Output is correct |
35 |
Correct |
31 ms |
79320 KB |
Output is correct |
36 |
Correct |
31 ms |
79276 KB |
Output is correct |
37 |
Correct |
30 ms |
79312 KB |
Output is correct |
38 |
Correct |
32 ms |
79376 KB |
Output is correct |
39 |
Correct |
31 ms |
79276 KB |
Output is correct |
40 |
Correct |
32 ms |
79308 KB |
Output is correct |
41 |
Correct |
32 ms |
79336 KB |
Output is correct |
42 |
Correct |
36 ms |
79320 KB |
Output is correct |
43 |
Correct |
30 ms |
79280 KB |
Output is correct |
44 |
Correct |
32 ms |
79260 KB |
Output is correct |
45 |
Correct |
31 ms |
79392 KB |
Output is correct |
46 |
Correct |
29 ms |
79264 KB |
Output is correct |
47 |
Correct |
30 ms |
79308 KB |
Output is correct |
48 |
Correct |
30 ms |
79300 KB |
Output is correct |
49 |
Correct |
34 ms |
79368 KB |
Output is correct |
50 |
Correct |
31 ms |
79308 KB |
Output is correct |
51 |
Correct |
31 ms |
79292 KB |
Output is correct |
52 |
Correct |
32 ms |
79308 KB |
Output is correct |
53 |
Correct |
31 ms |
79300 KB |
Output is correct |
54 |
Correct |
31 ms |
79376 KB |
Output is correct |
55 |
Correct |
31 ms |
79308 KB |
Output is correct |
56 |
Correct |
33 ms |
79276 KB |
Output is correct |
57 |
Correct |
33 ms |
79308 KB |
Output is correct |
58 |
Correct |
37 ms |
79452 KB |
Output is correct |
59 |
Correct |
36 ms |
79956 KB |
Output is correct |
60 |
Correct |
41 ms |
79908 KB |
Output is correct |
61 |
Correct |
114 ms |
80028 KB |
Output is correct |
62 |
Correct |
295 ms |
80836 KB |
Output is correct |
63 |
Correct |
51 ms |
80844 KB |
Output is correct |
64 |
Correct |
167 ms |
80716 KB |
Output is correct |
65 |
Correct |
32 ms |
79332 KB |
Output is correct |
66 |
Correct |
31 ms |
79372 KB |
Output is correct |
67 |
Correct |
31 ms |
79296 KB |
Output is correct |
68 |
Correct |
32 ms |
79264 KB |
Output is correct |
69 |
Correct |
32 ms |
79316 KB |
Output is correct |
70 |
Correct |
31 ms |
79304 KB |
Output is correct |
71 |
Correct |
52 ms |
79520 KB |
Output is correct |
72 |
Correct |
32 ms |
79444 KB |
Output is correct |
73 |
Correct |
41 ms |
79504 KB |
Output is correct |
74 |
Correct |
39 ms |
79952 KB |
Output is correct |
75 |
Correct |
44 ms |
79948 KB |
Output is correct |
76 |
Correct |
111 ms |
80000 KB |
Output is correct |
77 |
Correct |
307 ms |
80832 KB |
Output is correct |
78 |
Correct |
48 ms |
80716 KB |
Output is correct |
79 |
Correct |
164 ms |
80832 KB |
Output is correct |
80 |
Correct |
43 ms |
80716 KB |
Output is correct |
81 |
Correct |
68 ms |
80744 KB |
Output is correct |
82 |
Correct |
297 ms |
80900 KB |
Output is correct |
83 |
Correct |
32 ms |
79444 KB |
Output is correct |
84 |
Correct |
35 ms |
79392 KB |
Output is correct |
85 |
Correct |
55 ms |
79644 KB |
Output is correct |
86 |
Correct |
34 ms |
79612 KB |
Output is correct |
87 |
Correct |
38 ms |
79560 KB |
Output is correct |
88 |
Correct |
36 ms |
80356 KB |
Output is correct |
89 |
Correct |
43 ms |
80524 KB |
Output is correct |
90 |
Correct |
116 ms |
80544 KB |
Output is correct |
91 |
Correct |
340 ms |
82540 KB |
Output is correct |
92 |
Correct |
48 ms |
82396 KB |
Output is correct |
93 |
Correct |
176 ms |
82588 KB |
Output is correct |
94 |
Correct |
33 ms |
79432 KB |
Output is correct |
95 |
Correct |
49 ms |
79444 KB |
Output is correct |
96 |
Correct |
32 ms |
79300 KB |
Output is correct |
97 |
Correct |
31 ms |
79288 KB |
Output is correct |
98 |
Correct |
31 ms |
79308 KB |
Output is correct |
99 |
Correct |
31 ms |
79296 KB |
Output is correct |