Submission #1104210

# Submission time Handle Problem Language Result Execution time Memory
1104210 2024-10-23T08:59:28 Z nasir_bashirov Feast (NOI19_feast) C++11
18 / 100
150 ms 12112 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define db long double
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long

const int sz = 3e5 + 5;
int n, k, a[sz];
pii dp[sz][2];

void calc(int mid){
    dp[1][0] = {0, 0}, dp[1][1] = {a[1] - mid, 1};
    for(int i = 2; i <= n; i++){
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = max(make_pair(dp[i - 1][0].first + a[i] - mid, dp[i - 1][0].second + 1), make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second));
    }
}

void fmain(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int l = 0, r = 1e15, res = 0;
    while(l <= r){
        int mid = (l + r) / 2;
        calc(mid);
        if(max(dp[n][0], dp[n][1]).second >= k){
            l = mid + 1;
            if(dp[n][0].second == k)    res = max(res, dp[n][0].first + k * mid);
            if(dp[n][1].second == k)    res = max(res, dp[n][1].first + k * mid);
        } 
        else{
            r = mid - 1;
        }
    }
    cout << res;
}

signed main(){
    int tmr = 1;
    //cin >> tmr;
    while(tmr--){
        fmain();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 11848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 12112 KB Output is correct
2 Correct 89 ms 12104 KB Output is correct
3 Correct 64 ms 11960 KB Output is correct
4 Incorrect 63 ms 12108 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 126 ms 12112 KB Output is correct
2 Correct 118 ms 12104 KB Output is correct
3 Correct 132 ms 11960 KB Output is correct
4 Correct 149 ms 12104 KB Output is correct
5 Correct 118 ms 12104 KB Output is correct
6 Correct 124 ms 11960 KB Output is correct
7 Correct 150 ms 11960 KB Output is correct
8 Correct 118 ms 12104 KB Output is correct
9 Correct 121 ms 11952 KB Output is correct
10 Correct 131 ms 11956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 11848 KB Output isn't correct
2 Halted 0 ms 0 KB -