Submission #856709

#TimeUsernameProblemLanguageResultExecution timeMemory
856709a_l_i_r_e_z_aSplit the sequence (APIO14_sequence)C++14
11 / 100
59 ms131072 KiB
// Be name Khoda // Khodaya khodet komak kon // Hope is last to die #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define pb push_back #define S second #define F first #define mp make_pair #define smax(x, y) (x) = max((x), (y)) #define smin(x, y) (x) = min((x), (y)) #define all(x) (x).begin(), (x).end() #define set_dec(x) cout << fixed << setprecision(x); #define kill(x) cout << x << endl, exit(0) #define sz(x) ((int)(x).size()) #define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); const ll maxN = 1000 + 10, maxK = 210, inf = 1e18 + 7; ll sm[maxN], dp[maxK][maxN]; vector<ll> O[maxK][maxN]; void divide(ll k, ll l, ll r, ll optl, ll optr){ if(r - l < 0) return; ll mid = (l + r) / 2, op = 0; dp[k][mid] = -inf; for(int i = optl; i <= optr; i++){ ll res = dp[k - 1][i] + sm[i] * (sm[mid] - sm[i]); if(res > dp[k][mid]) dp[k][mid] = res, op = i; } O[k][mid] = O[k - 1][op]; O[k][mid].pb(op); divide(k, l, mid - 1, optl, op); divide(k, mid + 1, r, op, optr); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, k; cin >> n >> k; for(int i = 0; i < n; i++){ ll x; cin >> x; sm[i + 1] = sm[i] + x; } for(int i = 1; i <= k; i++) divide(i, 1, n, 0, n); cout << dp[k][n] << '\n'; for(auto u: O[k][n]) cout << u << " "; return 0; }
#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...