题目大意:有n种牌,第i种牌的数目为c[i]。另外有m张王牌,每套牌可以使用1张。求最多组成多少套牌
题解:二分比较显然
我的收获:…………
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int M=55;
int n,m,mx,w[M];
bool ok(int x){
long long tot=0;//惨痛的教训
for(int i=1;i<=n;i++)
tot+=max(0,x-w[i]);
return tot<=min(m,x);//1套牌只能用1张王
}
void work()
{
int l=0,r=1000000000,mid,ans;
while(l<=r){
mid=(l+r)>>1;
if(ok(mid)) ans=mid,l=mid+1;
else r=mid-1;
}
cout<<ans<<endl;
}
void init()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
scanf("%d",&w[i]),mx=max(mx,w[i]);
}
int main()
{
init();
work();
return 0;
}