Submission #731481

# Submission time Handle Problem Language Result Execution time Memory
731481 2023-04-27T13:19:14 Z mohav48173 Feast (NOI19_feast) C++14
0 / 100
1000 ms 4872 KB
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long a[400000];
long long m[400000];
long long mincnt=0;
double score=0;
double get(int ind) {
    if(ind<0)return 0;
    else return m[ind];
}
void calc(double lam) {
    double bestscore=0;
    long long bestcnt=0;
    double bestnxt=-lam;
    long long nxtcnt=0;
    for(int i=0;i<n;i++) {
        if(bestscore-lam-get(i-1)>bestnxt ||
           (bestscore-lam-get(i-1)==bestnxt && nxtcnt>bestcnt)) {
            bestnxt=bestscore-get(i-1)-lam;
            nxtcnt=bestcnt;
        }
        if(bestnxt+get(i)>bestscore || (bestnxt+get(i)==bestscore && nxtcnt+1<bestcnt)) {
            bestscore=bestnxt+get(i);
            bestcnt=nxtcnt+1;
        }
    }
    mincnt=bestcnt;
    score=bestscore;
}
int main() {
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    m[0]=a[0];for(int i=1;i<n;i++)m[i]=m[i-1]+a[i];
    double l=0,r=1e16;
    while((r-l)>1e-6) {
        double mid=(l+r)/2;
        calc(mid);
        if(mincnt<=k)r=mid;
        else l=mid;
    }
    calc(r);
    cout<<score+round(k*r)<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 4832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 4872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 4868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 4832 KB Output isn't correct
2 Halted 0 ms 0 KB -