# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135016 | CaroLinda | Split the sequence (APIO14_sequence) | C++14 | 3 ms | 508 KiB |
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 lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
const int inf = 0x3f3f3f3f ;
const int MAXN = 12 ;
using namespace std ;
int n , k ;
vector<pii> intervals ;
ll pref[MAXN] , ans = 0 ;
ll get(int i , int j) { return pref[j] - pref[i-1] ; }
int main()
{
scanf("%d%d", &n , &k ) ;
lp(i,1,n+1) scanf("%lld", &pref[i] ) ;
lp(i,1,n+1) pref[i] += pref[i-1] ;
intervals.pb( mk(1,n) ) ;
lp(i,0,k)
{
pair<ll,int> ansK = mk(-1,-1) ;
for( pii myInt : intervals )
lp(j,myInt.ff , myInt.ss)
ansK = max(ansK , mk(get(myInt.ff,j)*get(j+1, myInt.ss), j) ) ;
lp(j,0,intervals.size())
if( intervals[j].ff <= ansK.ff && intervals[j].ss >= ansK.ss )
{
int beg=intervals[j].ff, en=intervals[j].ss ;
intervals[j] = mk(beg,ansK.ss) ;
intervals.pb(mk(ansK.ss+1,en)) ;
break ;
}
ans += ansK.ff ;
}
printf("%lld\n" , ans ) ;
}
Compilation message (stderr)
# | 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... |