https://old.ynoip.cn/p/3011

psn  •  1年前


#include <cstdio>
using namespace std;
int num[100005][2];
int maps[2][1000000];

int main(void) {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &num[i][0]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &num[i][1]);
	for (int i = 1; i <= n; i++) {
		for (int u = num[i][0]; u <= m; u++)
			if (num[i][1] + maps[0][u - num[i][0]] > maps[0][u])
				maps[1][u] = num[i][1] + maps[0][u - num[i][0]];
			else
				maps[1][u] = maps[0][u];
		for (int y = 0; y <= m; y++)
			maps[0][y] = maps[1][y];
	}
	printf("%d", maps[1][m]);
	return 0;
}

评论:

请先登录,才能进行评论