답안 #930489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930489 2024-02-20T02:37:12 Z Pikachu Feast (NOI19_feast) C++17
0 / 100
57 ms 4956 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

template<typename T>
inline bool maxi(T &x, const T &val)
{
    if (x < val) return x = val, true;
    return false;
}

template<typename T>
inline bool mini(T &x, const T &val)
{
    if (x > val) return x = val, true;
    return false;
}

const int maxn = 3e5 + 10, oo = 1e15;
int n, k;
int a[maxn], S[maxn];
int dp, cnt;

void trydp(int lam)
{
    dp = cnt = 0;
    for (int i = 1, cur = 0, curcnt = 0; i <= n; i++) {
        if (maxi(dp, cur + S[i] - lam)) cnt = curcnt + 1;
        if (maxi(cur, dp - S[i])) curcnt = cnt;
    }
}

void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], S[i] = S[i - 1] + a[i];
    int l = 0, r = oo;
    while (l < r) {
        int mid = (l + r) >> 1;
        trydp(mid);
        if (cnt > k) {
            l = mid + 1;
        }
        else {
            r = mid;
        }
    }
    trydp(r);
    cout << dp << ' ' << cnt << '\n';
    cout << dp + cnt * r << '\n';
}

signed main()
{
#ifdef LOCAL
    clock_t st = clock();
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

#define Task ""
#ifdef LOCAL
    if (!fopen("D:\\.inp", "r")) {
        freopen("D:\\.inp", "w", stdout);
        freopen("D:\\.out", "w", stdout);
        cerr << "get input from file\n";
        return 0;
    }
    freopen("D:\\.inp", "r", stdin);
    freopen("D:\\.out", "w", stdout);
#else
    if (fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
#endif

    solve();

#ifdef LOCAL
    cerr << clock() - st << endl;
#endif
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(Task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -