phr0720 @ 2024-08-28 16:39:35
#include<bits/stdc++.h>
using namespace std;
long long h[1000005];
long long n,k;
bool check(long long x) {
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans += h[i] / x;
}
return ans >= k;
}
int main() {
cin>>n>>k;
for(int i=1; i<=n; i++) {
cin>>h[i];
}
long long mid;
long long l=1,r=100000001;
while(l+1<r) {
mid=(l+r)/2;
if(check(mid))l=mid;
else {
r=mid;
}
}
cout<<l;
return 0;
}
by meifan666 @ 2024-08-28 16:44:20
@phr0720 首先,第一个for里加
sum+=a[i];
然后下一行加
if(sumt<k){
cout<<0;
return 0;
}
by meifan666 @ 2024-08-28 16:44:44
其他的再说,我的88就因为这个
by Yxy7952 @ 2024-08-28 16:46:53
@phr0720
#include<bits/stdc++.h>
using namespace std;
long long h[1000005];
long long n,k,sum;
bool check(long long x) {
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans += h[i] / x;
}
return ans >= k;
}
int main() {
cin>>n>>k;
for(int i=1; i<=n; i++) {
cin>>h[i];
}
long long mid;
long long l=1,r=100000001;
while(l<=r) {
mid=(l+r)/2;
if(check(mid)){
l=mid+1;
sum=mid;
}
else {
r=mid-1;
}
}
cout<<sum;
return 0;
}
by phr0720 @ 2024-08-29 08:41:08
@yixingyou,@meifan666,感谢两位大佬,此题已过,谢谢,此帖结。