| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAWWWWWAWWWWWWAAAAAAW |
| 题目名称 |
Asteroid Mining |
最终得分 |
52 |
| 用户昵称 |
PXCZM |
运行时间 |
2.704 s |
| 代码语言 |
C++ |
内存使用 |
7.02 MiB |
| 提交时间 |
2026-09-05 11:57:02 |
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
pair<ll,ll>a[500010];
ll dp[10010];
void solve1()
{
for(int i=1;i<=n;i++)
for(int j=m;j>=a[i].first;j--)
dp[j]=max(dp[j],dp[j-a[i].first]+a[i].second);
cout<<dp[m]<<'\n';
}
void solve2()
{
ll num=m/a[1].first,res=0;
for(int i=n;i>=max(n-num+1,1LL);i--) res+=a[i].second;
cout<<res<<'\n';
}
void solve3()
{
int pos,_pos;
for(int i=1;i<=n;i++)
if(a[i].first!=a[1].first)
{
_pos=pos=i-1;
break;
}
ll now=0,val=0,res=0;
while(pos&&now+a[pos].first<=m)
{
now+=a[pos].first;
val+=a[pos].second;
pos--;
}
res=val;
for(int i=n;i>_pos;i--)
{
now+=a[i].first; val+=a[i].second;
while(pos!=_pos&&now>m)
{
pos++;
now-=a[pos].first;
val-=a[pos].second;
}
if(now>m) break;
res=max(res,val);
}
cout<<res<<'\n';
}
bool cmp(const pair<ll,ll>& s1,const pair<ll,ll>& s2)
{
if(s1.second!=s2.second) return s1.second>s2.second;
else return s1.first<s2.first;
}
int main()
{
freopen("Mining.in","r",stdin);
freopen("Mining.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i].second>>a[i].first;
if(m<=1e4&&n<=1e3)
{
solve1();
return 0;
}
sort(a+1,a+1+n);
if(a[1].first==a[n].first)
{
solve2();
return 0;
}
if(lower_bound(a+1,a+1+n,make_pair(a[1].first+1,0LL))->first==a[n].first)
{
solve3();
return 0;
}
sort(a+1,a+1+n,cmp);
ll res=0,now=0;
for(int i=1;i<=n;i++)
{
if(a[i].first+now<=m)
{
now+=a[i].first;
res+=a[i].second;
}
}
cout<<res<<'\n';
return 0;
}