Submission #930166

# Submission time Handle Problem Language Result Execution time Memory
930166 2024-02-18T19:22:45 Z ASN49K Feast (NOI19_feast) C++14
0 / 100
138 ms 1372 KB
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
const int inf=1e9;
using i64=long long;
int n;
vector<int>a;

pair<double , int> test(const double lambda)
{
    pair<double,int>sol={0,0};
    pair<double,int> last={-2*inf,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;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>n>>k;
    a.resize(n);
    int sum=0,cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>0)sum+=a[i],cnt++;
    }
    if(cnt <= k)
    {
        cout<<sum;
        return 0;
    }
    double st=0,dr=inf;
    double rez=-inf;
    while(dr-st>0.00001)
    {
        double m=(st+dr)/2;
        auto xd=test(m);
        if(xd.second < k)
        {
            dr=m;
        }
        else
        {
            st=m;
            rez=xd.first+1LL*k*m;
        }
    }
    cout<<rez;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 1372 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 41 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -