Submission #1017406

# Submission time Handle Problem Language Result Execution time Memory
1017406 2024-07-09T07:47:33 Z vjudge1 Feast (NOI19_feast) C++17
12 / 100
66 ms 12124 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
pair<int, int> dp[300005][2];
int n, k, a[300005];
pair<int, int> sigma(int cost) {
    dp[0][1] = {-1e9, 0};
    for (int i = 1; i <= n; i++) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
        pair<int,int> v1 = {dp[i-1][1].first+a[i],dp[i-1][1].second};
        pair<int,int> v2 = {dp[i-1][0].first+a[i]-cost, dp[i-1][0].second+1};
        dp[i][1] = (v1.first > v2.first ? v1 : v2);
        //if(cost == 2) cout << i << ' ' << dp[i][0].first << ' ' << dp[i][0].second << ' ' << dp[i][1].first << ' ' << dp[i][1].second << '\n';
    }
    return max(dp[n][0], dp[n][1]);
}
void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int l = 0, r = 3e14, mid, ans=0;
    while(l <= r) {
        mid = (l + r) / 2;
        pair<int, int> val = sigma(mid);
        if(val.second <= k) {
           // cout << mid << ' ' << val.first << ' ' << val.second << '\n';
            ans = max(ans, val.first + mid * val.second);
            r = mid-1;
        }
        else l = mid+1;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen("input.inp","r")){
        freopen("input.inp", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
    }
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("input.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 11864 KB Output is correct
2 Correct 47 ms 11868 KB Output is correct
3 Correct 48 ms 12124 KB Output is correct
4 Correct 48 ms 11860 KB Output is correct
5 Correct 61 ms 11868 KB Output is correct
6 Correct 50 ms 11868 KB Output is correct
7 Correct 47 ms 11864 KB Output is correct
8 Correct 48 ms 11868 KB Output is correct
9 Correct 48 ms 11860 KB Output is correct
10 Correct 47 ms 11856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 11908 KB Output is correct
2 Correct 42 ms 12124 KB Output is correct
3 Correct 45 ms 11868 KB Output is correct
4 Correct 42 ms 11864 KB Output is correct
5 Correct 47 ms 11904 KB Output is correct
6 Correct 41 ms 11928 KB Output is correct
7 Correct 45 ms 12120 KB Output is correct
8 Correct 48 ms 12124 KB Output is correct
9 Correct 47 ms 11868 KB Output is correct
10 Correct 42 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 12068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 11864 KB Output is correct
2 Correct 47 ms 11868 KB Output is correct
3 Correct 48 ms 12124 KB Output is correct
4 Correct 48 ms 11860 KB Output is correct
5 Correct 61 ms 11868 KB Output is correct
6 Correct 50 ms 11868 KB Output is correct
7 Correct 47 ms 11864 KB Output is correct
8 Correct 48 ms 11868 KB Output is correct
9 Correct 48 ms 11860 KB Output is correct
10 Correct 47 ms 11856 KB Output is correct
11 Correct 43 ms 11908 KB Output is correct
12 Correct 42 ms 12124 KB Output is correct
13 Correct 45 ms 11868 KB Output is correct
14 Correct 42 ms 11864 KB Output is correct
15 Correct 47 ms 11904 KB Output is correct
16 Correct 41 ms 11928 KB Output is correct
17 Correct 45 ms 12120 KB Output is correct
18 Correct 48 ms 12124 KB Output is correct
19 Correct 47 ms 11868 KB Output is correct
20 Correct 42 ms 12124 KB Output is correct
21 Incorrect 66 ms 12068 KB Output isn't correct
22 Halted 0 ms 0 KB -