| 比赛 |
2026.9.5 |
评测结果 |
AAWWWWEEEEEWEEEEEEAAAAAAE |
| 题目名称 |
Asteroid Mining |
最终得分 |
32 |
| 用户昵称 |
VTXE |
运行时间 |
3.948 s |
| 代码语言 |
C++ |
内存使用 |
7.35 MiB |
| 提交时间 |
2026-09-05 11:01:56 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
ll v,w;
}t[510000];
ll n,m;
ll f[11000];
ll a[510000],b[510000];
ll w1,w2;
bool c1=1,c2;
ll tot,cnt=1,lt;
bool cmp(node aa,node bb){
if (aa.w==bb.w) return aa.v>bb.v;
return aa.w<bb.w;
}
int main(){
freopen("Mining.in","r",stdin);
freopen("Mining.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for (int i=1;i<=n;i++){
cin>>t[i].v>>t[i].w;
}
sort(t+1,t+n+1,cmp);
for (int i=2;i<=n;i++){
if (t[i].w!=t[i-1].w){
c1=0;
cnt++;
tot=i-1;
}
}
if (cnt==2) c2=1;
if (c1){
ll cnt=1,ans=0;
while (m>t[cnt].w){
ans+=t[cnt].v;
m-=t[cnt].w;
cnt++;
}
cout<<ans<<'\n';
}else if (c2){
w1=t[1].w;
w2=t[tot+1].w;
for (int i=1;i<=tot;i++){
a[i]+=t[i].v;
}
for (int i=tot+1;i<=n;i++){
b[i]+=t[i].v;
}
cnt=m/w1;
ll ans=0;
for (int i=cnt;i>=0;i--){
lt=(m-i*w1)/w2;
ans=max(ans,a[i]+b[lt]);
}
cout<<ans<<'\n';
}else{
for (int i=1;i<=n;i++){
for (int j=m;j>=t[i].w;j--){
f[j]=max(f[j],f[j-t[i].w]+t[i].v);
}
}
cout<<f[m];
}
return 0;
}