Submission #950600

# Submission time Handle Problem Language Result Execution time Memory
950600 2024-03-20T13:29:25 Z VMaksimoski008 Feast (NOI19_feast) C++14
0 / 100
1000 ms 9808 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

int32_t main() {
    int n, K, neg = 0;
    cin >> n >> K;

    vector<int> v(n+1);
    vector<ll> pref(n+1);
    for(int i=1; i<=n; i++) {
        cin >> v[i];
        neg += (v[i] < 0);
        pref[i] = pref[i-1] + v[i];
    }

    ll l=-1e15, r=1e15, ans=0;

    while(l <= r) {
        ll mid = (l + r) / 2;
        vector<ll> dp(n+1, 0), cnt(n+1, 1e9);
        cnt[0] = 0;

        for(int i=1; i<=n; i++) {
            dp[i] = dp[i-1];
            cnt[i] = cnt[i-1];
            for(int j=1; j<=i; j++) {
                if(dp[i] < dp[j-1] + pref[i] - pref[j-1] - mid) {
                    dp[i] = dp[j-1] + pref[i] - pref[j-1] - mid;
                    cnt[i] = cnt[j-1] + 1;
                } else if(dp[i] == dp[j-1] + pref[i] - pref[j-1] - mid) {
                    cnt[i] = min(cnt[i], cnt[j-1] + 1);
                }
            }
        }

        if(cnt[n] >= K) {
            ans = dp[n] + cnt[n] * mid;
            l = mid + 1;
        } else r = mid - 1;
    }

    cout << max(0ll, ans) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1037 ms 9300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 9556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 9808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1037 ms 9300 KB Time limit exceeded
2 Halted 0 ms 0 KB -