Submission #679408

# Submission time Handle Problem Language Result Execution time Memory
679408 2023-01-08T08:37:59 Z bachhoangxuan Feast (NOI19_feast) C++17
100 / 100
136 ms 10408 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define pii pair<int,int>
const int inf=1e18;
const int mod=998244353;
const int maxn=300005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
int n,k,a[maxn],ans;
pii dp[maxn];
pii check(int mid){
    pii Max={0,0};
    dp[0]={0,0};
    for(int i=1;i<=n;i++){
        dp[i]=max(make_pair(Max.first+a[i]-mid,Max.second+1),dp[i-1]);
        Max=max(Max,make_pair(dp[i].first-a[i],dp[i].second));
    }
    //cout << mid << ' ' << dp[n].first << ' ' << dp[n].second << '\n';
    return dp[n];
}
void solve(){
    cin >> n >> k;
    for(int i=1;i<=n;i++){cin >> a[i];a[i]+=a[i-1];}
    int l=0,r=3e14;
    while(r>=l){
        int mid=(r+l)>>1;
        pii p=check(mid);
        if(p.second<=k){ans=p.first+mid*p.second;r=mid-1;}
        else l=mid+1;
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t=1;//cin >> t;
    while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 73 ms 9944 KB Output is correct
2 Correct 88 ms 10128 KB Output is correct
3 Correct 95 ms 10132 KB Output is correct
4 Correct 74 ms 10060 KB Output is correct
5 Correct 74 ms 10116 KB Output is correct
6 Correct 73 ms 9944 KB Output is correct
7 Correct 75 ms 9984 KB Output is correct
8 Correct 93 ms 10060 KB Output is correct
9 Correct 75 ms 9848 KB Output is correct
10 Correct 74 ms 10064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 8280 KB Output is correct
2 Correct 58 ms 8384 KB Output is correct
3 Correct 61 ms 8396 KB Output is correct
4 Correct 63 ms 8368 KB Output is correct
5 Correct 70 ms 9932 KB Output is correct
6 Correct 58 ms 8284 KB Output is correct
7 Correct 62 ms 8492 KB Output is correct
8 Correct 87 ms 10224 KB Output is correct
9 Correct 89 ms 9924 KB Output is correct
10 Correct 60 ms 8436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 10308 KB Output is correct
2 Correct 88 ms 10176 KB Output is correct
3 Correct 102 ms 10284 KB Output is correct
4 Correct 82 ms 10184 KB Output is correct
5 Correct 80 ms 10280 KB Output is correct
6 Correct 83 ms 10264 KB Output is correct
7 Correct 99 ms 10380 KB Output is correct
8 Correct 90 ms 10300 KB Output is correct
9 Correct 86 ms 10280 KB Output is correct
10 Correct 83 ms 10380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 9944 KB Output is correct
2 Correct 88 ms 10128 KB Output is correct
3 Correct 95 ms 10132 KB Output is correct
4 Correct 74 ms 10060 KB Output is correct
5 Correct 74 ms 10116 KB Output is correct
6 Correct 73 ms 9944 KB Output is correct
7 Correct 75 ms 9984 KB Output is correct
8 Correct 93 ms 10060 KB Output is correct
9 Correct 75 ms 9848 KB Output is correct
10 Correct 74 ms 10064 KB Output is correct
11 Correct 55 ms 8280 KB Output is correct
12 Correct 58 ms 8384 KB Output is correct
13 Correct 61 ms 8396 KB Output is correct
14 Correct 63 ms 8368 KB Output is correct
15 Correct 70 ms 9932 KB Output is correct
16 Correct 58 ms 8284 KB Output is correct
17 Correct 62 ms 8492 KB Output is correct
18 Correct 87 ms 10224 KB Output is correct
19 Correct 89 ms 9924 KB Output is correct
20 Correct 60 ms 8436 KB Output is correct
21 Correct 80 ms 10308 KB Output is correct
22 Correct 88 ms 10176 KB Output is correct
23 Correct 102 ms 10284 KB Output is correct
24 Correct 82 ms 10184 KB Output is correct
25 Correct 80 ms 10280 KB Output is correct
26 Correct 83 ms 10264 KB Output is correct
27 Correct 99 ms 10380 KB Output is correct
28 Correct 90 ms 10300 KB Output is correct
29 Correct 86 ms 10280 KB Output is correct
30 Correct 83 ms 10380 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 328 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 328 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 123 ms 10172 KB Output is correct
62 Correct 116 ms 10408 KB Output is correct
63 Correct 94 ms 10136 KB Output is correct
64 Correct 136 ms 10340 KB Output is correct
65 Correct 129 ms 10304 KB Output is correct
66 Correct 126 ms 10260 KB Output is correct
67 Correct 115 ms 10088 KB Output is correct
68 Correct 95 ms 10308 KB Output is correct
69 Correct 79 ms 10064 KB Output is correct
70 Correct 79 ms 10100 KB Output is correct