Submission #572186

# Submission time Handle Problem Language Result Execution time Memory
572186 2022-06-03T23:39:26 Z MODDI Feast (NOI19_feast) C++14
0 / 100
219 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][2500][2];
ll f(int at, int segments, int taken){
	if(at >= n)
		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);
	}
	memset(dp, -1, sizeof(dp));
	cout<<f(0, 0,0)<<endl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 219 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 155 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 218 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 219 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -