#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) (int)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; }
};
int nb,x;
ve hedi;
int dp[100011][211];
int pref[100011];
set<int>ans;
int par[100011][211];
int solve(int index,int k)
{
if(k==0)return 0;
else if(index==nb)return -INF;
if(dp[index+1][k]!=-1)return dp[index+1][k];
int ans=0;
int yup=0,dup=0,in=0;
for (int i = index+1; i < nb; ++i)
{
int now=0;
if(index<0)now=pref[i];
else now = pref[i]-pref[index];
int kow = pref[nb-1]-pref[i];
int dol = kow*now;
int sol = dol+solve(i,k-1);
if(ans<sol)
{
in=i;
}
ans=max(ans,sol);
}
int lol = solve(index+1,k);
ans=max(ans,lol);
//debugs(index+1,k);
//debug(in);
if(ans!=lol)par[index+1][k]=in;
//debugs(index,k);
return dp[index+1][k]=ans;
}
set<int>ans1;
void recur(int node,int x,int y)
{
ans1.insert(node);
if(!y)return;
recur(par[x][y]+1,par[x][y]+1,y-1);
}
int main()
{
//flash;
cin>>nb>>x;
memset(dp,-1,sizeof dp);
int cur=0;
for (int i = 0; i < nb; ++i)
{
int yo;
cin>>yo;
hedi.pb(yo);
cur+=yo;
pref[i]=cur;
}
int ans=solve(-1,x);
cout<<ans<<'\n';
for (int i = nb; i >= 0; --i)
{
if(ans==dp[i][x])
{
ans1.insert(i+1);
recur(par[i][x]+1,par[i][x]+1,x-1);
}
}
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 'int solve(int, int)':
sequence.cpp:36:7: warning: unused variable 'yup' [-Wunused-variable]
int yup=0,dup=0,in=0;
^~~
sequence.cpp:36:13: warning: unused variable 'dup' [-Wunused-variable]
int yup=0,dup=0,in=0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
82936 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Incorrect |
71 ms |
82936 KB |
declared answer doesn't correspond to the split scheme: declared = 999, real = 614 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
82936 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
83064 KB |
declared answer doesn't correspond to the split scheme: declared = 610590000, real = 510621050 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
83780 KB |
declared answer doesn't correspond to the split scheme: declared = 21503404, real = 14766068 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1625 ms |
92396 KB |
declared answer doesn't correspond to the split scheme: declared = 1818678304, real = 1418738064 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2062 ms |
84896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |