Submission #1017489

# Submission time Handle Problem Language Result Execution time Memory
1017489 2024-07-09T08:22:25 Z hehebjp123 Feast (NOI19_feast) C++14
100 / 100
105 ms 7484 KB
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll N=3e5+9;
const ll mod=1e9+7;
    ll t,n,k,i,m,x,a[N],tot[N],q,l,b[N],c[N],mu[N],sl=0,xor_basis[64],len=0,r;
ll dp[N][2];
ii check(ll pen)
{
    dp[0][1]=-pen;
    dp[0][0]=0;
    ll res=0;
    ll cnt=0;
    for(i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        dp[i][1]=max(dp[i-1][0]-pen,dp[i-1][1])+a[i];
        res=max(res,dp[i][1]);
    }
    bool op=0;
    ll tot=res;
    if(res==0) return {0,0};
    for(i=n;i>0;i--)
    if(res==dp[i][1])
    {
        res-=a[i];
        if(!op){ cnt++;}
        //if(res==0) break;
        op=1;
    }
    else{if(op)res+=pen; op=0;}
        return {tot+pen*cnt,cnt};
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
cin>>n>>k;
for(i=1;i<=n;i++)
    cin>>a[i];
ll l=0,r=1e18,kq=0;
while(l<=r)
{
    ll mid=(l+r)/2;
    ii ans=check(mid);
  //  cout<<mid<<" "<<ans.se<<'\n';
    if(ans.se<=k){
            if(ans.se>0)
        kq=max(kq,ans.fi);
        r=mid-1;
    }
    else l=mid+1;
}
cout<<kq;
}
/*
6 2
1 2 3 -10 5 6

*/
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7264 KB Output is correct
2 Correct 81 ms 7252 KB Output is correct
3 Correct 69 ms 7444 KB Output is correct
4 Correct 71 ms 7268 KB Output is correct
5 Correct 70 ms 7392 KB Output is correct
6 Correct 67 ms 7256 KB Output is correct
7 Correct 67 ms 7260 KB Output is correct
8 Correct 69 ms 7412 KB Output is correct
9 Correct 71 ms 7288 KB Output is correct
10 Correct 70 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7260 KB Output is correct
2 Correct 61 ms 7472 KB Output is correct
3 Correct 60 ms 7260 KB Output is correct
4 Correct 60 ms 7260 KB Output is correct
5 Correct 70 ms 7260 KB Output is correct
6 Correct 65 ms 7232 KB Output is correct
7 Correct 68 ms 7480 KB Output is correct
8 Correct 87 ms 7300 KB Output is correct
9 Correct 74 ms 7260 KB Output is correct
10 Correct 69 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 7260 KB Output is correct
2 Correct 90 ms 7320 KB Output is correct
3 Correct 72 ms 7248 KB Output is correct
4 Correct 70 ms 7124 KB Output is correct
5 Correct 71 ms 7248 KB Output is correct
6 Correct 101 ms 7248 KB Output is correct
7 Correct 72 ms 7456 KB Output is correct
8 Correct 82 ms 7384 KB Output is correct
9 Correct 78 ms 7248 KB Output is correct
10 Correct 73 ms 7452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7264 KB Output is correct
2 Correct 81 ms 7252 KB Output is correct
3 Correct 69 ms 7444 KB Output is correct
4 Correct 71 ms 7268 KB Output is correct
5 Correct 70 ms 7392 KB Output is correct
6 Correct 67 ms 7256 KB Output is correct
7 Correct 67 ms 7260 KB Output is correct
8 Correct 69 ms 7412 KB Output is correct
9 Correct 71 ms 7288 KB Output is correct
10 Correct 70 ms 7244 KB Output is correct
11 Correct 62 ms 7260 KB Output is correct
12 Correct 61 ms 7472 KB Output is correct
13 Correct 60 ms 7260 KB Output is correct
14 Correct 60 ms 7260 KB Output is correct
15 Correct 70 ms 7260 KB Output is correct
16 Correct 65 ms 7232 KB Output is correct
17 Correct 68 ms 7480 KB Output is correct
18 Correct 87 ms 7300 KB Output is correct
19 Correct 74 ms 7260 KB Output is correct
20 Correct 69 ms 7260 KB Output is correct
21 Correct 73 ms 7260 KB Output is correct
22 Correct 90 ms 7320 KB Output is correct
23 Correct 72 ms 7248 KB Output is correct
24 Correct 70 ms 7124 KB Output is correct
25 Correct 71 ms 7248 KB Output is correct
26 Correct 101 ms 7248 KB Output is correct
27 Correct 72 ms 7456 KB Output is correct
28 Correct 82 ms 7384 KB Output is correct
29 Correct 78 ms 7248 KB Output is correct
30 Correct 73 ms 7452 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 99 ms 7248 KB Output is correct
62 Correct 105 ms 7484 KB Output is correct
63 Correct 76 ms 7292 KB Output is correct
64 Correct 98 ms 7420 KB Output is correct
65 Correct 89 ms 7424 KB Output is correct
66 Correct 89 ms 7404 KB Output is correct
67 Correct 90 ms 7168 KB Output is correct
68 Correct 77 ms 7312 KB Output is correct
69 Correct 76 ms 7260 KB Output is correct
70 Correct 76 ms 7264 KB Output is correct