#include <bits/stdc++.h>
#define no "NO"
#define yes "YES"
#define F first
#define S second
#define vec vector
#define task "main"
#define ll long long
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())
using namespace std;
template<typename U, typename V> bool maximize(U &a, V b) {
if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool minimize(U &a, V b) {
if (a > b) { a = b; return 1; } return 0;
}
const int N = (int)1e5 + 9;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int n, k;
int a[N];
ll sum[N], dp[202][N], bestPos[202][N];
ll cost(int i, int j) {
return (sum[j] - sum[i - 1]) * (sum[n] - sum[j]);
}
void solve(int id, int l, int r, int optL, int optR) {
if (l > r) return;
int mid = (l + r) >> 1;
dp[id][mid] = 0;
FOR(i, optL, optR) {
ll newCost = dp[id - 1][i] + cost(i + 1, mid);
if (maximize(dp[id][mid], newCost)) bestPos[id][mid] = i;
}
solve(id, l, mid - 1, optL, bestPos[id][mid]);
solve(id, mid + 1, r, bestPos[id][mid], optR);
}
void main_code() {
cin >> n >> k;
FOR(i, 1, n) cin >> a[i], sum[i] = sum[i - 1] + a[i];
FOR(i, 1, n) dp[1][i] = cost(1, i);
FOR(i, 2, k + 1) solve(i, 1, n, 1, n);
cout << dp[k + 1][n] << "\n";
vector<int> trace;
int p = n, id = k + 1;
while (p > 0) {
p = bestPos[id][p];
trace.push_back(p);
id--;
}
FOD(i, k - 1, 0) cout << trace[i] << " ";
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
const bool MULTITEST = 0;
int num_test = 1; if (MULTITEST) cin >> num_test;
while (num_test--) { main_code(); cout << "\n"; }
}
/* Lak lu theo dieu nhac */
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Incorrect |
0 ms |
2396 KB |
Integer 0 violates the range [1, 1] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
7 ms |
80456 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
1 ms |
8536 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
2 ms |
20828 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
1 ms |
14684 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Correct |
4 ms |
41420 KB |
contestant found the optimal answer: 25082842857 == 25082842857 |
8 |
Correct |
2 ms |
20996 KB |
contestant found the optimal answer: 687136 == 687136 |
9 |
Correct |
2 ms |
14680 KB |
contestant found the optimal answer: 27295930079 == 27295930079 |
10 |
Correct |
2 ms |
24920 KB |
contestant found the optimal answer: 29000419931 == 29000419931 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
9 ms |
98800 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
8 ms |
99948 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Incorrect |
9 ms |
104540 KB |
position 1 occurs twice in split scheme |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Correct |
13 ms |
106556 KB |
contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 |
Correct |
1 ms |
8540 KB |
contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 |
Correct |
14 ms |
110672 KB |
contestant found the optimal answer: 679388326 == 679388326 |
6 |
Correct |
12 ms |
105816 KB |
contestant found the optimal answer: 4699030287 == 4699030287 |
7 |
Correct |
13 ms |
102492 KB |
contestant found the optimal answer: 12418819758185 == 12418819758185 |
8 |
Correct |
12 ms |
104580 KB |
contestant found the optimal answer: 31093317350 == 31093317350 |
9 |
Correct |
7 ms |
66140 KB |
contestant found the optimal answer: 12194625429236 == 12194625429236 |
10 |
Correct |
9 ms |
95324 KB |
contestant found the optimal answer: 12345131038664 == 12345131038664 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Correct |
2 ms |
8796 KB |
contestant found the optimal answer: 1326260195 == 1326260195 |
3 |
Correct |
53 ms |
125916 KB |
contestant found the optimal answer: 4973126687469639 == 4973126687469639 |
4 |
Correct |
2 ms |
8796 KB |
contestant found the optimal answer: 3748491676694116 == 3748491676694116 |
5 |
Correct |
58 ms |
112464 KB |
contestant found the optimal answer: 1085432199 == 1085432199 |
6 |
Correct |
54 ms |
111956 KB |
contestant found the optimal answer: 514790755404 == 514790755404 |
7 |
Correct |
54 ms |
113748 KB |
contestant found the optimal answer: 1256105310476641 == 1256105310476641 |
8 |
Correct |
37 ms |
105460 KB |
contestant found the optimal answer: 3099592898816 == 3099592898816 |
9 |
Correct |
53 ms |
114004 KB |
contestant found the optimal answer: 1241131419367412 == 1241131419367412 |
10 |
Correct |
62 ms |
118864 KB |
contestant found the optimal answer: 1243084101967798 == 1243084101967798 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
9820 KB |
contestant found the optimal answer: 19795776960 == 19795776960 |
2 |
Correct |
16 ms |
10044 KB |
contestant found the optimal answer: 19874432173 == 19874432173 |
3 |
Runtime error |
201 ms |
131072 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |