比赛 2022级DP专题练习赛6 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 珠宝 最终得分 100
用户昵称 yrtiop 运行时间 3.597 s
代码语言 C++ 内存使用 7.91 MiB
提交时间 2023-02-24 19:44:39
显示代码纯文本
// Problem: #6039. 「雅礼集训 2017 Day5」珠宝
// Contest: LibreOJ
// URL: https://loj.ac/p/6039
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb emplace_back
using i64 = long long;

const int N = 300;
const int M = 5e4;
int n,m,idx[M + 5],cnt;
i64 val[M + 5],f[M + 5],g[M + 5];
std::vector<int> G[N + 5];

int read() {
	int s = 0;
	char c = getchar();
	for(;c < '0'||c > '9';c = getchar());
	for(;c >= '0'&&c <= '9';c = getchar())
		s = (s << 1) + (s << 3) + (c ^ '0');
	return s;
}

void solve(int l,int r,int pl,int pr) {
	int mid = (l + r) >> 1,R = std::min(pr , mid),p = pl;
	for(int i = pl;i <= R;++ i) {
		i64 v = g[idx[i]] + val[mid - i];
		if(v > f[idx[mid]])
			p = i,f[idx[mid]] = v;
	}
	if(l < mid)
		solve(l , mid - 1 , pl , p);
	if(r > mid)
		solve(mid + 1 , r , p , pr);
	return ;
}

void calc(int x,int len) {
	cnt = 0;
	for(int i = 0;x + i * len <= m;++ i)
		idx[++ cnt] = x + i * len;
	solve(1 , cnt , 1 , cnt);
	return ;
}

int main() {
	freopen("zhubao.in","r",stdin);
	freopen("zhubao.out","w",stdout);
	n = read();
	m = read();
	for(int i = 1;i <= n;++ i) {
		int c = read(),v = read();
		G[c].pb(v);
	}
	for(int i = 1;i <= N;++ i) {
		if(G[i].empty())
			continue ;
		std::sort(G[i].begin() , G[i].end() , std::greater<int>());
		int par = m / i;
		val[0] = 0;
		for(int k = 1;k <= (int)G[i].size()&&k <= par;++ k)
			val[k] = val[k - 1] + (i64)G[i][k - 1];
		for(int k = G[i].size() + 1;k <= par;++ k)
			val[k] = val[k - 1];
		memcpy(g , f , sizeof(f));
		memset(f , 0 , sizeof(f));
		for(int k = 0;k < i&&k <= m;++ k)
			calc(k , i);
	}
	for(int i = 1;i <= m;++ i)
		printf("%lld ",f[i]);
	return 0;
}