#include <stdio.h>
#include <iomanip>
#include <vector>
using namespace std;
const int N = 102;
#define pb push_back
#define ll long long
#define int long long
#define fr first
#define sc second
#define mk make_pair
int b[N][N][N];
int n, a[N], k, t[N * 4], ans = 1e8;
vector < pair < int, int > > lr[N];
void bld(int v = 1, int l = 1, int r = n)
{
if(l == r)
{
t[v] = a[l];
return;
}
else
{
int mid = l + r >> 1ll;
bld(v + v, l, mid);
bld(v + v + 1, mid + 1, r);
}
t[v] = max(t[v + v], t[v + v + 1]);
}
int getmx(int ql, int qr, int v = 1, int l = 1, int r = n)
{
if(l > qr || ql > r) return 0;
if(ql <= l && r <= qr)
return t[v];
int mid = l + r >> 1ll;
return max(getmx(ql, qr, v + v, l, mid), getmx(ql, qr, v + v + 1, mid + 1, r));
}
main()
{
scanf("%lld %lld", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
bld();
for(int i = 1; i <= k; i++)
{
for(int l = 1; l <= n; l++)
{
for(int r = 1; r <= n; r++)
{
b[i][l][r] = 1e9;
}
}
}
for(int r = 1; r <= n; r++)
{
b[1][1][r] = getmx(1, r);
}
for(int i = 2; i <= k; i++)
{
for(int l = i; l <= n; l++)
{
for(int r = l; r <= n; r++)
{
for(int j = 1; j < l; j++)
{
b[i][l][r] = min(b[i - 1][j][l - 1], b[i][l][r]);
}
b[i][l][r] += getmx(l, r);
}
}
}
for(int l = k; l <= n; l++)
{
ans = min(ans, b[k][l][n]);
}
//for(int r = 1; r <= n; r++)
//{
//printf("%lld %lld ", 1ll, r);
//printf("%lld\n", b[1][1][r]);
//}
printf("%lld\n", ans);
}
/**
5 2
4 5 1 2 3
5 2
1 2 3 4 5
5 1
1 2 3 4 5
**/
/**
5 3
1 2 3 4 5
100 50
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
**/
Compilation message
blocks.cpp: In function 'void bld(long long int, long long int, long long int)':
blocks.cpp:29:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1ll;
~~^~~
blocks.cpp: In function 'long long int getmx(long long int, long long int, long long int, long long int, long long int)':
blocks.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1ll;
~~^~~
blocks.cpp: At global scope:
blocks.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
blocks.cpp: In function 'int main()':
blocks.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &a[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
500 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
1 ms |
552 KB |
Output is correct |
5 |
Correct |
2 ms |
552 KB |
Output is correct |
6 |
Correct |
1 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
608 KB |
Output is correct |
11 |
Correct |
1 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
4 ms |
1012 KB |
Output is correct |
14 |
Correct |
5 ms |
1012 KB |
Output is correct |
15 |
Correct |
1 ms |
1012 KB |
Output is correct |
16 |
Correct |
3 ms |
1012 KB |
Output is correct |
17 |
Correct |
1 ms |
1012 KB |
Output is correct |
18 |
Correct |
17 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1028 KB |
Output is correct |
2 |
Correct |
1 ms |
1028 KB |
Output is correct |
3 |
Correct |
1 ms |
1028 KB |
Output is correct |
4 |
Correct |
1 ms |
1028 KB |
Output is correct |
5 |
Correct |
2 ms |
1028 KB |
Output is correct |
6 |
Correct |
2 ms |
1028 KB |
Output is correct |
7 |
Correct |
2 ms |
1028 KB |
Output is correct |
8 |
Correct |
2 ms |
1028 KB |
Output is correct |
9 |
Correct |
2 ms |
1028 KB |
Output is correct |
10 |
Correct |
2 ms |
1028 KB |
Output is correct |
11 |
Correct |
1 ms |
1028 KB |
Output is correct |
12 |
Correct |
1 ms |
1028 KB |
Output is correct |
13 |
Correct |
1 ms |
1028 KB |
Output is correct |
14 |
Correct |
2 ms |
1028 KB |
Output is correct |
15 |
Correct |
2 ms |
1028 KB |
Output is correct |
16 |
Correct |
2 ms |
1028 KB |
Output is correct |
17 |
Correct |
2 ms |
1028 KB |
Output is correct |
18 |
Correct |
2 ms |
1028 KB |
Output is correct |
19 |
Correct |
2 ms |
1028 KB |
Output is correct |
20 |
Correct |
2 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
4652 KB |
Output is correct |
2 |
Correct |
1 ms |
4652 KB |
Output is correct |
3 |
Correct |
2 ms |
4652 KB |
Output is correct |
4 |
Correct |
1 ms |
4652 KB |
Output is correct |
5 |
Correct |
1 ms |
4652 KB |
Output is correct |
6 |
Correct |
2 ms |
4652 KB |
Output is correct |
7 |
Correct |
1 ms |
4652 KB |
Output is correct |
8 |
Correct |
2 ms |
4652 KB |
Output is correct |
9 |
Correct |
2 ms |
4652 KB |
Output is correct |
10 |
Correct |
2 ms |
4652 KB |
Output is correct |
11 |
Correct |
2 ms |
4652 KB |
Output is correct |
12 |
Correct |
2 ms |
4652 KB |
Output is correct |
13 |
Correct |
15 ms |
4652 KB |
Output is correct |
14 |
Correct |
14 ms |
4652 KB |
Output is correct |
15 |
Correct |
29 ms |
8764 KB |
Output is correct |
16 |
Correct |
30 ms |
8764 KB |
Output is correct |
17 |
Correct |
26 ms |
8764 KB |
Output is correct |
18 |
Correct |
30 ms |
8892 KB |
Output is correct |
19 |
Correct |
32 ms |
8892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
284 ms |
17216 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |