Submission #971442

# Submission time Handle Problem Language Result Execution time Memory
971442 2024-04-28T13:55:37 Z mychecksedad Feast (NOI19_feast) C++17
100 / 100
135 ms 18036 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
const double eps = 0.00001;

int n, k;
ll a[N];
pair<ll, int> dp[N][2];
pair<ll, int> f(ll lambda){
  dp[1][0] = {0, 0};
  dp[1][1] = {a[1] - lambda, 1};
  for(int i = 2; i <= n; ++i){
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = max(pair<ll,int>{dp[i - 1][0].first + a[i] - lambda, dp[i - 1][0].second + 1}, pair<ll,int>{dp[i - 1][1].first + a[i], dp[i - 1][1].second});
  }
  // cout << dp[1][1].first << ' ';
  return max(dp[n][0], dp[n][1]);
}
void solve(){
  cin >> n >> k;
  for(int i = 1; i <= n; ++i) cin >> a[i];
  ll l = 0, r = 1e18, lambda = 0;
  while(l <= r){
    ll m = (l+r)/2;
    if(f(m).second <= k){
      lambda = m;
      r = m - 1;
    }else{
      l = m + 1;
    }
  }

  // cout << f(lambda).second << ' ';

  cout << (ll)(f(lambda).first + lambda * k);
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:48:15: warning: unused variable 'aa' [-Wunused-variable]
   48 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 72 ms 17712 KB Output is correct
2 Correct 72 ms 17628 KB Output is correct
3 Correct 73 ms 17872 KB Output is correct
4 Correct 76 ms 17756 KB Output is correct
5 Correct 74 ms 17848 KB Output is correct
6 Correct 71 ms 17756 KB Output is correct
7 Correct 79 ms 17748 KB Output is correct
8 Correct 73 ms 17852 KB Output is correct
9 Correct 76 ms 17976 KB Output is correct
10 Correct 79 ms 17740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 15960 KB Output is correct
2 Correct 65 ms 15960 KB Output is correct
3 Correct 63 ms 15964 KB Output is correct
4 Correct 64 ms 15960 KB Output is correct
5 Correct 75 ms 17756 KB Output is correct
6 Correct 65 ms 16104 KB Output is correct
7 Correct 70 ms 16132 KB Output is correct
8 Correct 74 ms 17748 KB Output is correct
9 Correct 72 ms 17744 KB Output is correct
10 Correct 68 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 18004 KB Output is correct
2 Correct 96 ms 17968 KB Output is correct
3 Correct 96 ms 17984 KB Output is correct
4 Correct 94 ms 17744 KB Output is correct
5 Correct 95 ms 18004 KB Output is correct
6 Correct 96 ms 18000 KB Output is correct
7 Correct 102 ms 17828 KB Output is correct
8 Correct 96 ms 18012 KB Output is correct
9 Correct 104 ms 17964 KB Output is correct
10 Correct 97 ms 18036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2516 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2516 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2592 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2516 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2592 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 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 1 ms 2396 KB Output is correct
27 Correct 1 ms 2532 KB Output is correct
28 Correct 1 ms 2396 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 72 ms 17712 KB Output is correct
2 Correct 72 ms 17628 KB Output is correct
3 Correct 73 ms 17872 KB Output is correct
4 Correct 76 ms 17756 KB Output is correct
5 Correct 74 ms 17848 KB Output is correct
6 Correct 71 ms 17756 KB Output is correct
7 Correct 79 ms 17748 KB Output is correct
8 Correct 73 ms 17852 KB Output is correct
9 Correct 76 ms 17976 KB Output is correct
10 Correct 79 ms 17740 KB Output is correct
11 Correct 63 ms 15960 KB Output is correct
12 Correct 65 ms 15960 KB Output is correct
13 Correct 63 ms 15964 KB Output is correct
14 Correct 64 ms 15960 KB Output is correct
15 Correct 75 ms 17756 KB Output is correct
16 Correct 65 ms 16104 KB Output is correct
17 Correct 70 ms 16132 KB Output is correct
18 Correct 74 ms 17748 KB Output is correct
19 Correct 72 ms 17744 KB Output is correct
20 Correct 68 ms 15960 KB Output is correct
21 Correct 97 ms 18004 KB Output is correct
22 Correct 96 ms 17968 KB Output is correct
23 Correct 96 ms 17984 KB Output is correct
24 Correct 94 ms 17744 KB Output is correct
25 Correct 95 ms 18004 KB Output is correct
26 Correct 96 ms 18000 KB Output is correct
27 Correct 102 ms 17828 KB Output is correct
28 Correct 96 ms 18012 KB Output is correct
29 Correct 104 ms 17964 KB Output is correct
30 Correct 97 ms 18036 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2516 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2516 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2508 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 1 ms 2592 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2392 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 1 ms 2396 KB Output is correct
57 Correct 1 ms 2532 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 131 ms 17832 KB Output is correct
62 Correct 126 ms 18000 KB Output is correct
63 Correct 109 ms 17968 KB Output is correct
64 Correct 135 ms 17984 KB Output is correct
65 Correct 132 ms 18000 KB Output is correct
66 Correct 131 ms 18012 KB Output is correct
67 Correct 129 ms 17744 KB Output is correct
68 Correct 96 ms 18032 KB Output is correct
69 Correct 93 ms 17744 KB Output is correct
70 Correct 96 ms 17952 KB Output is correct