华华给月月准备礼物
华华给月月准备礼物
https://ac.nowcoder.com/acm/problem/23049
前言:
真就一眼题.
思路:
二分即可.
代码:
#include <bit.stdc++.h>
using namespace std;
const int N=2e5+50;
int w[N],n,m;
bool check(int len)
{
int sum=0;
if(len==0) return true;
for(int i=1;i<=n;i++)
{
sum+=w[i]/len;
}return sum>=m;
}
int main()
{
int ans=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&w[i]);
int l=0,r=1e9;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid))
{
ans=max(ans,mid);
l=mid+1;
}
else r=mid-1;
}printf("%d\n",ans);
return 0;
}lpt的小屋 文章被收录于专栏
我想要一份甜甜的爱情
SHEIN希音公司福利 280人发布