This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
//#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k;
cin >> n >> k;
vi a(n + 1);
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] += a[i - 1];
}
vvi dp(n + 1, vi(k + 1));
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= k; j++){
for(int z = 1; z <= i; z++){
dp[i][j] = max(dp[i][j], dp[z - 1][j - 1] + (a[i] - a[z - 1]) * (a[n] - a[i]));
}
}
ans = max(ans, dp[i][k]);
}
cout << ans << "\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |