Submission #1288509

#TimeUsernameProblemLanguageResultExecution timeMemory
1288509LIATricks of the Trade (CEOI23_trade)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define tp tuple<ll, ll, ll>
const ll inf = 1e18;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll n, k, ans = -1e18;
  cin >> n >> k;
  vll b(n), s(n);
  for (ll i = 0; i < n; ++i)
    cin >> b[i];
  for (ll i = 0; i < n; ++i)
    cin >> s[i];

  vector<vll> dp(n + 1, vll(k + 1, -inf));

  for (ll j = 0; j <= k; ++j)
    dp[0][j] = 0;

  for (ll j = 1; j <= k; ++j) {
    vll pref(n + 1, 0);
    set<ll> st;
    st.insert(-dp[0][j - 1]);
    for (ll i = 1; i <= n; ++i) {
      ll cost = b[i - 1], prof = s[i - 1];
      pref[i] = pref[i - 1] + cost;
      dp[i][j] = prof - pref[i] - *st.begin();
      st.insert(-dp[i][j - 1] + pref[i]);
    }
  }
  for (ll i = 1; i <= n; ++i)
    ans = max(ans, dp[i][k]);

  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...