# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535636 |
2022-03-10T18:39:36 Z |
leaked |
Feast (NOI19_feast) |
C++14 |
|
108 ms |
12636 KB |
#include <bits/stdc++.h>
#define f first
#define s second
#define m_p make_pair
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))
#define int long long
#define fast_resp ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
const ll inf=1e18;
signed main(){
fast_resp;
int n,k;
cin>>n>>k;
vec<int>a(n);
for(auto &z : a) cin>>z;
vec<ll>pref(n,0);
for(int i=0;i<n;i++) pref[i]=(i?pref[i-1]:0)+a[i];
auto check=[&](ll x){
vec<pll>dp(n+1,m_p(-inf,-1));
pll mx={0,0};
dp[0]={0,0};
// cout<<"CHECK "<<x<<endl;
for(int i=0;i<n;i++){
dp[i+1]=dp[i];
umax(dp[i+1],m_p(dp[i].f-x,dp[i].s+1));
umax(dp[i+1],m_p(mx.f+pref[i]-x,mx.s+1));
umax(mx,m_p(dp[i+1].f-pref[i],dp[i+1].s));
// cout<<"I "<<dp[i+1].f<<endl;
}
// cout<<"W "<<dp[n].f<<' '<<dp[n].s<<endl;
return dp[n];
};
ll l=0,r=1e9;
while(l!=r){
ll tm=(l+r)/2;
if(check(tm).s<k) r=tm;
else l=tm+1;
}
--l;
// cout<<k<<' '<<l<<endl;
cout<<check(l).f+1ll*k*l;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
12368 KB |
Output is correct |
2 |
Correct |
74 ms |
12360 KB |
Output is correct |
3 |
Correct |
73 ms |
12556 KB |
Output is correct |
4 |
Correct |
69 ms |
12512 KB |
Output is correct |
5 |
Correct |
67 ms |
12436 KB |
Output is correct |
6 |
Correct |
83 ms |
12184 KB |
Output is correct |
7 |
Correct |
69 ms |
12172 KB |
Output is correct |
8 |
Correct |
65 ms |
12460 KB |
Output is correct |
9 |
Correct |
65 ms |
12264 KB |
Output is correct |
10 |
Correct |
72 ms |
12372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
10596 KB |
Output is correct |
2 |
Correct |
57 ms |
10776 KB |
Output is correct |
3 |
Correct |
58 ms |
10588 KB |
Output is correct |
4 |
Correct |
60 ms |
10672 KB |
Output is correct |
5 |
Correct |
82 ms |
12372 KB |
Output is correct |
6 |
Correct |
56 ms |
10572 KB |
Output is correct |
7 |
Correct |
54 ms |
10836 KB |
Output is correct |
8 |
Correct |
78 ms |
12492 KB |
Output is correct |
9 |
Correct |
69 ms |
12192 KB |
Output is correct |
10 |
Correct |
62 ms |
10776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
12636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
12368 KB |
Output is correct |
2 |
Correct |
74 ms |
12360 KB |
Output is correct |
3 |
Correct |
73 ms |
12556 KB |
Output is correct |
4 |
Correct |
69 ms |
12512 KB |
Output is correct |
5 |
Correct |
67 ms |
12436 KB |
Output is correct |
6 |
Correct |
83 ms |
12184 KB |
Output is correct |
7 |
Correct |
69 ms |
12172 KB |
Output is correct |
8 |
Correct |
65 ms |
12460 KB |
Output is correct |
9 |
Correct |
65 ms |
12264 KB |
Output is correct |
10 |
Correct |
72 ms |
12372 KB |
Output is correct |
11 |
Correct |
55 ms |
10596 KB |
Output is correct |
12 |
Correct |
57 ms |
10776 KB |
Output is correct |
13 |
Correct |
58 ms |
10588 KB |
Output is correct |
14 |
Correct |
60 ms |
10672 KB |
Output is correct |
15 |
Correct |
82 ms |
12372 KB |
Output is correct |
16 |
Correct |
56 ms |
10572 KB |
Output is correct |
17 |
Correct |
54 ms |
10836 KB |
Output is correct |
18 |
Correct |
78 ms |
12492 KB |
Output is correct |
19 |
Correct |
69 ms |
12192 KB |
Output is correct |
20 |
Correct |
62 ms |
10776 KB |
Output is correct |
21 |
Incorrect |
108 ms |
12636 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |