Submission #3216449


Source Code Expand

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=100;
ll dp[MAX_N+1][MAX_N*3+1];
int N;
ll W,w[MAX_N],v[MAX_N];
int main(){
	cin>>N>>W;
	REP(i,N){
		cin>>w[i]>>v[i];
	}
	REP(i,N){
		for(int n=i+1;n>=1;n--){
			REP(j,3*N+1){
				if (j-(w[i]-w[0])>=0){
					dp[n][j]=max(dp[n][j],dp[n-1][j-(w[i]-w[0])]+v[i]);
				}
			}
		}
	}
	ll ans=0;
	REP(i,N){
		REP(j,3*N+1){
			if ((i+1)*w[0]+j<=W){
				ans=max(ans,dp[i+1][j]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - Simple Knapsack
User addeight
Language C++14 (GCC 5.4.1)
Score 400
Code Size 603 Byte
Status AC
Exec Time 3 ms
Memory 512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 16
Set Name Test Cases
Sample example0, example1, example2, example3
All antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2
Case Name Status Exec Time Memory
antigreedy0 AC 3 ms 512 KB
antigreedy1 AC 3 ms 512 KB
antigreedy2 AC 3 ms 512 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
example3 AC 1 ms 256 KB
quarter0 AC 3 ms 512 KB
quarter1 AC 3 ms 512 KB
quarter2 AC 3 ms 512 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 384 KB
rand2 AC 1 ms 256 KB
smallw0 AC 3 ms 512 KB
smallw1 AC 3 ms 512 KB
smallw2 AC 3 ms 512 KB