답안 #1077261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077261 2024-08-27T04:14:54 Z YudoTLE Feast (NOI19_feast) C++17
0 / 100
27 ms 2324 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int INF = INT_MAX / 2;
const int MAXN = 1e5 + 5;

int n, k;
ll arr[MAXN], dp[MAXN][2];
int cnt[MAXN][2];
ll answer;

bool eval(ll c)
{
    dp[0][1] = -INF;
    for (int i = 1; i <= n; i++)
    {
        if (dp[i - 1][0] >= dp[i - 1][1])
        {
            dp[i][0] = dp[i - 1][0];
            cnt[i][0] = cnt[i - 1][0];
        }
        else
        {
            dp[i][0] = dp[i - 1][1];
            cnt[i][0] = cnt[i - 1][1];
        }
        if (dp[i - 1][0] - c >= dp[i - 1][1])
        {
            dp[i][1] = arr[i] + dp[i - 1][0] - c;
            cnt[i][1] = cnt[i - 1][0] + 1;
        }
        else
        {
            dp[i][1] = arr[i] + dp[i - 1][1];
            cnt[i][1] = cnt[i - 1][1];
        }
    }

    ll optv = LLONG_MIN;
    int optx = INT_MIN;
    for (int i = 0; i <= n; i++)
        for (int ii = 0; ii < 2; ii++)
    {
        ll nv = dp[i][ii] + c * cnt[i][ii];
        int nx = cnt[i][ii];
        if (nv > optv)
        {
            optv = nv;
            optx = nx;
        }
        if (nv == optv)
            optx = min(optx, nx);
    }
    if (optx <= k)
        answer = max(answer, optv);
    return optx <= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    ll lo = 0, hi = INF;
    // while (lo <= hi)
    // {
    //     ll mi = lo + (hi - lo) / 2;
    //     if (eval(mi))
    //         hi = mi - 1;
    //     else
    //         lo = mi + 1;
    // }
    // for (int i = 0; i <= 1000; i++)
    //     eval(i);

    // cout << answer << '\n';

    // cout << accumulate(arr + 1, arr + n + 1, 0ll) << '\n';
}

int main()
{
    // ios_base::sync_with_stdio(false), cin.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:78:8: warning: unused variable 'lo' [-Wunused-variable]
   78 |     ll lo = 0, hi = INF;
      |        ^~
feast.cpp:78:16: warning: unused variable 'hi' [-Wunused-variable]
   78 |     ll lo = 0, hi = INF;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 2128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 2324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 2128 KB Output isn't correct
2 Halted 0 ms 0 KB -