Submission #1320965

#TimeUsernameProblemLanguageResultExecution timeMemory
1320965tolgaFeast (NOI19_feast)C++20
41 / 100
171 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  vector<vector<array<ll, 2>>> dp(n + 1, vector<array<ll, 2>>(n + 1));
  // dp[i][j][0/1] = upto i with j subarrays
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j][1]);
      dp[i][j][1] = max(dp[i - 1][j - 1][0], dp[i - 1][j][1]) + a[i - 1];
    }
  }

  ll ans = 0;
  for (int j = 1; j <= k; j++)
    ans = max({ans, dp[n][j][0], dp[n][j][1]});
  cout << ans << endl;
}
#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...