cyb89 @ 2024-08-16 18:00:34
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;int sum=0;
const int maxn=1e7+10;
int a[maxn];
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
if(sum<m)
{
cout<<0;
return 0;
}
int l=0,r=sum/m;
int mid;
while(l+1<r)
{
mid=(l+r)/2;
int ans=0;
for (int i=1;i<=n;i++)
{
ans+=a[i]/mid;
}
if(ans>=m)l=mid;
else
{
r=mid;
}
}
cout<<l;
}
by _lxc__ @ 2024-08-16 18:53:31
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,a[N],k;
bool chk(int mid){
int sum=0;
for(int i=1;i<=n;i++){
sum+=a[i]/mid;
}
return sum>=k;
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
long long l=1,r=1e8,ans=0;
while(l<=r){
int m=(l+r)/2;
if(chk(m)){
ans=m;
l=m+1;
}
else{
r=m-1;
}
}
cout<<ans;
return 0;
}
by hehe_666 @ 2024-09-08 09:34:33
@cyb89
#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[1000005];
bool check(int x)
{
long long sum = 0;
for(int i = 1; i <= n; i++)
{
if(l[i] >= x)
{
sum += l[i] / x;
}
}
if(sum >= m) return true;
return false;
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> l[i];
int l = 1, r = 1e9, ans = 0;
while(l <= r)
{
int mid = (l + r) / 2;
if(check(mid) == true)
{
l = mid + 1;
ans = mid;
}
else
{
r = mid - 1;
}
}
cout << ans << endl;
return 0;
}