This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int K = 105;
ll dp[K][N];
ll a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[1][i] = max(dp[1][i - 1], a[i]);
}
for (int i = 2; i <= k; i++) {
vector<pair<ll, ll>> kek;
for (int j = 1; j <= n; j++) {
ll cur = dp[i - 1][j - 1];
if (!cur) {
cur = 1e12;
}
while (!kek.empty() && a[j] + cur <= max(kek.back().first, a[j]) + kek.back().second) {
kek.pop_back();
}
if (kek.empty()) {
kek.emplace_back(a[j], cur);
}
dp[i][j] = max(kek.back().first, a[j]) + kek.back().second;
}
}
cout << dp[k][n];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |