답안 #927890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927890 2024-02-15T13:45:17 Z sleepntsheep Feast (NOI19_feast) C++17
18 / 100
356 ms 22356 KB
#include <cstdio>
#include <cmath>
#include <climits>
#include <functional>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;

#define N 300005
#define ALL(x) x.begin(), x.end()

int n, k, a[N];
long long p[N];
pair<long double, int> dp[N][2];
const long double EPS = 1e-3;

int check(long double lambda)
{
    dp[0][1] = make_pair(-1e18, 0);
    for (int i = 1; i <= n; ++i)
    {
        dp[i][0] = max({dp[i-1][0], dp[i-1][1]});
        dp[i][1] = max(make_pair(dp[i-1][0].first + a[i] - lambda, dp[i-1][0].second + 1),
                make_pair(dp[i-1][1].first + a[i], dp[i-1][1].second));
    }
    return max(dp[n][0], dp[n][1]).second >= k;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    ll l = 0, r = 1e18;
    while (l <= r)
    {
        ll y = (l+r)/2;
        if (check(y)) l = y + 1;
        else r = y - 1;
    }

    check(l-1);
    cout << (long long)round(k * (l-1) + max(dp[n][0], dp[n][1]).first);

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Incorrect 329 ms 20232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 20240 KB Output is correct
2 Correct 328 ms 22100 KB Output is correct
3 Correct 321 ms 20308 KB Output is correct
4 Incorrect 327 ms 20060 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 20268 KB Output is correct
2 Correct 338 ms 20240 KB Output is correct
3 Correct 342 ms 20308 KB Output is correct
4 Correct 337 ms 20060 KB Output is correct
5 Correct 339 ms 20248 KB Output is correct
6 Correct 343 ms 20056 KB Output is correct
7 Correct 345 ms 22332 KB Output is correct
8 Correct 335 ms 20060 KB Output is correct
9 Correct 345 ms 22100 KB Output is correct
10 Correct 356 ms 22356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 329 ms 20232 KB Output isn't correct
2 Halted 0 ms 0 KB -