# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237703 | 2020-06-08T11:31:39 Z | Half | Feast (NOI19_feast) | C++14 | 57 ms | 63992 KB |
#include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmath> using namespace std; typedef vector<int> vi; typedef pair<int,int> pi; typedef long long ll; #define loop(i,a,b) for (int i = a; i <= b; i++) #define INF ((unsigned) ~0) #define F first #define S second #define PB push_back #define MP make_pair const int MXN = 2000; int N, K; int a[MXN]; vi g; vector<ll> sg; ll mem[MXN][MXN]; int dp(int l, int n){ if(l >= g.size()) return 0; if(n <= 0) return 0; if(mem[l][n] != -1) return mem[l][n]; ll sol = sg[l + 1] - sg[l]; for(int i = l + 1; i <= g.size(); i++) for(int j = l; j <= i; j++) sol = max(sol, dp(i, n - 1) + sg[i] - sg[j]); mem[l][n] = sol; return sol; } int main(){ cin >> N >> K; for(int i = 0; i < N; i++){ cin >> a[i]; if(g.size() == 0){ g.push_back(a[i]); }else if((g[g.size() - 1] > 0 && a[i] > 0) || (g[g.size() - 1] < 0 && a[i] < 0)){ g[g.size() - 1] += a[i]; }else{ //cout << g[g.size() - 1] << " "; g.push_back(a[i]); } } //cout << "\n"; for(int i = 0; i < MXN; i++) for(int j = 0; j < MXN; j++) mem[i][j] = -1; ll sm = 0; sg.push_back(0); for(int i = 0; i < g.size(); i++){ sm += g[i]; sg.push_back(sm); } cout << dp(0, K) << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 512 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 | Incorrect | 21 ms | 31616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 57 ms | 63992 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 | Incorrect | 20 ms | 31616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 31616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 31616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |