标签:
2 7
200000
500000
100000
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 1000005; int n,m,a[maxn]; bool check(int t){ int ans = 0,tmp; for(int i = 1;i <= n;i++){ tmp = a[i] / t; if(tmp * t < a[i]) tmp++; ans += tmp; if(ans > m) return false; } return true; } int main(){ cin>>n>>m; int l = 0,r = 0,mid,ans; for(int i = 1;i <= n;i++){ scanf("%d",&a[i]); if(a[i] > r) r = a[i]; } while(l <= r){ mid = (l + r) >> 1; if(check(mid)){ ans = mid; r = mid - 1; }else{ l = mid + 1; } } cout<<ans; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5791429.html