#include <bits/stdc++.h>
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%Id",&x)
#define SF2(x,y) scanf("%Id%Id",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
using namespace std;
const long long INF = 1e18+1;
const long long MOD = 1e9+7;
const int MX=100015;
ll a[MX];
ll n,m;
ll SUM;
vector<ll> v;
ll val;
ll dp[10005][802];
ll su[10005];
ll DP(ll x,ll k){
if(k==0)R 0;
if(x==n)R -INF;
ll sum=0;
ll &ret=dp[x][k];
if(ret!=-1)R ret;
ret=-INF;
ll z;
for(int i=x;i<n;i++){
z=DP(i+1,k-1);
// cout<<z<<endl;
if(z==-INF)break;
sum+=a[i];
if(val<=sum)
ret=max(ret,z+(sum*su[i+1]));
}
R ret;
}
void fs(ll x,ll k){
if(k==0)R;
ll sum=0;
ll ret=dp[x][k];
ll z;
for(int i=x;i<n;i++){
z=DP(i+1,k-1);
if(z==-INF)break;
sum+=a[i];
if(val>sum)continue;
if(ret==z+(sum*su[i+1])){
cout<<i+1<<" ";
fs(i+1,k-1);
R;
}
}
}
ll solve(){
ll l=0,r=1e16+1;
W(l<r){
// l=5,r=5;
ll mid=(l+r)/2;
ll k=m+1;
for(int i=0;i<n;i++){
ll sum=0;
W(i<n){
sum+=a[i];
if(sum>=mid){
k--;
break;
}
i++;
}
if(k==0){
val=mid;
l=mid+1;
break;
}
}
if(k){
r=mid;
}
}
ll res=DP(0,m);
R res;
}
int main(){
MEM(dp,-1);
cin>>n>>m;
for(ll i=0;i<n;i++){
cin>>a[i];
SUM+=a[i];
}
for(ll i=n-1;i>=0;i--)
su[i]=su[i+1]+a[i];
ll z=SUM;
ll res=solve();
cout<<res<<endl;
fs(0,m);
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:107:8: warning: unused variable 'z' [-Wunused-variable]
ll z=SUM;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
63228 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
48 ms |
63268 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Correct |
48 ms |
63268 KB |
contestant found the optimal answer: 0 == 0 |
4 |
Correct |
48 ms |
63296 KB |
contestant found the optimal answer: 1542524 == 1542524 |
5 |
Correct |
48 ms |
63296 KB |
contestant found the optimal answer: 4500000000 == 4500000000 |
6 |
Correct |
48 ms |
63296 KB |
contestant found the optimal answer: 1 == 1 |
7 |
Correct |
50 ms |
63388 KB |
contestant found the optimal answer: 1 == 1 |
8 |
Correct |
47 ms |
63388 KB |
contestant found the optimal answer: 1 == 1 |
9 |
Correct |
48 ms |
63388 KB |
contestant found the optimal answer: 100400096 == 100400096 |
10 |
Correct |
48 ms |
63388 KB |
contestant found the optimal answer: 900320000 == 900320000 |
11 |
Correct |
51 ms |
63388 KB |
contestant found the optimal answer: 3698080248 == 3698080248 |
12 |
Correct |
47 ms |
63388 KB |
contestant found the optimal answer: 3200320000 == 3200320000 |
13 |
Correct |
48 ms |
63524 KB |
contestant found the optimal answer: 140072 == 140072 |
14 |
Correct |
51 ms |
63524 KB |
contestant found the optimal answer: 376041456 == 376041456 |
15 |
Correct |
52 ms |
63524 KB |
contestant found the optimal answer: 805 == 805 |
16 |
Correct |
47 ms |
63524 KB |
contestant found the optimal answer: 900189994 == 900189994 |
17 |
Correct |
52 ms |
63524 KB |
contestant found the optimal answer: 999919994 == 999919994 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
63524 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
47 ms |
63524 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
51 ms |
63524 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
49 ms |
63524 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
48 ms |
63524 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
47 ms |
63524 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Incorrect |
50 ms |
63524 KB |
contestant didn't find the optimal answer: 25079535562 < 25082842857 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
63524 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
47 ms |
63524 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
49 ms |
63524 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
47 ms |
63524 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
48 ms |
63524 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Correct |
48 ms |
63524 KB |
contestant found the optimal answer: 107630884 == 107630884 |
7 |
Correct |
48 ms |
63524 KB |
contestant found the optimal answer: 475357671774 == 475357671774 |
8 |
Incorrect |
50 ms |
63524 KB |
contestant didn't find the optimal answer: 193549614 < 193556962 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
63524 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
60 ms |
63524 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Correct |
212 ms |
63524 KB |
contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 |
Correct |
55 ms |
63524 KB |
contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 |
Correct |
223 ms |
63524 KB |
contestant found the optimal answer: 679388326 == 679388326 |
6 |
Incorrect |
179 ms |
63524 KB |
contestant didn't find the optimal answer: 4699030286 < 4699030287 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
848 ms |
63524 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Incorrect |
186 ms |
63596 KB |
contestant didn't find the optimal answer: 1301400195 < 1326260195 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
64244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |