답안 #848216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
848216 2023-09-11T16:30:14 Z quanlt206 Feast (NOI19_feast) C++14
100 / 100
662 ms 11856 KB
#include <bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, b, a) for (int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define SQR(x) (1LL * (x) * (x))
#define MASK(x) (1LL << (x))
#define mxx max_element
#define mnn min_element

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;

template<class A, class B>
    bool maximize(A& x, B y) {
        if (x < y) return x = y, true; else return false;
    }

template<class A, class B>
    bool minimize(A& x, B y) {
        if (x > y) return x = y, true; else return false;
    }
/* END OF TEMPLATE */

const int N = 3e5 + 7;

long double dp[N];

int trace[N], n, k;

ll a[N];

pll dynamic_dp(long double cost) {
    dp[0] = 0;
    FOR(i, 1, n) dp[i] = -1e18;
    long double tmp_val = 0;
    int idx = 0;
    FOR(i, 1, n) {
        dp[i] = dp[i - 1];
        if (maximize(dp[i], tmp_val + a[i] - cost)) trace[i] = idx;
        if (maximize(tmp_val, dp[i - 1] - a[i])) idx = i;
    }
    ll cnt = 0, res = 0;
    int i = n;
    while (i > 0) {
        if (abs(dp[i] - dp[i - 1]) < 1e-9) {
            i--;
            continue;
        }
        cnt++;
        res+=a[i] - a[trace[i]];
        i = trace[i] - 1;
    }
    return {cnt, res};
}

int main() {
//    freopen("test.INP", "r", stdin);
//    freopen("test.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    FOR(i, 1, n) cin>>a[i], a[i]+=a[i - 1];
    long double l = -1e12, r = 1e12;
    ll res = 0;
    FOR(i, 1, 100) {
        long double mid = (l + r) / 2.0;
        pll tmp = dynamic_dp(mid);
//        exit(0);
        if (tmp.X <= k) {
            maximize(res, tmp.Y);
            r = mid;
        }
        else l = mid;
    }
    cout<<res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 8528 KB Output is correct
2 Correct 401 ms 8596 KB Output is correct
3 Correct 434 ms 8784 KB Output is correct
4 Correct 421 ms 8620 KB Output is correct
5 Correct 390 ms 8596 KB Output is correct
6 Correct 408 ms 8516 KB Output is correct
7 Correct 415 ms 8760 KB Output is correct
8 Correct 343 ms 8528 KB Output is correct
9 Correct 344 ms 8528 KB Output is correct
10 Correct 350 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 8540 KB Output is correct
2 Correct 313 ms 8796 KB Output is correct
3 Correct 309 ms 8540 KB Output is correct
4 Correct 467 ms 8536 KB Output is correct
5 Correct 330 ms 8272 KB Output is correct
6 Correct 312 ms 8536 KB Output is correct
7 Correct 387 ms 8652 KB Output is correct
8 Correct 335 ms 8784 KB Output is correct
9 Correct 316 ms 8272 KB Output is correct
10 Correct 444 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 441 ms 8604 KB Output is correct
2 Correct 432 ms 8784 KB Output is correct
3 Correct 426 ms 8528 KB Output is correct
4 Correct 425 ms 8544 KB Output is correct
5 Correct 425 ms 8728 KB Output is correct
6 Correct 439 ms 8528 KB Output is correct
7 Correct 436 ms 8632 KB Output is correct
8 Correct 431 ms 8528 KB Output is correct
9 Correct 435 ms 8640 KB Output is correct
10 Correct 440 ms 8628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 3 ms 2392 KB Output is correct
22 Correct 3 ms 2396 KB Output is correct
23 Correct 4 ms 2392 KB Output is correct
24 Correct 3 ms 2392 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 3 ms 2392 KB Output is correct
27 Correct 3 ms 2392 KB Output is correct
28 Correct 3 ms 2392 KB Output is correct
29 Correct 3 ms 2648 KB Output is correct
30 Correct 3 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 8528 KB Output is correct
2 Correct 401 ms 8596 KB Output is correct
3 Correct 434 ms 8784 KB Output is correct
4 Correct 421 ms 8620 KB Output is correct
5 Correct 390 ms 8596 KB Output is correct
6 Correct 408 ms 8516 KB Output is correct
7 Correct 415 ms 8760 KB Output is correct
8 Correct 343 ms 8528 KB Output is correct
9 Correct 344 ms 8528 KB Output is correct
10 Correct 350 ms 8568 KB Output is correct
11 Correct 286 ms 8540 KB Output is correct
12 Correct 313 ms 8796 KB Output is correct
13 Correct 309 ms 8540 KB Output is correct
14 Correct 467 ms 8536 KB Output is correct
15 Correct 330 ms 8272 KB Output is correct
16 Correct 312 ms 8536 KB Output is correct
17 Correct 387 ms 8652 KB Output is correct
18 Correct 335 ms 8784 KB Output is correct
19 Correct 316 ms 8272 KB Output is correct
20 Correct 444 ms 8784 KB Output is correct
21 Correct 441 ms 8604 KB Output is correct
22 Correct 432 ms 8784 KB Output is correct
23 Correct 426 ms 8528 KB Output is correct
24 Correct 425 ms 8544 KB Output is correct
25 Correct 425 ms 8728 KB Output is correct
26 Correct 439 ms 8528 KB Output is correct
27 Correct 436 ms 8632 KB Output is correct
28 Correct 431 ms 8528 KB Output is correct
29 Correct 435 ms 8640 KB Output is correct
30 Correct 440 ms 8628 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2392 KB Output is correct
46 Correct 1 ms 2392 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 1 ms 2392 KB Output is correct
49 Correct 1 ms 2392 KB Output is correct
50 Correct 1 ms 2392 KB Output is correct
51 Correct 3 ms 2392 KB Output is correct
52 Correct 3 ms 2396 KB Output is correct
53 Correct 4 ms 2392 KB Output is correct
54 Correct 3 ms 2392 KB Output is correct
55 Correct 3 ms 2396 KB Output is correct
56 Correct 3 ms 2392 KB Output is correct
57 Correct 3 ms 2392 KB Output is correct
58 Correct 3 ms 2392 KB Output is correct
59 Correct 3 ms 2648 KB Output is correct
60 Correct 3 ms 2392 KB Output is correct
61 Correct 651 ms 11356 KB Output is correct
62 Correct 658 ms 11712 KB Output is correct
63 Correct 478 ms 11344 KB Output is correct
64 Correct 662 ms 11856 KB Output is correct
65 Correct 648 ms 11644 KB Output is correct
66 Correct 633 ms 11856 KB Output is correct
67 Correct 622 ms 11504 KB Output is correct
68 Correct 433 ms 11656 KB Output is correct
69 Correct 424 ms 11600 KB Output is correct
70 Correct 425 ms 11344 KB Output is correct