Submission #868720

# Submission time Handle Problem Language Result Execution time Memory
868720 2023-11-01T18:29:45 Z MON Feast (NOI19_feast) C++14
100 / 100
247 ms 14160 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 * ans.first;

    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 210 ms 10576 KB Output is correct
2 Correct 207 ms 10836 KB Output is correct
3 Correct 214 ms 10832 KB Output is correct
4 Correct 207 ms 10836 KB Output is correct
5 Correct 212 ms 10832 KB Output is correct
6 Correct 206 ms 10656 KB Output is correct
7 Correct 210 ms 10544 KB Output is correct
8 Correct 207 ms 10768 KB Output is correct
9 Correct 205 ms 10840 KB Output is correct
10 Correct 204 ms 10580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 10540 KB Output is correct
2 Correct 175 ms 11180 KB Output is correct
3 Correct 173 ms 10580 KB Output is correct
4 Correct 170 ms 10780 KB Output is correct
5 Correct 204 ms 10656 KB Output is correct
6 Correct 168 ms 11876 KB Output is correct
7 Correct 174 ms 12116 KB Output is correct
8 Correct 218 ms 13788 KB Output is correct
9 Correct 206 ms 13348 KB Output is correct
10 Correct 173 ms 11856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 10684 KB Output is correct
2 Correct 210 ms 13692 KB Output is correct
3 Correct 215 ms 13652 KB Output is correct
4 Correct 208 ms 13712 KB Output is correct
5 Correct 212 ms 13652 KB Output is correct
6 Correct 216 ms 13908 KB Output is correct
7 Correct 217 ms 14160 KB Output is correct
8 Correct 247 ms 13980 KB Output is correct
9 Correct 215 ms 13904 KB Output is correct
10 Correct 220 ms 13972 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 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 444 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 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 444 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 1 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 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 444 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 1 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 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 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 344 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 10576 KB Output is correct
2 Correct 207 ms 10836 KB Output is correct
3 Correct 214 ms 10832 KB Output is correct
4 Correct 207 ms 10836 KB Output is correct
5 Correct 212 ms 10832 KB Output is correct
6 Correct 206 ms 10656 KB Output is correct
7 Correct 210 ms 10544 KB Output is correct
8 Correct 207 ms 10768 KB Output is correct
9 Correct 205 ms 10840 KB Output is correct
10 Correct 204 ms 10580 KB Output is correct
11 Correct 169 ms 10540 KB Output is correct
12 Correct 175 ms 11180 KB Output is correct
13 Correct 173 ms 10580 KB Output is correct
14 Correct 170 ms 10780 KB Output is correct
15 Correct 204 ms 10656 KB Output is correct
16 Correct 168 ms 11876 KB Output is correct
17 Correct 174 ms 12116 KB Output is correct
18 Correct 218 ms 13788 KB Output is correct
19 Correct 206 ms 13348 KB Output is correct
20 Correct 173 ms 11856 KB Output is correct
21 Correct 213 ms 10684 KB Output is correct
22 Correct 210 ms 13692 KB Output is correct
23 Correct 215 ms 13652 KB Output is correct
24 Correct 208 ms 13712 KB Output is correct
25 Correct 212 ms 13652 KB Output is correct
26 Correct 216 ms 13908 KB Output is correct
27 Correct 217 ms 14160 KB Output is correct
28 Correct 247 ms 13980 KB Output is correct
29 Correct 215 ms 13904 KB Output is correct
30 Correct 220 ms 13972 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 1 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 444 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 1 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 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 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 344 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 604 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
61 Correct 210 ms 13692 KB Output is correct
62 Correct 218 ms 14036 KB Output is correct
63 Correct 214 ms 13776 KB Output is correct
64 Correct 219 ms 13928 KB Output is correct
65 Correct 213 ms 13904 KB Output is correct
66 Correct 213 ms 13880 KB Output is correct
67 Correct 210 ms 13684 KB Output is correct
68 Correct 228 ms 14028 KB Output is correct
69 Correct 223 ms 13652 KB Output is correct
70 Correct 237 ms 13396 KB Output is correct