Submission #994478

# Submission time Handle Problem Language Result Execution time Memory
994478 2024-06-07T17:08:42 Z idiotcomputer Feast (NOI19_feast) C++11
4 / 100
81 ms 1628 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<ll,ll>
#define f first
#define s second

const int mxN = 3e5;
int n,k;
int a[mxN];

pii test(ll v){
    pii dp[2];
    pii dp2[2];
    dp[0] = {0,0};
    dp[1] = {0,0};
    for (int i = 0; i < n; i++){
        dp2[0] = max(dp[0],(pii){dp[1].f-v,dp[1].s+1});
        dp2[1] = max((pii) {dp[0].f+a[i],dp[0].s}, (pii) {dp[1].f+a[i],dp[1].s});
        swap(dp2,dp);
    }
    dp[1] = (pii) {dp[1].f-v,dp[1].s+1};
    return max(dp[0],dp[1]);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    
    ll l = -1;
    ll r = 1e15;
    ll c;
    while (r-l>1){
        c = (l+r)/2;
        if(test(c).s<=k) r = c;
        else l = c;
    }
    pii t = test(r);
 //   cout << r << " -=  " << t.f << " " << t.s << '\n';
    cout << t.f - (t.s-k)*r << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1372 KB Output is correct
2 Correct 36 ms 1528 KB Output is correct
3 Correct 39 ms 1628 KB Output is correct
4 Correct 34 ms 1536 KB Output is correct
5 Correct 49 ms 1368 KB Output is correct
6 Correct 34 ms 1372 KB Output is correct
7 Correct 33 ms 1368 KB Output is correct
8 Correct 35 ms 1368 KB Output is correct
9 Correct 35 ms 1512 KB Output is correct
10 Correct 35 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1372 KB Output is correct
2 Correct 36 ms 1528 KB Output is correct
3 Correct 39 ms 1628 KB Output is correct
4 Correct 34 ms 1536 KB Output is correct
5 Correct 49 ms 1368 KB Output is correct
6 Correct 34 ms 1372 KB Output is correct
7 Correct 33 ms 1368 KB Output is correct
8 Correct 35 ms 1368 KB Output is correct
9 Correct 35 ms 1512 KB Output is correct
10 Correct 35 ms 1372 KB Output is correct
11 Incorrect 34 ms 1368 KB Output isn't correct
12 Halted 0 ms 0 KB -