Submission #871575

# Submission time Handle Problem Language Result Execution time Memory
871575 2023-11-11T06:20:11 Z MON Feast (NOI19_feast) C++14
100 / 100
255 ms 14056 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 203 ms 13392 KB Output is correct
2 Correct 208 ms 13704 KB Output is correct
3 Correct 210 ms 13848 KB Output is correct
4 Correct 209 ms 13660 KB Output is correct
5 Correct 210 ms 13688 KB Output is correct
6 Correct 210 ms 13396 KB Output is correct
7 Correct 206 ms 13348 KB Output is correct
8 Correct 217 ms 14056 KB Output is correct
9 Correct 206 ms 13396 KB Output is correct
10 Correct 221 ms 13392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 12212 KB Output is correct
2 Correct 173 ms 12084 KB Output is correct
3 Correct 176 ms 11604 KB Output is correct
4 Correct 176 ms 11740 KB Output is correct
5 Correct 206 ms 13468 KB Output is correct
6 Correct 169 ms 11608 KB Output is correct
7 Correct 183 ms 12116 KB Output is correct
8 Correct 209 ms 13700 KB Output is correct
9 Correct 205 ms 13396 KB Output is correct
10 Correct 172 ms 11856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 13848 KB Output is correct
2 Correct 217 ms 13628 KB Output is correct
3 Correct 216 ms 13824 KB Output is correct
4 Correct 211 ms 13648 KB Output is correct
5 Correct 255 ms 13952 KB Output is correct
6 Correct 214 ms 13908 KB Output is correct
7 Correct 222 ms 13968 KB Output is correct
8 Correct 221 ms 13864 KB Output is correct
9 Correct 217 ms 14012 KB Output is correct
10 Correct 215 ms 13908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 372 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 600 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 1 ms 348 KB Output is correct
2 Correct 0 ms 372 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 600 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 1 ms 348 KB Output is correct
12 Correct 0 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 1 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 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 372 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 600 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 1 ms 348 KB Output is correct
12 Correct 0 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 1 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 344 KB Output is correct
19 Correct 1 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 344 KB Output is correct
23 Correct 2 ms 348 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 344 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 13392 KB Output is correct
2 Correct 208 ms 13704 KB Output is correct
3 Correct 210 ms 13848 KB Output is correct
4 Correct 209 ms 13660 KB Output is correct
5 Correct 210 ms 13688 KB Output is correct
6 Correct 210 ms 13396 KB Output is correct
7 Correct 206 ms 13348 KB Output is correct
8 Correct 217 ms 14056 KB Output is correct
9 Correct 206 ms 13396 KB Output is correct
10 Correct 221 ms 13392 KB Output is correct
11 Correct 174 ms 12212 KB Output is correct
12 Correct 173 ms 12084 KB Output is correct
13 Correct 176 ms 11604 KB Output is correct
14 Correct 176 ms 11740 KB Output is correct
15 Correct 206 ms 13468 KB Output is correct
16 Correct 169 ms 11608 KB Output is correct
17 Correct 183 ms 12116 KB Output is correct
18 Correct 209 ms 13700 KB Output is correct
19 Correct 205 ms 13396 KB Output is correct
20 Correct 172 ms 11856 KB Output is correct
21 Correct 215 ms 13848 KB Output is correct
22 Correct 217 ms 13628 KB Output is correct
23 Correct 216 ms 13824 KB Output is correct
24 Correct 211 ms 13648 KB Output is correct
25 Correct 255 ms 13952 KB Output is correct
26 Correct 214 ms 13908 KB Output is correct
27 Correct 222 ms 13968 KB Output is correct
28 Correct 221 ms 13864 KB Output is correct
29 Correct 217 ms 14012 KB Output is correct
30 Correct 215 ms 13908 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 372 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 600 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 1 ms 348 KB Output is correct
42 Correct 0 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 1 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 344 KB Output is correct
49 Correct 1 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 344 KB Output is correct
53 Correct 2 ms 348 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 344 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 344 KB Output is correct
59 Correct 2 ms 600 KB Output is correct
60 Correct 2 ms 344 KB Output is correct
61 Correct 212 ms 13696 KB Output is correct
62 Correct 218 ms 14028 KB Output is correct
63 Correct 211 ms 13744 KB Output is correct
64 Correct 217 ms 13904 KB Output is correct
65 Correct 223 ms 13888 KB Output is correct
66 Correct 228 ms 13884 KB Output is correct
67 Correct 222 ms 13692 KB Output is correct
68 Correct 228 ms 13940 KB Output is correct
69 Correct 228 ms 13892 KB Output is correct
70 Correct 230 ms 13396 KB Output is correct