# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
935819 |
2024-02-29T15:07:47 Z |
imarn |
Feast (NOI19_feast) |
C++14 |
|
103 ms |
12356 KB |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
const int N=3e5+5;
ll a[N]{0};
pll dp[N];
pll mx[N];
pll solve(ll x,int n){
dp[0]=mx[0]={0,0};
for(int i=1;i<=n;i++){
dp[i] = max(dp[i-1],{mx[i-1].f+a[i]-x,mx[i-1].s+1});
mx[i] = max(mx[i-1],{dp[i].f-a[i],-dp[i].s});
}
return dp[n];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,k;cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i],a[i]+=a[i-1];
ll l=0,r=1e12;
while(l<r){
ll m=(l+r)>>1;
if(solve(m,n).s<=k)r=m;
else l=m+1;
}
cout<<solve(l,n).f+l*k;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12104 KB |
Output is correct |
2 |
Correct |
56 ms |
12164 KB |
Output is correct |
3 |
Correct |
57 ms |
12172 KB |
Output is correct |
4 |
Correct |
56 ms |
11940 KB |
Output is correct |
5 |
Correct |
56 ms |
12124 KB |
Output is correct |
6 |
Correct |
54 ms |
12356 KB |
Output is correct |
7 |
Correct |
58 ms |
12120 KB |
Output is correct |
8 |
Correct |
55 ms |
12156 KB |
Output is correct |
9 |
Correct |
54 ms |
12116 KB |
Output is correct |
10 |
Correct |
55 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
12120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12104 KB |
Output is correct |
2 |
Correct |
56 ms |
12164 KB |
Output is correct |
3 |
Correct |
57 ms |
12172 KB |
Output is correct |
4 |
Correct |
56 ms |
11940 KB |
Output is correct |
5 |
Correct |
56 ms |
12124 KB |
Output is correct |
6 |
Correct |
54 ms |
12356 KB |
Output is correct |
7 |
Correct |
58 ms |
12120 KB |
Output is correct |
8 |
Correct |
55 ms |
12156 KB |
Output is correct |
9 |
Correct |
54 ms |
12116 KB |
Output is correct |
10 |
Correct |
55 ms |
12120 KB |
Output is correct |
11 |
Incorrect |
48 ms |
12120 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |