Submission #595941

# Submission time Handle Problem Language Result Execution time Memory
595941 2022-07-14T08:16:13 Z Tenis0206 Feast (NOI19_feast) C++11
0 / 100
16 ms 3144 KB
#include <bits/stdc++.h>

using namespace std;

const int oo = 0x3f3f3f3f;

int n,k;
int v[100005];
int sp[100005];

pair<int,int> dp[100005];

pair<int,int> get_val(int c)
{
    int Max = 0, nrval = 0;
    int Max_pref = 0, nrval_pref = 0;
    for(int i=1;i<=n;i++)
    {
        dp[i].first = Max_pref + sp[i] - c;
        dp[i].second = nrval_pref + 1;
        if(dp[i].first > Max || (dp[i].first==Max && dp[i].second < nrval))
        {
            Max = dp[i].first;
            nrval = dp[i].second;
        }
        if(Max - sp[i] > Max_pref || (Max - sp[i]==Max_pref && nrval < nrval_pref))
        {
            Max_pref = Max - sp[i];
            nrval_pref = nrval;
        }
    }
    return {Max,nrval};
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        sp[i] = sp[i-1] + v[i];
    }
    int st = -oo;
    int dr = oo;
    while(st<=dr)
    {
        int mij = (st + dr) >> 1;
        pair<int,int> val = get_val(mij);
        if(val.second==k)
        {
            cout<<val.first + k * mij<<'\n';
            return 0;
        }
        if(val.second<k)
        {
            dr = mij - 1;
        }
        else
        {
            st = mij + 1;
        }
    }
    pair<int,int> val = get_val(st);
    cout<<val.first + val.second * st<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 3144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 3144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -