Submission #969925

#TimeUsernameProblemLanguageResultExecution timeMemory
969925blackslexFeast (NOI19_feast)C++17
21 / 100
1008 ms262144 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int n, k; int main() { scanf("%d %d", &n, &k); vector<ll> a(n + 5), pref(n + 5); vector<vector<ll>> dp(k + 5, vector<ll>(n + 5)), dp2(n + 5, vector<ll>(n + 5, -1e18)); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i]; for (int i = 0; i <= n; i++) { dp2[i][i] = pref[i]; for (int j = i + 1; j <= n; j++) dp2[i][j] = max(dp2[i][j - 1], pref[j]); } for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { for (int l = 0; l <= j; l++) dp[i][j] = max(dp[i][j], dp[i - 1][l] + dp2[l][j] - pref[l]); } } printf("%lld", *max_element(dp[k].begin(), dp[k].end())); }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
feast.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i];
      |                                  ~~~~~^~~~~~~~~~~~~~~
#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...