Submission #949060

# Submission time Handle Problem Language Result Execution time Memory
949060 2024-03-18T21:52:55 Z alexdd Feast (NOI19_feast) C++17
100 / 100
191 ms 12880 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 2e9;
int n,k;
int a[300005];
int dp[300005];
int cnt[300005];
int pref[300005];
int coef;
void solve()
{
    int mxm=0,cate=0;
    for(int i=1;i<=n;i++)
    {
        pref[i] = pref[i-1] + a[i];

        dp[i] = dp[i-1];
        cnt[i] = cnt[i-1];


        if(dp[i]-pref[i]>mxm || (dp[i]-pref[i]==mxm && cnt[i]>cate))
        {
            mxm = dp[i]-pref[i];
            cate = cnt[i];
        }

        int aux = mxm + pref[i] - coef;
        if(aux>dp[i] || (aux==dp[i] && cate+1>cnt[i]))
        {
            dp[i] = aux;
            cnt[i] = cate+1;
        }
    }
}
/**

dp[i] = max(dp[x] - pref[x]) + pref[i] - coef

*/
signed main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int st,dr,ans=n*INF;
    st=0;
    dr=n*INF;
    while(st<=dr)
    {
        coef = (st+dr)/2;
        solve();
        if(cnt[n]<=k)
        {
            ans=coef;
            dr=coef-1;
        }
        else
            st=coef+1;
    }
    coef=ans;
    solve();
    cout<<dp[n] + cnt[n]*coef;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9376 KB Output is correct
2 Correct 123 ms 12448 KB Output is correct
3 Correct 132 ms 12560 KB Output is correct
4 Correct 132 ms 12576 KB Output is correct
5 Correct 140 ms 12440 KB Output is correct
6 Correct 131 ms 12328 KB Output is correct
7 Correct 137 ms 12368 KB Output is correct
8 Correct 128 ms 12368 KB Output is correct
9 Correct 125 ms 12376 KB Output is correct
10 Correct 123 ms 12308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 9516 KB Output is correct
2 Correct 86 ms 10512 KB Output is correct
3 Correct 83 ms 10324 KB Output is correct
4 Correct 83 ms 10464 KB Output is correct
5 Correct 125 ms 12344 KB Output is correct
6 Correct 84 ms 10624 KB Output is correct
7 Correct 86 ms 10832 KB Output is correct
8 Correct 126 ms 12580 KB Output is correct
9 Correct 129 ms 12368 KB Output is correct
10 Correct 86 ms 10688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 9632 KB Output is correct
2 Correct 162 ms 12576 KB Output is correct
3 Correct 142 ms 12712 KB Output is correct
4 Correct 147 ms 12684 KB Output is correct
5 Correct 146 ms 12712 KB Output is correct
6 Correct 146 ms 12564 KB Output is correct
7 Correct 140 ms 12624 KB Output is correct
8 Correct 144 ms 12820 KB Output is correct
9 Correct 147 ms 12880 KB Output is correct
10 Correct 143 ms 12688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2548 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2548 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2516 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 1 ms 2512 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9376 KB Output is correct
2 Correct 123 ms 12448 KB Output is correct
3 Correct 132 ms 12560 KB Output is correct
4 Correct 132 ms 12576 KB Output is correct
5 Correct 140 ms 12440 KB Output is correct
6 Correct 131 ms 12328 KB Output is correct
7 Correct 137 ms 12368 KB Output is correct
8 Correct 128 ms 12368 KB Output is correct
9 Correct 125 ms 12376 KB Output is correct
10 Correct 123 ms 12308 KB Output is correct
11 Correct 78 ms 9516 KB Output is correct
12 Correct 86 ms 10512 KB Output is correct
13 Correct 83 ms 10324 KB Output is correct
14 Correct 83 ms 10464 KB Output is correct
15 Correct 125 ms 12344 KB Output is correct
16 Correct 84 ms 10624 KB Output is correct
17 Correct 86 ms 10832 KB Output is correct
18 Correct 126 ms 12580 KB Output is correct
19 Correct 129 ms 12368 KB Output is correct
20 Correct 86 ms 10688 KB Output is correct
21 Correct 142 ms 9632 KB Output is correct
22 Correct 162 ms 12576 KB Output is correct
23 Correct 142 ms 12712 KB Output is correct
24 Correct 147 ms 12684 KB Output is correct
25 Correct 146 ms 12712 KB Output is correct
26 Correct 146 ms 12564 KB Output is correct
27 Correct 140 ms 12624 KB Output is correct
28 Correct 144 ms 12820 KB Output is correct
29 Correct 147 ms 12880 KB Output is correct
30 Correct 143 ms 12688 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2548 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2548 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2392 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 2 ms 2648 KB Output is correct
54 Correct 2 ms 2396 KB Output is correct
55 Correct 2 ms 2396 KB Output is correct
56 Correct 1 ms 2516 KB Output is correct
57 Correct 2 ms 2396 KB Output is correct
58 Correct 1 ms 2512 KB Output is correct
59 Correct 2 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 171 ms 12616 KB Output is correct
62 Correct 176 ms 12708 KB Output is correct
63 Correct 150 ms 12444 KB Output is correct
64 Correct 173 ms 12692 KB Output is correct
65 Correct 191 ms 12776 KB Output is correct
66 Correct 175 ms 12760 KB Output is correct
67 Correct 172 ms 12372 KB Output is correct
68 Correct 144 ms 12700 KB Output is correct
69 Correct 137 ms 12368 KB Output is correct
70 Correct 140 ms 12688 KB Output is correct