Submission #8523821


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	int MW; cin >> MW;
	int W0;
	vector<vector<int>> dp(N+1, vector<int>(3*N+1));
	for (int i = 0; i < N; i++) {
		int w, v; cin >> w >> v;
		if (i == 0) W0 = w;
		assert(W0 <= w && w <= W0 + 3);
		w -= W0;
		for (int c = i; c >= 0; c--) {
			for (int t = 0; t <= 3 * i; t++) {
				dp[c+1][t+w] = max(dp[c+1][t+w], dp[c][t] + v);
			}
		}
	}
	int ans = 0;
	for (int c = 0; c <= N; c++) {
		for (int t = 0; t <= 3 * N; t++) {
			if (1ll * W0 * c + t <= MW) {
				ans = max(ans, dp[c][t]);
			}
		}
	}
	cout << ans << '\n';

	return 0;
}

Submission Info

Submission Time
Task D - Simple Knapsack
User ecnerwala
Language C++14 (GCC 5.4.1)
Score 400
Code Size 698 Byte
Status AC
Exec Time 3 ms
Memory 384 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 384 KB
antigreedy1 AC 3 ms 384 KB
antigreedy2 AC 3 ms 384 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 384 KB
quarter1 AC 3 ms 384 KB
quarter2 AC 3 ms 384 KB
rand0 AC 3 ms 384 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB
smallw0 AC 3 ms 384 KB
smallw1 AC 3 ms 384 KB
smallw2 AC 3 ms 384 KB