zhanghaoyu1234567890 @ 2024-10-05 21:30:28
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,sum=0,a[1000001];
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
if(sum<k) cout<<0;
else{
long long l=sum/k;
long long ans=0;
for(int i=1;i<=n;i++) ans+=a[i]/l;
while(ans<k){
l--;
ans=0;
for(int i=1;i<=n;i++) ans+=a[i]/l;
}
cout<<l;
}
return 0;
}
by _Vistion_ @ 2024-10-05 21:46:42
这道题模板吧
#include <bits/stdc++.h>
#define int long long
using namespace std;
int arr[100001];
int solve(int n, int k){
int left=0, right=1e8+1, mid;
while(left+1<right){
mid=(left+right)/2;
int temp=0;
for(int i=1; i<=n; i++){
temp+=arr[i]/mid;
}
if(temp>=k) left=mid;
else right=mid;
}
return left;
}
signed main(){
int n,k;
cin>>n>>k;
for(int i=1; i<=n; i++)cin>>arr[i];
cout<<solve(n,k);
return 0;
}
by zhanghaoyu1234567890 @ 2024-10-05 21:53:00
@YZ_zhang 感谢,明白了