#include <stdio.h>
#include <iomanip>
#include <set>
using namespace std;
const int N = 200;
#define pb insert
#define ll long long
#define int long long
#define fr first
#define sc second
#define mk make_pair
ll ans = 2e9;
int n, a[N + 1], k, t[N * 4];
set < pair < int, int > > lr[201];
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]);
}
void brute(int l, int r, int q)
{
if(q == 1)
{
//printf("%lld %lld %lld\n\n", k - q + 1, l, n);
lr[k - q].pb( mk( l, n ) );
return;
}
if(l == n) return;
else
{
for(int i = r; i <= n - q + 1; i++)
{
//printf("%lld %lld %lld\n", k - q + 1, l, i);
lr[k - q].pb( mk( l, i ) );
brute(i + 1, i + 1, q - 1);
}
}
}
int getmx(int ql, int qr, int v = 1, int l = 1, int r = n)
{
if(l > qr || ql > r) return 0ll;
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));
}
void calc(int cur, int q, ll psum = 0ll/**, int prer = 0**/)
{
if(q == 0)
{
ans = min(ans, psum);
return;
}
else
{
for(pair < int, int > i : lr[cur])
{
/***if(lr[cur][i].fr <= prer);
else***/ calc(cur + 1, q - 1, psum + getmx(i.fr, i.sc)/***, lr[cur][i].sc***/);
}
}
}
main()
{
scanf("%lld %lld", &n, &k);
//scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
//scanf("%d", &a[i]);
bld();
brute(1, 1, k);
calc(0, k);
printf("%lld", ans);
}
/**
5 3
1 2 3 4 5
**/
Compilation message
blocks.cpp: In function 'void bld(long long int, long long int, long long int)':
blocks.cpp:28: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:60:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1ll;
~~^~~
blocks.cpp: At global scope:
blocks.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
blocks.cpp: In function 'int main()':
blocks.cpp:83: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:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &a[i]);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
564 KB |
Output is correct |
2 |
Correct |
2 ms |
576 KB |
Output is correct |
3 |
Correct |
2 ms |
576 KB |
Output is correct |
4 |
Correct |
2 ms |
576 KB |
Output is correct |
5 |
Correct |
2 ms |
576 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
644 KB |
Output is correct |
10 |
Incorrect |
3 ms |
656 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1067 ms |
1048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2 ms |
1048 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |