답안 #474552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474552 2021-09-19T02:51:38 Z PurpleCrayon Feast (NOI19_feast) C++17
67 / 100
256 ms 12732 KB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int MAXN = 3e5+10, MOD = 1e9+7;

int n, k;
ll a[MAXN], ps[MAXN];
pair<double, ll> dp[MAXN];

pair<double, ll> v(double x) { // cnt, cost
    fill(dp, dp+n, make_pair(0., 0ll));
    pair<double, ll> prv{0., 0};
    for (int i = 0; i < n; i++) {
        if (i) dp[i] = dp[i-1];
        // {ps[i] - ps[j] + dp[j].first, dp[j].second + 1}
        dp[i] = max(dp[i], make_pair(prv.first + ps[i] - x, prv.second + 1));
        prv = max(prv, make_pair(-ps[i] + dp[i].first, dp[i].second));
    }
    return dp[n-1];
}
void solve() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) ps[i] = a[i] + (i ? ps[i-1] : 0);

    double lo = 1e-9, hi = 1e18;
    for (int rep = 0; rep < 80; rep++) {
        double mid = (lo + hi) / 2;
        if (v(mid).second >= k) lo = mid;
        else hi = mid;
    }
    double opt = lo;
    auto [ans, cnt] = v(opt);
    ans += opt * cnt;
    cout << llround(ans) << '\n';
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int T=1;
    //cin >> T;
    while (T--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 11064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 9960 KB Output is correct
2 Correct 162 ms 10820 KB Output is correct
3 Correct 167 ms 10568 KB Output is correct
4 Correct 164 ms 10556 KB Output is correct
5 Correct 188 ms 12232 KB Output is correct
6 Correct 163 ms 10524 KB Output is correct
7 Correct 160 ms 10828 KB Output is correct
8 Correct 180 ms 12568 KB Output is correct
9 Correct 170 ms 12156 KB Output is correct
10 Correct 162 ms 10760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 11352 KB Output is correct
2 Correct 235 ms 12520 KB Output is correct
3 Correct 222 ms 12576 KB Output is correct
4 Correct 233 ms 12468 KB Output is correct
5 Correct 256 ms 12528 KB Output is correct
6 Correct 234 ms 12660 KB Output is correct
7 Correct 237 ms 12700 KB Output is correct
8 Correct 253 ms 12532 KB Output is correct
9 Correct 232 ms 12732 KB Output is correct
10 Correct 248 ms 12704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 396 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 11064 KB Output isn't correct
2 Halted 0 ms 0 KB -