제출 #917391

#제출 시각아이디문제언어결과실행 시간메모리
917391406Feast (NOI19_feast)C++17
100 / 100
112 ms5876 KiB
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ar = array<int, 2>;

const int64_t INF = 1ll << 60;
const int N = 3e5 + 5;
int n, k, a[N], ans;

bool check(const int O, bool f = 0) {
        ar dp{0, 0}, F{0, 0};
        int s = 0;
        FOR(i, 0, n) {
                s += a[i];
                F = max(F, ar{dp[0] - s, dp[1]});
                dp = max(dp, ar{s + F[0] - O, F[1] - 1});
        }
        if (f) ans = max(ans, dp[0] + k * O);
        return -dp[1] >= k;
}

signed main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); 
        cin >> n >> k;
        FOR(i, 0, n) cin >> a[i];
        int l = 0, r = 1ll << 50;
        while (r - l > 1) {
                int m = l + r >> 1;
                if (check(m)) l = m;
                else r = m;
        }
        check(l, 1);
        cout << ans << '\n';
        return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

feast.cpp: In function 'int main()':
feast.cpp:31:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |                 int m = l + r >> 1;
      |                         ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...