Submission #871576

# Submission time Handle Problem Language Result Execution time Memory
871576 2023-11-11T06:20:26 Z MON Feast (NOI19_feast) C++14
100 / 100
246 ms 11088 KB
#include<iostream>
#include<vector>
#warning we made it
using namespace std;
using ll = long long;
using pii = pair<int,long long>;
 
constexpr int NMAX = 3e5 + 1;
const ll oo = 1e16;
 
int a[NMAX];
 
inline pii best(pii a,pii b)
{
   if(a.second != b.second) return (a.second > b.second ? a : b);
   return (a.first < b.first ? a : b);
}
 
pii solve(int n,ll l)
{
    pii dp[2][n + 1]; dp[0][0] = {0,0},dp[1][0] = {0,-oo};
    for(int i = 0 ; i < n ; i++)
        {
            dp[0][i + 1] = best(dp[0][i],dp[1][i]);
            dp[1][i + 1] = best({dp[0][i].first + 1,dp[0][i].second + a[i + 1] - l},
                                {dp[1][i].first,dp[1][i].second + a[i + 1]});
        }
    return best(dp[0][n],dp[1][n]);
}
 
int main()
{
    int n,k; cin >> n >> k;
    for(int i = 1; i <= n ; i++) cin >> a[i];
 
    ll st = 0 , dr = 1LL << 62 , lambda(0);
    while(st <= dr)
        {
            ll mid = st + (dr - st) / 2; pii now = solve(n,mid);
            if(now.first <= k) dr = mid - 1,lambda = mid;
            else st = mid + 1;
        }
 
    pii ans = solve(n,lambda);
    ll out = ans.second + lambda * k;
 
    cout << out;
    //solve(n,1);
 
}

Compilation message

feast.cpp:3:2: warning: #warning we made it [-Wcpp]
    3 | #warning we made it
      |  ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 218 ms 10636 KB Output is correct
2 Correct 225 ms 10840 KB Output is correct
3 Correct 227 ms 10744 KB Output is correct
4 Correct 209 ms 10816 KB Output is correct
5 Correct 221 ms 10832 KB Output is correct
6 Correct 205 ms 10408 KB Output is correct
7 Correct 207 ms 10608 KB Output is correct
8 Correct 207 ms 10860 KB Output is correct
9 Correct 209 ms 10676 KB Output is correct
10 Correct 205 ms 10580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 10832 KB Output is correct
2 Correct 174 ms 10832 KB Output is correct
3 Correct 171 ms 10576 KB Output is correct
4 Correct 171 ms 10796 KB Output is correct
5 Correct 209 ms 10580 KB Output is correct
6 Correct 174 ms 10592 KB Output is correct
7 Correct 176 ms 10924 KB Output is correct
8 Correct 205 ms 10900 KB Output is correct
9 Correct 203 ms 10576 KB Output is correct
10 Correct 171 ms 10900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 10836 KB Output is correct
2 Correct 210 ms 10576 KB Output is correct
3 Correct 210 ms 10832 KB Output is correct
4 Correct 209 ms 10684 KB Output is correct
5 Correct 236 ms 10576 KB Output is correct
6 Correct 216 ms 10868 KB Output is correct
7 Correct 246 ms 10920 KB Output is correct
8 Correct 211 ms 10828 KB Output is correct
9 Correct 219 ms 11088 KB Output is correct
10 Correct 217 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 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 0 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 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 1 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 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 428 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 2 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 10636 KB Output is correct
2 Correct 225 ms 10840 KB Output is correct
3 Correct 227 ms 10744 KB Output is correct
4 Correct 209 ms 10816 KB Output is correct
5 Correct 221 ms 10832 KB Output is correct
6 Correct 205 ms 10408 KB Output is correct
7 Correct 207 ms 10608 KB Output is correct
8 Correct 207 ms 10860 KB Output is correct
9 Correct 209 ms 10676 KB Output is correct
10 Correct 205 ms 10580 KB Output is correct
11 Correct 174 ms 10832 KB Output is correct
12 Correct 174 ms 10832 KB Output is correct
13 Correct 171 ms 10576 KB Output is correct
14 Correct 171 ms 10796 KB Output is correct
15 Correct 209 ms 10580 KB Output is correct
16 Correct 174 ms 10592 KB Output is correct
17 Correct 176 ms 10924 KB Output is correct
18 Correct 205 ms 10900 KB Output is correct
19 Correct 203 ms 10576 KB Output is correct
20 Correct 171 ms 10900 KB Output is correct
21 Correct 213 ms 10836 KB Output is correct
22 Correct 210 ms 10576 KB Output is correct
23 Correct 210 ms 10832 KB Output is correct
24 Correct 209 ms 10684 KB Output is correct
25 Correct 236 ms 10576 KB Output is correct
26 Correct 216 ms 10868 KB Output is correct
27 Correct 246 ms 10920 KB Output is correct
28 Correct 211 ms 10828 KB Output is correct
29 Correct 219 ms 11088 KB Output is correct
30 Correct 217 ms 10836 KB Output is correct
31 Correct 0 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 0 ms 348 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 0 ms 348 KB Output is correct
42 Correct 1 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 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 440 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 428 KB Output is correct
55 Correct 2 ms 504 KB Output is correct
56 Correct 2 ms 344 KB Output is correct
57 Correct 2 ms 344 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 2 ms 600 KB Output is correct
60 Correct 2 ms 440 KB Output is correct
61 Correct 215 ms 10580 KB Output is correct
62 Correct 215 ms 10836 KB Output is correct
63 Correct 215 ms 10684 KB Output is correct
64 Correct 212 ms 10888 KB Output is correct
65 Correct 213 ms 10880 KB Output is correct
66 Correct 212 ms 10940 KB Output is correct
67 Correct 208 ms 10580 KB Output is correct
68 Correct 213 ms 10680 KB Output is correct
69 Correct 208 ms 10580 KB Output is correct
70 Correct 207 ms 10580 KB Output is correct