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;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
const int maxk = 2e2 + 20;
int l[maxn] , r[maxn] , sum[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n , k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> sum[i] , sum[i] += sum[i - 1];
l[i] = 1 , r[i] = n;
}
ll res = 0;
for(int i = 0; i < k; i++)
{
ll mx = 0;
for(int j = 1; j <= n; j++)
if(r[j] > j)
mx = max(mx , 1LL * (sum[r[j]] - sum[j]) * (sum[j] - sum[l[j] - 1]));
for(int j = 1; j <= n; j++)
if(r[j] > j && 1LL * (sum[r[j]] - sum[j]) * (sum[j] - sum[l[j] - 1]) == mx)
{
for(int x = j + 1; x <= r[j]; x++)
l[x] = j + 1;
for(int x = l[j]; x <= j; x++)
r[x] = j;
break;
}
res += mx;
}
cout << res << endl;
for(int i = 1; r[i] < n; i = r[i] + 1)
cout << r[i] << " ";
cout << endl;
}
# | 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... |