Submission #989214

# Submission time Handle Problem Language Result Execution time Memory
989214 2024-05-27T18:37:15 Z ASN49K Feast (NOI19_feast) C++14
0 / 100
53 ms 5716 KB
#include <bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define int long long
const int inf=1e9;
using i64=long long;
int n;
vector<int>a;
pair<i64 , int> test(const int lambda)
{
    pair<i64,int>sol={0,0};
    pair<i64,int> last={-1e18,0};
    for(int i=0;i<n;i++)
    {
        if(sol.first-lambda > last.first || (sol.first-lambda == last.first && sol.second<last.second))
        {
            last={sol.first+a[i]-lambda, sol.second+1};
        }
        else
        {
            last.first+=a[i];
        }
 
        if(sol.first<last.first || (sol.first==last.first && sol.second>last.second))
        {
            sol=last;
        }
    }
    return sol;
}
main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>n>>k;
    a.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int st=0,dr=1e12;
    i64 rez=-1e18;
    while(st<=dr)
    {
        int m=(st+dr)/2;
        auto xd=test(m);
        if(xd.second <= k)
        {
            dr=m-1;
            rez=max(rez , xd.first+1LL*k*m);
        }
        else
        {
            st=m+1;
        }
    }
    cout<<rez;
    return 0;
}

Compilation message

feast.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 5716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -