Submission #991315

# Submission time Handle Problem Language Result Execution time Memory
991315 2024-06-02T01:04:30 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
109 ms 12164 KB
#include<bits/stdc++.h>
#include<ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define Fast ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define int long long
template<class T> using ordered_set = tree<T, null_type , less<T> ,rb_tree_tag , tree_order_statistics_node_update> ;
typedef long long ll;
const int N=3e5+3,LG=__lg(N)+2,M=21,MOD=998244353,inf=1e16;
pair<int,int> dp[2][N];
int v[N],n;
pair<int,int> sol(int mid) {
    dp[0][0] = {0, 0};
    dp[1][0] = {v[0] - mid, 1};

    for (int i = 1; i < n; i++) {
        dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]);

        dp[1][i] =
                max(make_pair(dp[0][i - 1].first + v[i] - mid,
                              dp[0][i - 1].second + 1),
                    make_pair(dp[1][i - 1].first + v[i], dp[1][i - 1].second));
    }

    return max(dp[0][n - 1], dp[1][n - 1]);
}
void solve() {
    int k;
    cin>>n>>k;
    for (int i = 0; i <n ; ++i)
        cin>>v[i];
    int l=0,r=inf;
    while(r-l>1){
        int mid=l+(r-l)/2;
        if(sol(mid).second<k)
            r=mid;
        else l=mid;
    }
    cout<<sol(l).first+l*k<<'\n';
}
signed main() {
    Fast;
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11904 KB Output is correct
2 Correct 49 ms 12120 KB Output is correct
3 Correct 49 ms 12112 KB Output is correct
4 Correct 49 ms 12120 KB Output is correct
5 Correct 50 ms 12120 KB Output is correct
6 Correct 60 ms 11864 KB Output is correct
7 Correct 48 ms 11860 KB Output is correct
8 Correct 49 ms 12116 KB Output is correct
9 Correct 48 ms 11868 KB Output is correct
10 Correct 53 ms 12088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 11908 KB Output is correct
2 Correct 43 ms 12124 KB Output is correct
3 Correct 41 ms 11868 KB Output is correct
4 Correct 42 ms 11864 KB Output is correct
5 Correct 49 ms 11860 KB Output is correct
6 Correct 54 ms 11868 KB Output is correct
7 Correct 47 ms 12120 KB Output is correct
8 Correct 49 ms 11920 KB Output is correct
9 Correct 49 ms 11864 KB Output is correct
10 Correct 43 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 12116 KB Output is correct
2 Correct 75 ms 11868 KB Output is correct
3 Correct 70 ms 12112 KB Output is correct
4 Correct 70 ms 11856 KB Output is correct
5 Correct 82 ms 11904 KB Output is correct
6 Correct 71 ms 12124 KB Output is correct
7 Correct 79 ms 12124 KB Output is correct
8 Correct 70 ms 12112 KB Output is correct
9 Correct 74 ms 12164 KB Output is correct
10 Correct 72 ms 12112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4584 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 1 ms 4524 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11904 KB Output is correct
2 Correct 49 ms 12120 KB Output is correct
3 Correct 49 ms 12112 KB Output is correct
4 Correct 49 ms 12120 KB Output is correct
5 Correct 50 ms 12120 KB Output is correct
6 Correct 60 ms 11864 KB Output is correct
7 Correct 48 ms 11860 KB Output is correct
8 Correct 49 ms 12116 KB Output is correct
9 Correct 48 ms 11868 KB Output is correct
10 Correct 53 ms 12088 KB Output is correct
11 Correct 43 ms 11908 KB Output is correct
12 Correct 43 ms 12124 KB Output is correct
13 Correct 41 ms 11868 KB Output is correct
14 Correct 42 ms 11864 KB Output is correct
15 Correct 49 ms 11860 KB Output is correct
16 Correct 54 ms 11868 KB Output is correct
17 Correct 47 ms 12120 KB Output is correct
18 Correct 49 ms 11920 KB Output is correct
19 Correct 49 ms 11864 KB Output is correct
20 Correct 43 ms 12124 KB Output is correct
21 Correct 71 ms 12116 KB Output is correct
22 Correct 75 ms 11868 KB Output is correct
23 Correct 70 ms 12112 KB Output is correct
24 Correct 70 ms 11856 KB Output is correct
25 Correct 82 ms 11904 KB Output is correct
26 Correct 71 ms 12124 KB Output is correct
27 Correct 79 ms 12124 KB Output is correct
28 Correct 70 ms 12112 KB Output is correct
29 Correct 74 ms 12164 KB Output is correct
30 Correct 72 ms 12112 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 0 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 0 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4584 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
55 Correct 1 ms 4524 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4440 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 100 ms 11868 KB Output is correct
62 Correct 98 ms 12120 KB Output is correct
63 Correct 87 ms 12048 KB Output is correct
64 Correct 97 ms 11912 KB Output is correct
65 Correct 105 ms 11908 KB Output is correct
66 Correct 109 ms 11916 KB Output is correct
67 Correct 103 ms 12052 KB Output is correct
68 Correct 73 ms 12112 KB Output is correct
69 Correct 70 ms 11868 KB Output is correct
70 Correct 69 ms 12024 KB Output is correct