Submission #237744

# Submission time Handle Problem Language Result Execution time Memory
237744 2020-06-08T14:52:31 Z Haunted_Cpp Feast (NOI19_feast) C++17
0 / 100
99 ms 37244 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2005;
bool calc [N][N][2];
long long dp [N][N][2];
long long arr [N];

int n, k;

long long solve (int p, int box, bool is) {

  if (box < 0) return -1e18;  
  if (p >= n) return (box == 0 ? 0 : -1e18);
  if (calc[p][box][is]) return dp[p][box][is];
  
  long long &res = dp[p][box][is];
  calc[p][box][is] = true;
  
  res = -1e15;
  
  if (!is) {
    res = max (res, solve (p + 1, box, false) );
    res = max (res, solve (p + 1, box - 1, true) + arr[p]);
  } else {
    res = max (res, solve (p + 1, box, true) + arr[p]);
    res = max (res, solve (p + 1, box, false) );
  }

  return res;
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset (calc, false, sizeof(calc));
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << max (0LL, solve (0, k, false) ) << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 91 ms 37240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 71 ms 37164 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 99 ms 37244 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Incorrect 11 ms 8576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Incorrect 11 ms 8576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Incorrect 11 ms 8576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 91 ms 37240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -