Submission #731505

# Submission time Handle Problem Language Result Execution time Memory
731505 2023-04-27T13:37:28 Z mohav48173 Feast (NOI19_feast) C++14
63 / 100
1000 ms 7868 KB
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long a[400000];
long long m[400000];
long long mincnt=0;
long double score=0;
long double get(int ind) {
    if(ind<0)return 0;
    else return m[ind];
}
void calc(long double lam) {
    long double bestscore=0;
    long long bestcnt=0;
    long 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];
    long double l=0,r=1e18;
    while((r-l)>(long double)(1e-7)) {
        long double mid=(l+r)/2.0;
        calc(mid);
        if(mincnt<k)r=mid;
        else l=mid;
    }
    calc(r);
    cout<<(long long)(round(score+k*r))<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 168 ms 4840 KB Output is correct
2 Correct 169 ms 4908 KB Output is correct
3 Correct 194 ms 7868 KB Output is correct
4 Correct 171 ms 7804 KB Output is correct
5 Correct 170 ms 7672 KB Output is correct
6 Correct 188 ms 7548 KB Output is correct
7 Correct 163 ms 7596 KB Output is correct
8 Correct 173 ms 7744 KB Output is correct
9 Correct 211 ms 7752 KB Output is correct
10 Correct 164 ms 7640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 4844 KB Output is correct
2 Correct 116 ms 4980 KB Output is correct
3 Correct 128 ms 4756 KB Output is correct
4 Correct 116 ms 4940 KB Output is correct
5 Execution timed out 1089 ms 4788 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 265 ms 4928 KB Output is correct
2 Correct 239 ms 4876 KB Output is correct
3 Correct 242 ms 4976 KB Output is correct
4 Correct 236 ms 4968 KB Output is correct
5 Correct 286 ms 4912 KB Output is correct
6 Correct 234 ms 5048 KB Output is correct
7 Correct 251 ms 4928 KB Output is correct
8 Correct 243 ms 4940 KB Output is correct
9 Correct 236 ms 5072 KB Output is correct
10 Correct 232 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 352 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 4840 KB Output is correct
2 Correct 169 ms 4908 KB Output is correct
3 Correct 194 ms 7868 KB Output is correct
4 Correct 171 ms 7804 KB Output is correct
5 Correct 170 ms 7672 KB Output is correct
6 Correct 188 ms 7548 KB Output is correct
7 Correct 163 ms 7596 KB Output is correct
8 Correct 173 ms 7744 KB Output is correct
9 Correct 211 ms 7752 KB Output is correct
10 Correct 164 ms 7640 KB Output is correct
11 Correct 119 ms 4844 KB Output is correct
12 Correct 116 ms 4980 KB Output is correct
13 Correct 128 ms 4756 KB Output is correct
14 Correct 116 ms 4940 KB Output is correct
15 Execution timed out 1089 ms 4788 KB Time limit exceeded
16 Halted 0 ms 0 KB -