Submission #892800

# Submission time Handle Problem Language Result Execution time Memory
892800 2023-12-26T02:21:25 Z votranngocvy Feast (NOI19_feast) C++14
100 / 100
306 ms 36052 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
const int N = 3e5 + 5;
const int inf = (long long)(1e9 * N);
int a[N],pre[N],n,k;

namespace sub1 {
    bool check_condition() {
        for (int i = 1; i <= n; i++)
            if (a[i] < 0) return false;
        return true;
    }
    void solve() {
        int ans = 0;
        for (int i = 1; i <= n; i++) ans += a[i];
        cout << ans << "\n";
    }
}

namespace sub2 {
    bool check_condition() {
        int cnt = 0;
        for (int i = 1; i <= n; i++)
            if (a[i] < 0) cnt++;
        return (cnt == 1);
    }
    void solve() {
        pre[0] = 0;
        int pos = 0;
        for (int i = 1; i <= n; i++) {
            pre[i] = pre[i - 1] + a[i];
            if (a[i] < 0) pos = i;
        }
        if (k == 1) cout << max(max(pre[pos - 1],pre[n] - pre[pos]),pre[n]) << "\n";
        else cout << pre[n] - a[pos] << "\n";
    }
}

namespace sub3 {
    void solve() {
        int ans = -inf,sum = 0;
        for (int i = 1; i <= n; i++) {
            sum = max(sum + a[i],a[i]);
            ans = max(ans,sum);
        }
        cout << ans << "\n";
    }
}

namespace sub5 {
    int dp[305][305];
    void solve() {
        pre[0] = 0;
        for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= k; j++) {
                dp[i][j] = dp[i - 1][j];
                for (int z = 1; z <= i; z++)
                    dp[i][j] = max(dp[i][j],dp[z - 1][j - 1] + pre[i] - pre[z - 1]);
            }
        cout << dp[n][k] << "\n";
    }
}

namespace sub7 {
    pair<ld,int>dp[N][3];
    bool check(ld val) {
        dp[0][0] = mp(0,0),dp[0][1] = mp(-inf,0);
        for (int i = 1; i <= n; i++) {
            dp[i][0] = max(dp[i - 1][0],dp[i - 1][1]);
            dp[i][1] = max(mp(dp[i - 1][0].fi + (ld)a[i] - val,dp[i - 1][0].se + 1),mp(dp[i - 1][1].fi + (ld)a[i],dp[i - 1][1].se));
        }
        return (max(dp[n][0],dp[n][1]).se >= k);
    }
    void alien_trick() {
        ld l = 0,r = inf;
        while (l + 1e-3 < r) {
            ld mid = (l + r) / 2.0;
            if (check(mid)) l = mid + 1;
            else r = mid;
        }
        check(l);
        cout << (int)(k * l + max(dp[n][0],dp[n][1]).fi) << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    /*if (sub1::check_condition()) sub1::solve();
    else if (sub2::check_condition()) sub2::solve();
    else if (k == 1) sub3::solve();
    else if (n <= 300) sub5::solve();
    else */
    sub7::alien_trick();
}
# Verdict Execution time Memory Grader output
1 Correct 194 ms 35252 KB Output is correct
2 Correct 194 ms 35804 KB Output is correct
3 Correct 210 ms 36052 KB Output is correct
4 Correct 196 ms 35664 KB Output is correct
5 Correct 196 ms 35808 KB Output is correct
6 Correct 192 ms 35508 KB Output is correct
7 Correct 194 ms 35412 KB Output is correct
8 Correct 195 ms 35820 KB Output is correct
9 Correct 190 ms 35408 KB Output is correct
10 Correct 193 ms 35796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 34756 KB Output is correct
2 Correct 161 ms 34652 KB Output is correct
3 Correct 183 ms 34648 KB Output is correct
4 Correct 204 ms 34768 KB Output is correct
5 Correct 173 ms 35416 KB Output is correct
6 Correct 158 ms 34748 KB Output is correct
7 Correct 198 ms 34640 KB Output is correct
8 Correct 209 ms 35820 KB Output is correct
9 Correct 196 ms 35504 KB Output is correct
10 Correct 202 ms 34796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 35760 KB Output is correct
2 Correct 234 ms 35780 KB Output is correct
3 Correct 216 ms 35804 KB Output is correct
4 Correct 233 ms 35784 KB Output is correct
5 Correct 201 ms 35796 KB Output is correct
6 Correct 205 ms 35664 KB Output is correct
7 Correct 207 ms 35824 KB Output is correct
8 Correct 197 ms 35776 KB Output is correct
9 Correct 205 ms 35828 KB Output is correct
10 Correct 202 ms 35828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4452 KB Output is correct
2 Correct 1 ms 4452 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4452 KB Output is correct
6 Correct 1 ms 4572 KB Output is correct
7 Correct 1 ms 4452 KB Output is correct
8 Correct 1 ms 4572 KB Output is correct
9 Correct 1 ms 4452 KB Output is correct
10 Correct 1 ms 4452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4452 KB Output is correct
2 Correct 1 ms 4452 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4452 KB Output is correct
6 Correct 1 ms 4572 KB Output is correct
7 Correct 1 ms 4452 KB Output is correct
8 Correct 1 ms 4572 KB Output is correct
9 Correct 1 ms 4452 KB Output is correct
10 Correct 1 ms 4452 KB Output is correct
11 Correct 1 ms 4452 KB Output is correct
12 Correct 1 ms 4452 KB Output is correct
13 Correct 1 ms 4452 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4448 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4452 KB Output is correct
2 Correct 1 ms 4452 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4452 KB Output is correct
6 Correct 1 ms 4572 KB Output is correct
7 Correct 1 ms 4452 KB Output is correct
8 Correct 1 ms 4572 KB Output is correct
9 Correct 1 ms 4452 KB Output is correct
10 Correct 1 ms 4452 KB Output is correct
11 Correct 1 ms 4452 KB Output is correct
12 Correct 1 ms 4452 KB Output is correct
13 Correct 1 ms 4452 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4448 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 2 ms 6812 KB Output is correct
23 Correct 2 ms 6752 KB Output is correct
24 Correct 3 ms 6752 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 5 ms 6820 KB Output is correct
27 Correct 3 ms 6752 KB Output is correct
28 Correct 2 ms 6752 KB Output is correct
29 Correct 2 ms 6752 KB Output is correct
30 Correct 2 ms 6752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 35252 KB Output is correct
2 Correct 194 ms 35804 KB Output is correct
3 Correct 210 ms 36052 KB Output is correct
4 Correct 196 ms 35664 KB Output is correct
5 Correct 196 ms 35808 KB Output is correct
6 Correct 192 ms 35508 KB Output is correct
7 Correct 194 ms 35412 KB Output is correct
8 Correct 195 ms 35820 KB Output is correct
9 Correct 190 ms 35408 KB Output is correct
10 Correct 193 ms 35796 KB Output is correct
11 Correct 183 ms 34756 KB Output is correct
12 Correct 161 ms 34652 KB Output is correct
13 Correct 183 ms 34648 KB Output is correct
14 Correct 204 ms 34768 KB Output is correct
15 Correct 173 ms 35416 KB Output is correct
16 Correct 158 ms 34748 KB Output is correct
17 Correct 198 ms 34640 KB Output is correct
18 Correct 209 ms 35820 KB Output is correct
19 Correct 196 ms 35504 KB Output is correct
20 Correct 202 ms 34796 KB Output is correct
21 Correct 236 ms 35760 KB Output is correct
22 Correct 234 ms 35780 KB Output is correct
23 Correct 216 ms 35804 KB Output is correct
24 Correct 233 ms 35784 KB Output is correct
25 Correct 201 ms 35796 KB Output is correct
26 Correct 205 ms 35664 KB Output is correct
27 Correct 207 ms 35824 KB Output is correct
28 Correct 197 ms 35776 KB Output is correct
29 Correct 205 ms 35828 KB Output is correct
30 Correct 202 ms 35828 KB Output is correct
31 Correct 1 ms 4452 KB Output is correct
32 Correct 1 ms 4452 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4452 KB Output is correct
36 Correct 1 ms 4572 KB Output is correct
37 Correct 1 ms 4452 KB Output is correct
38 Correct 1 ms 4572 KB Output is correct
39 Correct 1 ms 4452 KB Output is correct
40 Correct 1 ms 4452 KB Output is correct
41 Correct 1 ms 4452 KB Output is correct
42 Correct 1 ms 4452 KB Output is correct
43 Correct 1 ms 4452 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4440 KB Output is correct
49 Correct 1 ms 4448 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 2 ms 6812 KB Output is correct
53 Correct 2 ms 6752 KB Output is correct
54 Correct 3 ms 6752 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 5 ms 6820 KB Output is correct
57 Correct 3 ms 6752 KB Output is correct
58 Correct 2 ms 6752 KB Output is correct
59 Correct 2 ms 6752 KB Output is correct
60 Correct 2 ms 6752 KB Output is correct
61 Correct 293 ms 35768 KB Output is correct
62 Correct 306 ms 35792 KB Output is correct
63 Correct 223 ms 35768 KB Output is correct
64 Correct 266 ms 35816 KB Output is correct
65 Correct 261 ms 35668 KB Output is correct
66 Correct 256 ms 35820 KB Output is correct
67 Correct 257 ms 35772 KB Output is correct
68 Correct 200 ms 35812 KB Output is correct
69 Correct 200 ms 35544 KB Output is correct
70 Correct 227 ms 35764 KB Output is correct