Submission #697722

# Submission time Handle Problem Language Result Execution time Memory
697722 2023-02-10T22:23:48 Z thomas_li Feast (NOI19_feast) C++17
12 / 100
154 ms 10432 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,k; cin >> n >> k;
    vector<int> a(n); for(int& v : a) cin >> v;
    partial_sum(a.begin(),a.end(),a.begin());
    auto go = [&](int c){
        vector<int> dp(n+1,-1e18),cnt(n+1);
        dp[0] = 0;
        pair<int,int> mx = {0,0};
        pair<int,int> bst = {-1e18,0};
        for(int i = 1; i <= n; i++){
            dp[i] = dp[i-1]; cnt[i] = cnt[i-1];
            auto[adj, cntj] = mx; cntj *= -1;
            if(adj-c+a[i-1] > dp[i]){
                dp[i] = adj-c+a[i-1];
                cnt[i] = cntj+1;
            }
            mx = max(mx,{dp[i]-a[i-1],-cnt[i]});
            bst = max(bst,{dp[i],-cnt[i]});
        }
        bst.second *= -1;
        bst.first += c*bst.second;
        return bst;
    };
    /*
    for(int i = 0; i <= 10; i++){
        auto[res,cnt] = go(i);
        cout << i << ": " << cnt << " " << res << "\n";
    }*/
    int lo = 0, hi = 1e9; 
    while(lo < hi){
        int mid = (lo+hi)/2;
        auto[res,cnt] = go(mid);
        if(cnt <= k) hi = mid;
        else lo = mid+1;
    }
    cout << go(lo).first << "\n";
}
// dp[i] = max{mx[j]+psa[i]-psa[j]-c}
# Verdict Execution time Memory Grader output
1 Correct 99 ms 10044 KB Output is correct
2 Correct 105 ms 10220 KB Output is correct
3 Correct 97 ms 10396 KB Output is correct
4 Correct 99 ms 10296 KB Output is correct
5 Correct 99 ms 10176 KB Output is correct
6 Correct 108 ms 10004 KB Output is correct
7 Correct 103 ms 10012 KB Output is correct
8 Correct 95 ms 10256 KB Output is correct
9 Correct 99 ms 10152 KB Output is correct
10 Correct 118 ms 10144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 8640 KB Output is correct
2 Correct 94 ms 8576 KB Output is correct
3 Correct 91 ms 8396 KB Output is correct
4 Correct 80 ms 8480 KB Output is correct
5 Correct 96 ms 10140 KB Output is correct
6 Correct 96 ms 8392 KB Output is correct
7 Correct 86 ms 8616 KB Output is correct
8 Correct 102 ms 10264 KB Output is correct
9 Correct 99 ms 10000 KB Output is correct
10 Correct 92 ms 8636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 10432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 10044 KB Output is correct
2 Correct 105 ms 10220 KB Output is correct
3 Correct 97 ms 10396 KB Output is correct
4 Correct 99 ms 10296 KB Output is correct
5 Correct 99 ms 10176 KB Output is correct
6 Correct 108 ms 10004 KB Output is correct
7 Correct 103 ms 10012 KB Output is correct
8 Correct 95 ms 10256 KB Output is correct
9 Correct 99 ms 10152 KB Output is correct
10 Correct 118 ms 10144 KB Output is correct
11 Correct 95 ms 8640 KB Output is correct
12 Correct 94 ms 8576 KB Output is correct
13 Correct 91 ms 8396 KB Output is correct
14 Correct 80 ms 8480 KB Output is correct
15 Correct 96 ms 10140 KB Output is correct
16 Correct 96 ms 8392 KB Output is correct
17 Correct 86 ms 8616 KB Output is correct
18 Correct 102 ms 10264 KB Output is correct
19 Correct 99 ms 10000 KB Output is correct
20 Correct 92 ms 8636 KB Output is correct
21 Incorrect 154 ms 10432 KB Output isn't correct
22 Halted 0 ms 0 KB -