View Code of Problem 4041

# include<stdio.h>
# include <string.h>
int dp[310]={0};
int time[310]={0},value[310]={0};
int n,m;
int max(int a,int b)
{
	return a<b?b:a;
}
 
void go(int time,int value){
	for(int i = m; i >=time; i--){
		dp[i] = max(dp[i], dp[i - time] + value);
	}
}
 
int main(){
		scanf("%d%d",&n,&m);
		for(int i = 0; i < n; i++){
			scanf("%d%d",&time[i],&value[i]);
		}
		for(int i = 0; i < n; i++){
			go(time[i],value[i]);
		}
		printf("%d\n",dp[m]);
	
	return 0;
} 

Double click to view unformatted code.


Back to problem 4041