Submission #16609578


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;;

int main(){

	long long n,w;
	cin>>n>>w;
	
	long long berat[n],value[n];
	
	for (long long i=1;i<=n;i++){
		cin>>berat[i]>>value[i];
	}
	
	long long dp[n+1][w+1];
	
	memset(dp,0,sizeof dp);
	
	for (long long i=1;i<=n;i++){
		for (long long j=0;j<=w;j++){
			dp[i][j]=dp[i-1][j];
			if (j-berat[i]>=0){
				dp[i][j]=max(dp[i][j],dp[i-1][j-berat[i]]+value[i]);
			}
		}
	}

	cout<<dp[n][w]<<endl;

	return 0;
}

Submission Info

Submission Time
Task D - Knapsack 1
User nur47
Language C++ (GCC 9.2.1)
Score 100
Code Size 490 Byte
Status AC
Exec Time 74 ms
Memory 82272 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 13
Set Name Test Cases
All 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09
Case Name Status Exec Time Memory
0_00 AC 8 ms 3504 KB
0_01 AC 2 ms 3496 KB
0_02 AC 2 ms 3612 KB
1_00 AC 5 ms 5116 KB
1_01 AC 66 ms 82272 KB
1_02 AC 69 ms 79484 KB
1_03 AC 67 ms 81296 KB
1_04 AC 62 ms 81140 KB
1_05 AC 70 ms 81180 KB
1_06 AC 69 ms 82104 KB
1_07 AC 74 ms 81348 KB
1_08 AC 67 ms 81080 KB
1_09 AC 70 ms 82120 KB