Submission #1017334

# Submission time Handle Problem Language Result Execution time Memory
1017334 2024-07-09T07:26:06 Z khanhtb Feast (NOI19_feast) C++14
100 / 100
113 ms 12180 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vll vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 2e18;
const ll base = 31;
const ll blockdeg = 320;
const ll N = 3e5+8;
ll n,k,a[N];
pll dp[N][2];
pll solve_lambda(ll m){
    dp[1][0] = {0,0};
    dp[1][1] = {a[1]-m,1};
    for(ll i = 2; i <= n; i++){
        dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
        dp[i][1] = max(make_pair(dp[i-1][0].fi-m+a[i],dp[i-1][0].se+1),make_pair(dp[i-1][1].fi+a[i],dp[i-1][1].se));
    }
    return max(dp[n][0],dp[n][1]);
}
void solve(){
    cin >> n >> k;
    for(ll i = 1; i <= n; i++) cin >> a[i];
    ll l = 0, r = 1e18;
    pll ans;
    ll lbd;
    while(l <= r){
        ll m = l+r>>1;
        pll s = solve_lambda(m);
        if(s.se <= k){
            ans = s;
            lbd = m;
            r = m-1;
        }
        else l = m+1;
    }
    cout << ans.fi+lbd*k;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if(fopen("test.inp","r")){
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ll T = 1;
    // cin >> T;
    for(ll i = 1; i <= T; i++){
        solve();
        // cout << '\n';
    }
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:39:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         ll m = l+r>>1;
      |                ~^~
feast.cpp: In function 'int main()':
feast.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
feast.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
feast.cpp: In function 'void solve()':
feast.cpp:48:23: warning: 'lbd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     cout << ans.fi+lbd*k;
      |                    ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 52 ms 12100 KB Output is correct
2 Correct 55 ms 12152 KB Output is correct
3 Correct 53 ms 12120 KB Output is correct
4 Correct 53 ms 12112 KB Output is correct
5 Correct 55 ms 12116 KB Output is correct
6 Correct 51 ms 12124 KB Output is correct
7 Correct 51 ms 12104 KB Output is correct
8 Correct 57 ms 12124 KB Output is correct
9 Correct 52 ms 12124 KB Output is correct
10 Correct 52 ms 12040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 12124 KB Output is correct
2 Correct 54 ms 12124 KB Output is correct
3 Correct 45 ms 12124 KB Output is correct
4 Correct 45 ms 11988 KB Output is correct
5 Correct 54 ms 11860 KB Output is correct
6 Correct 46 ms 12124 KB Output is correct
7 Correct 46 ms 12180 KB Output is correct
8 Correct 53 ms 12120 KB Output is correct
9 Correct 57 ms 11988 KB Output is correct
10 Correct 46 ms 12120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 12156 KB Output is correct
2 Correct 77 ms 12112 KB Output is correct
3 Correct 81 ms 12124 KB Output is correct
4 Correct 83 ms 12116 KB Output is correct
5 Correct 76 ms 12112 KB Output is correct
6 Correct 79 ms 12116 KB Output is correct
7 Correct 78 ms 12112 KB Output is correct
8 Correct 76 ms 12120 KB Output is correct
9 Correct 76 ms 12124 KB Output is correct
10 Correct 79 ms 12172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 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 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2472 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 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2472 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 12100 KB Output is correct
2 Correct 55 ms 12152 KB Output is correct
3 Correct 53 ms 12120 KB Output is correct
4 Correct 53 ms 12112 KB Output is correct
5 Correct 55 ms 12116 KB Output is correct
6 Correct 51 ms 12124 KB Output is correct
7 Correct 51 ms 12104 KB Output is correct
8 Correct 57 ms 12124 KB Output is correct
9 Correct 52 ms 12124 KB Output is correct
10 Correct 52 ms 12040 KB Output is correct
11 Correct 50 ms 12124 KB Output is correct
12 Correct 54 ms 12124 KB Output is correct
13 Correct 45 ms 12124 KB Output is correct
14 Correct 45 ms 11988 KB Output is correct
15 Correct 54 ms 11860 KB Output is correct
16 Correct 46 ms 12124 KB Output is correct
17 Correct 46 ms 12180 KB Output is correct
18 Correct 53 ms 12120 KB Output is correct
19 Correct 57 ms 11988 KB Output is correct
20 Correct 46 ms 12120 KB Output is correct
21 Correct 79 ms 12156 KB Output is correct
22 Correct 77 ms 12112 KB Output is correct
23 Correct 81 ms 12124 KB Output is correct
24 Correct 83 ms 12116 KB Output is correct
25 Correct 76 ms 12112 KB Output is correct
26 Correct 79 ms 12116 KB Output is correct
27 Correct 78 ms 12112 KB Output is correct
28 Correct 76 ms 12120 KB Output is correct
29 Correct 76 ms 12124 KB Output is correct
30 Correct 79 ms 12172 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2392 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 0 ms 2472 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 2 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2392 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 104 ms 12116 KB Output is correct
62 Correct 108 ms 12116 KB Output is correct
63 Correct 89 ms 12120 KB Output is correct
64 Correct 109 ms 12120 KB Output is correct
65 Correct 113 ms 12120 KB Output is correct
66 Correct 110 ms 12112 KB Output is correct
67 Correct 110 ms 12112 KB Output is correct
68 Correct 79 ms 12112 KB Output is correct
69 Correct 79 ms 11964 KB Output is correct
70 Correct 75 ms 12120 KB Output is correct