一直WA
by JimmyFlower @ 2024-07-24 01:23:44
B1的代码是这样:
```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ri register int
using namespace std;
typedef long long ll;
const int N=200010;
int T;
ll n,m,t,ans,a[N];
struct node{ll x,tot;}b[N];
void solve()
{
scanf("%lld %lld",&n,&m);
for(ri i=1;i<=n;i++) scanf("%lld",&a[i]);
sort(a+1,a+n+1);
b[1].x=a[1],b[1].tot=1,t=1;
for(ri i=2;i<=n;i++)
if(a[i]==a[i-1]) b[t].tot++;
else t++,b[t].x=a[i],b[t].tot=1;
ans=0;
for(ri i=t-1;i>=1;i--)
if(b[i+1].x-b[i].x==1)
{
ll t1=min(m/b[i].x,b[i].tot),t2=min(m/b[i+1].x,b[i+1].tot);//t1=3 t2=4
if(b[i].x*t1+b[i+1].x*t2<=m) ans=max(ans,b[i].x*t1+b[i+1].x*t2);
else
{
ll x1=m-b[i].x*t1,x2=m-b[i+1].x*t2;
ans=max(ans,b[i].x*t1+min(x1/b[i+1].x,b[i+1].tot)*b[i+1].x);
ans=max(ans,b[i+1].x*t2+min(x2/b[i].x,b[i].tot)*b[i].x);
if(t1)
ans=max(ans,b[i].x*(t1-1)+min((x1+b[i].x)/b[i+1].x,b[i+1].tot)*b[i+1].x);
if(t2)
ans=max(ans,b[i+1].x*(t2-1)+min((x2+b[i+1].x)/b[i].x,b[i].tot)*b[i].x);
}
}
for(ri i=1;i<=t;i++) ans=max(ans,min(m/b[i].x,b[i].tot)*b[i].x);
printf("%lld\n",ans);
}
int main()
{
scanf("%d",&T);
while(T--) solve();
return 0;
}
```
by JimmyFlower @ 2024-07-24 01:31:38