专栏文章
题解:P12966 [CCO 2025] Asteroid Mining
P12966题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mincrlp2
- 此快照首次捕获于
- 2025/12/02 00:17 3 个月前
- 此快照最后确认于
- 2025/12/02 00:17 3 个月前
在此点名表扬mx高素质出题人。
vp了一场模拟赛,大概就是放在了T2然后写了2h过了。
观察性质:由于对于任意,都有或,那么可以知道其的值最多有个。
因此可以考虑以每个值域为转移,做那种类似的那种操作,把同层级的贡献算出来,然后向更高的值域转移。
code:
CPP#include<bits/stdc++.h>
using namespace std;
const int N=5e5 + 5;
#define int long long
int n,m,ans,b[N],tot,cnt,c[N];
struct node{
int w,v;
}e[N];
bool cmp1(int s1,int s2){
return s1>s2;
}
void solve(int x,int gx){
cnt=(m%gx)/x;
m-=cnt*x;
sort(b+1,b+tot+1);
for(int i=tot;i>=max(1ll,tot-cnt+1);--i){
ans+=b[i];
}
tot=max(0ll,tot-cnt);
if(!tot){
return ;
}
int kk=gx/x;
sort(b+1,b+tot+1,cmp1);
for(int i=1;i<=tot;++i){
c[i]=0;
}
for(int i=1;i<=tot;++i){
c[(i-1)/kk+1]+=b[i];
}
tot=(tot-1)/kk+1;
for(int i=1;i<=tot;++i){
b[i]=c[i];
}
}
bool cmp(node s1,node s2){
if(s1.w==s2.w){
return s1.v>s2.v;
}
return s1.w<s2.w;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i){
cin>>e[i].v>>e[i].w;
}
sort(e+1,e+n+1,cmp);
int cur=e[1].w;
for(int i=1;i<=n;++i){
if(e[i].w!=cur){
solve(cur,e[i].w);
cur=e[i].w;
}
b[++tot]=e[i].v;
}
sort(b+1,b+tot+1);
m/=e[n].w;
for(int i=tot;i>=max(tot-m+1,1ll);--i){
ans+=b[i];
}
cout<<ans<<'\n';
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...