Submission #935822

# Submission time Handle Problem Language Result Execution time Memory
935822 2024-02-29T15:18:43 Z imarn Feast (NOI19_feast) C++14
0 / 100
36 ms 24152 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});
    }
}
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;
}

Compilation message

feast.cpp: In function 'std::pair<long long int, long long int> solve(long long int, int)':
feast.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
   23 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 24060 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 24152 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 24148 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 21596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 21596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 21596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 24060 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -