#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
ll nb,x;
ve hedi;
ll dp[100011][211];
ll pref[100011];
set<ll>ans;
ll par[100011][211];
ll solve(ll index,ll k)
{
if(k==0)return 0;
else if(index==nb)return -INF;
if(dp[index+1][k]!=-1)return dp[index+1][k];
ll ans=0;
ll yup=0,dup=0,in=0;
for (ll i = index+1; i < nb; ++i)
{
ll now=0;
if(index<0)now=pref[i];
else now = pref[i]-pref[index];
ll kow = pref[nb-1]-pref[i];
ll dol = kow*now;
ll sol = dol+solve(i,k-1);
if(ans<sol)
{
in=i;
}
ans=max(ans,sol);
}
ll lol = solve(index+1,k);
ans=max(ans,lol);
par[index+1][k]=in;
return dp[index+1][k]=ans;
}
set<ll>ans1;
void recur(ll node,ll x,ll y)
{
ans1.insert(node);
if(!y)return;
recur(par[x][y]+1,par[x][y]+1,y-1);
}
int main()
{
flash;
cin>>nb>>x;
for (int i = 0; i <= nb+1; ++i)
{
for (int j = 0; j <= x+1; ++j)
{
dp[i][j]=-1;
}
}
ll cur=0;
for (ll i = 0; i < nb; ++i)
{
ll yo;
cin>>yo;
hedi.pb(yo);
cur+=yo;
pref[i]=cur;
}
ll ans=solve(-1,x);
cout<<ans<<'\n';
for (ll i = nb; i >= 0; --i)
{
if(ans==dp[i][x])
{
//debug(par[i][x]);
//ans1.insert(i+1);
recur(par[i][x]+1,par[i][x]+1,x-1);
break;
}
}
for(auto it:ans1)cout<<it<<" ";
return 0;
}
//code the AC sol !
// BS/queue/map
Compilation message
sequence.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
sequence.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
sequence.cpp: In function 'long long int solve(long long int, long long int)':
sequence.cpp:36:6: warning: unused variable 'yup' [-Wunused-variable]
ll yup=0,dup=0,in=0;
^~~
sequence.cpp:36:12: warning: unused variable 'dup' [-Wunused-variable]
ll yup=0,dup=0,in=0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 0 == 0 |
4 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 1542524 == 1542524 |
5 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 4500000000 == 4500000000 |
6 |
Correct |
2 ms |
380 KB |
contestant found the optimal answer: 1 == 1 |
7 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 1 == 1 |
8 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 1 == 1 |
9 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 100400096 == 100400096 |
10 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 900320000 == 900320000 |
11 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 3698080248 == 3698080248 |
12 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 3200320000 == 3200320000 |
13 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 140072 == 140072 |
14 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 376041456 == 376041456 |
15 |
Correct |
2 ms |
380 KB |
contestant found the optimal answer: 805 == 805 |
16 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 900189994 == 900189994 |
17 |
Correct |
2 ms |
376 KB |
contestant found the optimal answer: 999919994 == 999919994 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
2 ms |
476 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
2 ms |
520 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 25082842857 == 25082842857 |
8 |
Correct |
2 ms |
552 KB |
contestant found the optimal answer: 687136 == 687136 |
9 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 27295930079 == 27295930079 |
10 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 29000419931 == 29000419931 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
3 ms |
1016 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
10 ms |
1016 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
3 ms |
1016 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
10 ms |
1016 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Correct |
10 ms |
1016 KB |
contestant found the optimal answer: 107630884 == 107630884 |
7 |
Correct |
10 ms |
1016 KB |
contestant found the optimal answer: 475357671774 == 475357671774 |
8 |
Correct |
6 ms |
1016 KB |
contestant found the optimal answer: 193556962 == 193556962 |
9 |
Correct |
6 ms |
1016 KB |
contestant found the optimal answer: 482389919803 == 482389919803 |
10 |
Correct |
7 ms |
1016 KB |
contestant found the optimal answer: 490686959791 == 490686959791 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3840 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
13 ms |
3804 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Correct |
452 ms |
3968 KB |
contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 |
Correct |
12 ms |
3704 KB |
contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 |
Correct |
456 ms |
3932 KB |
contestant found the optimal answer: 679388326 == 679388326 |
6 |
Correct |
402 ms |
3968 KB |
contestant found the optimal answer: 4699030287 == 4699030287 |
7 |
Correct |
454 ms |
3872 KB |
contestant found the optimal answer: 12418819758185 == 12418819758185 |
8 |
Correct |
455 ms |
3832 KB |
contestant found the optimal answer: 31093317350 == 31093317350 |
9 |
Correct |
112 ms |
3704 KB |
contestant found the optimal answer: 12194625429236 == 12194625429236 |
10 |
Correct |
210 ms |
3832 KB |
contestant found the optimal answer: 12345131038664 == 12345131038664 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1598 ms |
34608 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Correct |
1319 ms |
34536 KB |
contestant found the optimal answer: 1326260195 == 1326260195 |
3 |
Execution timed out |
2048 ms |
34204 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
104 ms |
131072 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |