Submission #1085265

# Submission time Handle Problem Language Result Execution time Memory
1085265 2024-09-07T19:16:14 Z quan606303 Feast (NOI19_feast) C++14
100 / 100
108 ms 12884 KB
///0-0 : what is your motivation, quan606303?
///quan606303 : Hutao
/*idea : 



*/
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define file(a) freopen(a".inp","r",stdin); freopen(a".out","w",stdout);
using namespace std;
const int MOD=1e9+7;
const int maxn=3e5+7;;
int n,k,a[maxn],pre[maxn];
pair<int,int> dp[maxn];
pair<int,int> sub1(int pen)
{
    pair<int,int> cnt={0,0};
    for (int i=1;i<=n;i++)
    {   
        dp[i]=max(dp[i-1],make_pair(cnt.fi+pre[i]-pen,cnt.se+1));
        cnt=max(cnt,make_pair(dp[i].fi-pre[i],dp[i].se));
    }
    return dp[n];
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   // file("MUABANCO");
    cin>>n>>k;
    for (int i=1;i<=n;i++)cin>>a[i];
    for (int i=1;i<=n;i++)pre[i]=pre[i-1]+a[i];
    int l=0,r=1e18,ans=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        pair<int,int> cnt=sub1(mid);
        if (cnt.se<=k)
        {
            r=mid-1;
            ans=cnt.fi+cnt.se*mid;
        }
        else l=mid+1;
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 12112 KB Output is correct
2 Correct 47 ms 12372 KB Output is correct
3 Correct 47 ms 12636 KB Output is correct
4 Correct 47 ms 12440 KB Output is correct
5 Correct 56 ms 12580 KB Output is correct
6 Correct 46 ms 12124 KB Output is correct
7 Correct 46 ms 12124 KB Output is correct
8 Correct 46 ms 12368 KB Output is correct
9 Correct 49 ms 12372 KB Output is correct
10 Correct 46 ms 12376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 10688 KB Output is correct
2 Correct 44 ms 10844 KB Output is correct
3 Correct 42 ms 10588 KB Output is correct
4 Correct 42 ms 10588 KB Output is correct
5 Correct 46 ms 12304 KB Output is correct
6 Correct 42 ms 10588 KB Output is correct
7 Correct 42 ms 10844 KB Output is correct
8 Correct 46 ms 12636 KB Output is correct
9 Correct 46 ms 12124 KB Output is correct
10 Correct 48 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 12624 KB Output is correct
2 Correct 73 ms 12628 KB Output is correct
3 Correct 72 ms 12636 KB Output is correct
4 Correct 80 ms 12368 KB Output is correct
5 Correct 71 ms 12624 KB Output is correct
6 Correct 74 ms 12620 KB Output is correct
7 Correct 74 ms 12836 KB Output is correct
8 Correct 77 ms 12628 KB Output is correct
9 Correct 74 ms 12628 KB Output is correct
10 Correct 74 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 0 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 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 0 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 0 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 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 472 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 53 ms 12112 KB Output is correct
2 Correct 47 ms 12372 KB Output is correct
3 Correct 47 ms 12636 KB Output is correct
4 Correct 47 ms 12440 KB Output is correct
5 Correct 56 ms 12580 KB Output is correct
6 Correct 46 ms 12124 KB Output is correct
7 Correct 46 ms 12124 KB Output is correct
8 Correct 46 ms 12368 KB Output is correct
9 Correct 49 ms 12372 KB Output is correct
10 Correct 46 ms 12376 KB Output is correct
11 Correct 44 ms 10688 KB Output is correct
12 Correct 44 ms 10844 KB Output is correct
13 Correct 42 ms 10588 KB Output is correct
14 Correct 42 ms 10588 KB Output is correct
15 Correct 46 ms 12304 KB Output is correct
16 Correct 42 ms 10588 KB Output is correct
17 Correct 42 ms 10844 KB Output is correct
18 Correct 46 ms 12636 KB Output is correct
19 Correct 46 ms 12124 KB Output is correct
20 Correct 48 ms 10840 KB Output is correct
21 Correct 73 ms 12624 KB Output is correct
22 Correct 73 ms 12628 KB Output is correct
23 Correct 72 ms 12636 KB Output is correct
24 Correct 80 ms 12368 KB Output is correct
25 Correct 71 ms 12624 KB Output is correct
26 Correct 74 ms 12620 KB Output is correct
27 Correct 74 ms 12836 KB Output is correct
28 Correct 77 ms 12628 KB Output is correct
29 Correct 74 ms 12628 KB Output is correct
30 Correct 74 ms 12628 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 600 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 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 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 0 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 0 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 344 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 472 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 98 ms 12376 KB Output is correct
62 Correct 100 ms 12884 KB Output is correct
63 Correct 94 ms 12540 KB Output is correct
64 Correct 103 ms 12632 KB Output is correct
65 Correct 102 ms 12604 KB Output is correct
66 Correct 108 ms 12756 KB Output is correct
67 Correct 105 ms 12368 KB Output is correct
68 Correct 76 ms 12628 KB Output is correct
69 Correct 75 ms 12576 KB Output is correct
70 Correct 70 ms 12376 KB Output is correct