比赛 2022级DP专题练习赛6 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 珠宝 最终得分 100
用户昵称 op_组撒头屯 运行时间 9.038 s
代码语言 C++ 内存使用 123.11 MiB
提交时间 2023-02-24 18:21:22
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=1000000+5;
const int M=50000+5;
const int C=300+5;
const ll inf=0x3f3f3f3f3f3f;
int n,m,mxc;
vi v[C];
vector<ll>sum[C];
ll f[C][M];
bool cmp(int x,int y){
    return x>y;
}
inline int read(){
    int ans=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
} 
inline void write(ll x){
    if (x>9)write(x/10);
    putchar('0'+x%10);
}
int id[M],tot=0;
inline ll calc(int len,int l,int r){
    int cnt=(r-l)/len;
    if (cnt>v[len].size())return -inf;
    return f[len-1][l]+sum[len][cnt];
}
void solve(int len,int l,int r,int L,int R){
    if (l>r)return ;
    int mid=(l+r)/2,pos=0;ll val=0,mx=0;
    for (int i=L;i<=min(R,mid);i++){
        val=calc(len,id[i],id[mid]);
        if (val>mx)mx=val,pos=i;
    }
    if (l==r){
        f[len][id[l]]=mx;return ;
    }
    f[len][id[mid]]=mx;
    solve(len,l,mid-1,L,pos);
    solve(len,mid+1,r,pos,R);
}
int main(){
	freopen ("zhubao.in","r",stdin);
	freopen ("zhubao.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
	    int x=read(),y=read();
	    v[x].pb(y);mxc=max(mxc,x);
    }
    for (int i=1;i<=mxc;i++)if (v[i].size()>1)sort(v[i].begin(),v[i].end(),cmp);
    sum[0].pb(0);
    for (int i=1;i<=mxc;i++){
        sum[i].pb(0);
        if (!v[i].size())continue;
        ll now=0;
        for (int j=0;j<v[i].size();j++){
            now+=v[i][j];sum[i].pb(now);
        }
    }
    for (int i=1;i<=mxc;i++){
        for (int j=0;j<i;j++){
            tot=1;id[tot]=j;
            while(id[tot]+i<=m)id[tot+1]=id[tot]+i,tot++;
            solve(i,1,tot,1,tot);
        }
    }
    for (int i=1;i<=m;i++)write(f[mxc][i]),putchar(' ');
    return 0;
}