Submission #572188

# Submission time Handle Problem Language Result Execution time Memory
572188 2022-06-03T23:42:02 Z MODDI Feast (NOI19_feast) C++14
0 / 100
146 ms 262144 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n, k;
vi arr;
ll dp[10000][10000][2];
ll f(int at, int segments, int taken){
	if(at >= n)
		return 0;
	if(segments > k)
		return 0;
	if(dp[at][segments][taken] != -1)
		return dp[at][segments][taken];
		
	ll best = 0;
	best = max(best, arr[at] + f(at + 1, segments, 1));
	if(taken == 0)
		best = max(best, f(at + 1, segments, 0));
	if(segments + 1 < k && taken == 1)
		best = max(best, f(at + 1, segments + 1, 0));
	return dp[at][segments][taken] = best;
}
int main(){
	cin>>n>>k;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		arr.pb(a);
	}
	if(n > 2500 || k > 2500)
	{
		cout<<-1<<endl;
		return 0;
	}
	memset(dp, -1, sizeof(dp));
	cout<<f(0, 0,0)<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 2456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 2524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 2456 KB Output isn't correct
2 Halted 0 ms 0 KB -