PS: 最小值最大化,二分。省賽熱身。
#include#include #include #include #include #include using namespace std; int n, m; vector v; int maxv; bool ok(int d) { int last = 0, cur = last+1; for(int i = 1; i < m; i++) { while(cur =n) return false; last = cur; } return true; } int work() { sort(v.begin(), v.end()); int l = 0, r = maxv; int mid; while(r-l>1) { mid = (l+r)/2; if(ok(mid)) l = mid; else r = mid; } return l; } int main() { int x; while(scanf("%d%d", &n, &m)!=EOF) { v.clear(); maxv = 0; for(int i = 0; i < n; i++) { scanf("%d", &x); v.push_back(x); maxv = max(maxv, x); } int res = work(); printf("%d\n", res); } return 0; }