比赛 202103省实验桐柏一中普及组联赛 评测结果 AAAAAAAAAA
题目名称 自助者天助 最终得分 100
用户昵称 tb_PYD1 运行时间 0.231 s
代码语言 C++ 内存使用 4.14 MiB
提交时间 2021-03-22 18:10:17
显示代码纯文本
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

inline int max(int a,int b) {return a > b ? a : b;}

inline int read(){
	int t = 0,flag = 1;
	register char c = getchar();
	while (c < 48 || c > 57) flag = (c == '-') ? (-1) : (flag),c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return flag * t;
}

int n,m,w,v,wmax,vmax,num[1001][1001],ans,f[30001];

int main(){
	freopen("delicious.in","r",stdin);
	freopen("delicious.out","w",stdout);
	n = read(),m = read();
	for (int i = 1;i <= n;i++) w = read(),v = read(),++num[w][v],wmax = max(wmax,w),vmax = max(vmax,v);
	for (int w = 1;w <= wmax;w++){
		for (int v = 1;v <= vmax;v++){
			if (!num[w][v]) continue;
			for (int k = 0;(1 << k) <= num[w][v];k++){
				int temp = (1 << k);
				num[w][v] -= temp;
				for (int j = m;j >= temp * w;j--) f[j] = max(f[j],f[j - temp * w] + temp * v);
			}
			if (num[w][v]){
				for (int j = m;j >= num[w][v] * w;j--) f[j] = max(f[j],f[j - num[w][v] * w] + num[w][v] * v);
			}
		}
	}
	for (int i = 0;i <= m;i++) ans = max(ans,f[i]);
	printf("%d\n",ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}