solution
其实就是要求一个最大的x使得。
显然当x增大时答案会变小,具有单调性,所以考虑二分答案。
二分一个x,检查答案是否大于等于K即可。
code
/* * @Author: wxyww * @Date: 2020-04-16 11:12:25 * @Last Modified time: 2020-04-16 11:15:09 */ #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<ctime> using namespace std; typedef long long ll; const int N = 200010; ll read() { ll x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } int n,a[N]; int check(int x) { int ret = 0; for(int i = 1;i <= n;++i) ret += a[i] / x; return ret; } int main() { n = read();int K = read(); for(int i = 1;i <= n;++i) a[i] = read(); int l = 1,ans = 0,r = 1e9; while(l <= r) { int mid = (l + r) >> 1; if(check(mid) >= K) ans = mid,l = mid + 1; else r = mid - 1; } cout<<ans; return 0; }