Submission #1288857

#TimeUsernameProblemLanguageResultExecution timeMemory
1288857red_soulsFeast (NOI19_feast)C++20
59 / 100
1098 ms68936 KiB
#include <bits/stdc++.h>
#define ll long long
#define task "Feast"
using namespace std;

const int N = 3e5 + 16;
const ll INF = 1e18;
int n, q;
ll a[N];

namespace sub6 {

    ll dp[2016][2016], prefix[N], maxx[2016][2016];

    void solve() {

        for (int i = 1; i <= n; i++) {
            prefix[i] = prefix[i - 1] + a[i];
        }
        for (int k = 1; k <= q; k++) {
            for (int i = 1; i <= n; i++) {
                maxx[k][i] = max(maxx[k][i - 1], dp[k - 1][i - 1] - prefix[i - 1]);
            }
            for (int i = 1; i <= n; i++) {
                dp[k][i] = max(dp[k][i], dp[k][i - 1]);
                dp[k][i] = max(dp[k][i], maxx[k][i] + prefix[i]);
            }
        }
        cout << dp[q][n];
    }
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }

    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sub6 :: solve();

    return 0;
}

Compilation message (stderr)

feast.cpp: In function 'int main()':
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(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...