Submission #41934

#TimeUsernameProblemLanguageResultExecution timeMemory
41934festSplit the sequence (APIO14_sequence)C++14
0 / 100
1 ms388 KiB
// fest #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define y1 dasdasfasfas #define x1 wqdadfasfasfas #define All(c) c.begin(), c.end() #define SZ(A) (int((A).size())) #define umap unordered_map #define FILENAME "" #define __ fflush(stdout) typedef long long ll; typedef long double ld; using namespace std; void FREOPEN() { #ifdef COMP freopen(".in", "r", stdin); freopen("1.out", "w", stdout); #endif } inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } const int N = 110000, M = 201, inf = 1e9 * 2, MOD = (int)1e9 + 7; char CH[N]; const double eps = 1e-14; const ll INF = 1e18; const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1}; const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1}; int pref[N], a[N], pr[N][M]; ll dp[N][M]; double meet(int a1, ll b1, int a2, ll b2) { return (double)(b2 - b1) / (double)(a1 - a2); } int main() { FREOPEN(); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) scanf("%d ", a + i); for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i]; for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) dp[i][j] = -INF, pr[i][j] = -1; dp[0][0] = 0; for (int bl = 1; bl <= k; bl++) { vector<pair<int, pair<ll, int> > > lines; lines.pb({-pref[bl - 1], {dp[bl - 1][bl - 1], bl - 1}}); int lef = 0; for (int i = bl; i <= n; i++) { int x = pref[n] - pref[i]; while (lef + 1 < SZ(lines) && x * 1ll * lines[lef].F + lines[lef].S.F < x * 1ll * lines[lef + 1].F + lines[lef + 1].S.F) lef++; dp[i][bl] = x * 1ll * pref[i] + x * 1ll * lines[lef].F + lines[lef].S.F; pr[i][bl] = lines[lef].S.S; while (SZ(lines) >= 2 && meet(lines.back().F, lines.back().S.F, -pref[i], dp[i][bl - 1]) > meet(lines[SZ(lines) - 2].F, lines[SZ(lines) - 2].S.F, -pref[i], dp[i][bl - 1]) - eps) lines.pop_back(); lines.pb({-pref[i], {dp[i][bl - 1], i}}); } } int pos = 0; ll ans = -INF; for (int i = 1; i <= n; i++) { if (ans < dp[i][k]) { ans = dp[i][k]; pos = i; } } vector<int> out; cout << ans << endl; int bl = k; while (pos > 0) { out.pb(pos); pos = pr[pos][bl]; bl--; } sort(All(out)); for (auto i : out) printf("%d ", i); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:53:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d ", a + i);
                                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...