#include <bits/stdc++.h>
using namespace std;
#define file "test"
#define ll long long
#define X first
#define Y second
typedef pair <int, int> ii;
const int oo = 1e9 + 7;
const int mod = 1e6;
const int N = 100005;
int n, k;
int a[N];
int f[N][N];
void enter()
{
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
}
void solve()
{
memset(f, oo, sizeof f);
f[1][0] = 0;
for(int i = 1; i <= n; i++)
f[1][i] = max(f[1][i - 1], a[i]);
for(int i = 2; i <= k; i++)
{
stack <ii> s;
for(int j = i; j <= n; j++)
{
int Min = f[i - 1][j - 1];
while(!s.empty() && a[s.top().Y] <= a[j])
{
Min = min(Min, s.top().X);
s.pop();
}
f[i][j] = min(f[i][s.empty() ? 0 : s.top().Y], Min + a[j]);
s.push({Min, j});
}
}
cout << f[k][n];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen(file".INP", "r", stdin);
// freopen(file".OUT", "w", stdout);
enter();
solve();
return 0;
}
Compilation message
/tmp/ccgfuCjr.o: In function `enter()':
blocks.cpp:(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `n' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0x7): relocation truncated to fit: R_X86_64_32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a(globals_io.o)
blocks.cpp:(.text+0x16): relocation truncated to fit: R_X86_64_32 against symbol `k' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0x24): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0x2d): relocation truncated to fit: R_X86_64_32 against symbol `a' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0x44): relocation truncated to fit: R_X86_64_32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a(globals_io.o)
blocks.cpp:(.text+0x56): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccgfuCjr.o
/tmp/ccgfuCjr.o: In function `solve()':
blocks.cpp:(.text+0xb0): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0xd6): relocation truncated to fit: R_X86_64_32S against symbol `a' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0xed): relocation truncated to fit: R_X86_64_PC32 against symbol `k' defined in .bss section in /tmp/ccgfuCjr.o
blocks.cpp:(.text+0x1a9): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status