답안 #791750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791750 2023-07-24T09:33:59 Z minhnhatnoe Feast (NOI19_feast) C++14
100 / 100
93 ms 7392 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> a;

pair<ll, int> choose(pair<ll, int> a, pair<ll, int> b){
    if (a.first == b.first) return min(a, b);
    return max(a, b);
}
pair<ll, int> calc(ll bm){
    int n = a.size();
    pair<ll, int> pfmax(0, 0);
    pair<ll, int> prevdp(0, 0);
    for (int i=0; i<n; i++){
        // dp[i] = max(dp[i-1], dp[k-1] + pf[i] - pf[k-1] - bm)
        //                      (dp[k-1] - pf[k-1]) + pf[i] - bm
        pair<ll, int> cdp = prevdp;
        cdp = choose(cdp, pair<ll, int> (pfmax.first + a[i] - bm,
            pfmax.second + 1));
        pfmax = choose(pfmax, pair<ll, int> (cdp.first - a[i], cdp.second));
        prevdp = cdp;
    }
    return prevdp;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, k; cin >> n >> k;
    a.resize(n);
    for (int i=0; i<n; i++) cin >> a[i];
    partial_sum(a.begin(), a.end(), a.begin());

    ll bl=0, br=1e18;
    vector<pair<ll, int>> dp(n);
    while (bl < br){
        ll bm = (bl + br) >> 1;
        if (calc(bm).second > k) bl = bm+1;
        else br = bm;
    }
    pair<ll, int> s = calc(bl);
    cout << s.first + k * bl << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 7140 KB Output is correct
2 Correct 82 ms 7264 KB Output is correct
3 Correct 83 ms 7356 KB Output is correct
4 Correct 86 ms 7392 KB Output is correct
5 Correct 80 ms 7248 KB Output is correct
6 Correct 80 ms 7148 KB Output is correct
7 Correct 86 ms 7084 KB Output is correct
8 Correct 80 ms 7292 KB Output is correct
9 Correct 79 ms 7088 KB Output is correct
10 Correct 85 ms 7228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 7196 KB Output is correct
2 Correct 75 ms 7348 KB Output is correct
3 Correct 73 ms 7172 KB Output is correct
4 Correct 73 ms 7252 KB Output is correct
5 Correct 80 ms 7096 KB Output is correct
6 Correct 73 ms 7168 KB Output is correct
7 Correct 74 ms 7356 KB Output is correct
8 Correct 82 ms 7268 KB Output is correct
9 Correct 80 ms 7116 KB Output is correct
10 Correct 75 ms 7308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 7276 KB Output is correct
2 Correct 83 ms 7084 KB Output is correct
3 Correct 85 ms 7260 KB Output is correct
4 Correct 83 ms 7196 KB Output is correct
5 Correct 84 ms 7252 KB Output is correct
6 Correct 85 ms 7264 KB Output is correct
7 Correct 88 ms 7244 KB Output is correct
8 Correct 83 ms 7256 KB Output is correct
9 Correct 85 ms 7276 KB Output is correct
10 Correct 85 ms 7280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 7140 KB Output is correct
2 Correct 82 ms 7264 KB Output is correct
3 Correct 83 ms 7356 KB Output is correct
4 Correct 86 ms 7392 KB Output is correct
5 Correct 80 ms 7248 KB Output is correct
6 Correct 80 ms 7148 KB Output is correct
7 Correct 86 ms 7084 KB Output is correct
8 Correct 80 ms 7292 KB Output is correct
9 Correct 79 ms 7088 KB Output is correct
10 Correct 85 ms 7228 KB Output is correct
11 Correct 73 ms 7196 KB Output is correct
12 Correct 75 ms 7348 KB Output is correct
13 Correct 73 ms 7172 KB Output is correct
14 Correct 73 ms 7252 KB Output is correct
15 Correct 80 ms 7096 KB Output is correct
16 Correct 73 ms 7168 KB Output is correct
17 Correct 74 ms 7356 KB Output is correct
18 Correct 82 ms 7268 KB Output is correct
19 Correct 80 ms 7116 KB Output is correct
20 Correct 75 ms 7308 KB Output is correct
21 Correct 85 ms 7276 KB Output is correct
22 Correct 83 ms 7084 KB Output is correct
23 Correct 85 ms 7260 KB Output is correct
24 Correct 83 ms 7196 KB Output is correct
25 Correct 84 ms 7252 KB Output is correct
26 Correct 85 ms 7264 KB Output is correct
27 Correct 88 ms 7244 KB Output is correct
28 Correct 83 ms 7256 KB Output is correct
29 Correct 85 ms 7276 KB Output is correct
30 Correct 85 ms 7280 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 83 ms 7172 KB Output is correct
62 Correct 89 ms 7244 KB Output is correct
63 Correct 81 ms 7092 KB Output is correct
64 Correct 93 ms 7252 KB Output is correct
65 Correct 84 ms 7292 KB Output is correct
66 Correct 84 ms 7284 KB Output is correct
67 Correct 82 ms 7100 KB Output is correct
68 Correct 83 ms 7300 KB Output is correct
69 Correct 83 ms 7092 KB Output is correct
70 Correct 87 ms 7136 KB Output is correct