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>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N=1e3+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;
ll arr[N], n, k, dp[N][205], pref[N], nex[N][205];
int main()
{
inlld2(n, k);
for(ll a=1; a<=n; a++)
{
inlld(arr[a]);
pref[a]=pref[a-1]+arr[a];
}
for(ll a=1; a<=n; a++)
for(ll b=1; b<=k; b++)
dp[a][b]=-1e18;
for(ll b=1; b<=k; b++)
for(ll a=1; a<=n; a++)
for(ll c=1; c<a; c++)
{
// dp[a][b]=max(dp[a][b], dp[c][b-1]+(pref[a]-pref[c])*pref[c]);
if(dp[c][b-1]+(pref[a]-pref[c])*pref[c]>dp[a][b])
{
dp[a][b]=dp[c][b-1]+(pref[a]-pref[c])*pref[c];
nex[a][b]=c;
}
}
printf("%lld\n", dp[n][k]);
ll i=n, j=k;
vector<ll>ans;
while(j--)
{
// printf("%lld\n", nex[i][j]+1);
ans.pb(nex[i][j]+1);
i=nex[i][j];
}
// for(ll a=ans.size()-1; a>=0; a--)
// printf("%lld ", ans[a]);
// printf("\n");
return 0;
}
Compilation message (stderr)
sequence.cpp: In function 'int main()':
sequence.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
~~~~~^~~~~~~~~~~~~~~~~~~~
sequence.cpp:24:5: note: in expansion of macro 'inlld2'
inlld2(n, k);
^~~~~~
sequence.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld(a) scanf("%lld", &a)
~~~~~^~~~~~~~~~~~
sequence.cpp:27:9: note: in expansion of macro 'inlld'
inlld(arr[a]);
^~~~~
# | 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... |