#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "K blocks"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 1e5 + 7
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
int n, k;
int a[maxn];
pair<int, ll> q[maxn];
ll dp[2][maxn];
void solve()
{
cin >> n >> k;
fi(i, 1, n) cin >> a[i];
int pre = 0, cur = 1;
memset(dp, 60, sizeof dp);
dp[0][0] = 0;
fi(t, 1, k) {
int top = 0;
dp[cur][0] = 1e9;
fi(i, 1, n)
{
dp[cur][i] = 1e9;
ll Min = dp[pre][i - 1];
while(top && a[i] >= a[q[top].first]) {
Min = min(q[top].second, Min);
--top;
}
dp[cur][i] = Min + a[i];
if(top) dp[cur][i] = min(dp[cur][i], dp[cur][q[top].first]);
q[++top] = {i, Min};
}
Log(dp[cur], 1, n);
swap(pre, cur);
}
cout << dp[pre][n];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
blocks.cpp: In function 'void solve()':
blocks.cpp:59:9: error: 'Log' was not declared in this scope; did you mean 'log'?
59 | Log(dp[cur], 1, n);
| ^~~
| log
blocks.cpp: In function 'int main()':
blocks.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~