Submission #791745

# Submission time Handle Problem Language Result Execution time Memory
791745 2023-07-24T09:29:48 Z minhnhatnoe Feast (NOI19_feast) C++14
0 / 100
83 ms 6188 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> a;

pair<ll, int> choose(pair<ll, int> a, pair<ll, int> b){
    if (a.first == b.first) return min(a, b);
    return max(a, b);
}
pair<ll, int> calc(ll bm){
    int n = a.size();
    pair<ll, int> pfmax(0, 0);
    pair<ll, int> prevdp(0, 0);
    for (int i=0; i<n; i++){
        // dp[i] = max(dp[i-1], dp[k-1] + pf[i] - pf[k-1] - bm)
        //                      (dp[k-1] - pf[k-1]) + pf[i] - bm
        pair<ll, int> cdp = prevdp;
        cdp = choose(cdp, pair<ll, int> (pfmax.first + a[i] - bm,
            pfmax.second + 1));
        pfmax = choose(pfmax, pair<ll, int> (cdp.first - a[i], cdp.second));
        prevdp = cdp;
    }
    return prevdp;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, k; cin >> n >> k;
    a.resize(n);
    for (int i=0; i<n; i++) cin >> a[i];
    partial_sum(a.begin(), a.end(), a.begin());

    ll bl=0, br=1e18;
    vector<pair<ll, int>> dp(n);
    while (bl < br){
        ll bm = (bl + br) >> 1;
        if (calc(bm).second > k) bl = bm+1;
        else br = bm;
    }
    pair<ll, int> s = calc(bl);
    cout << s.first + k * bl << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 5964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 5960 KB Output is correct
2 Correct 76 ms 6188 KB Output is correct
3 Correct 73 ms 6036 KB Output is correct
4 Correct 73 ms 6092 KB Output is correct
5 Incorrect 80 ms 5964 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 6116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 5964 KB Output isn't correct
2 Halted 0 ms 0 KB -