boolcheck(int mid){ int start = a[1], cnt = 0; for (int i = 2; i <= n; i++) { cnt += 1; i = lower_bound(a + 1, a + n + 1, start + mid) - a; start = a[i]; } return cnt >= m; }
intmain(){ cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); r = a[n] + 1; while (r - l > 1) { int mid = (l + r) / 2; if (check(mid)) { l = mid; } else { r = mid; } } cout << l; }
boolcheck(int x){ int cnt = 0, start = a[1]; for (int i = 1; i <= n; i++){ if (start + x <= a[i]){ start = a[i]; cnt += 1; } } return cnt >= m; }
intmain(){ cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); r = a[n]; while (r - l > 1) { int mid = (r + l) >> 1; if (check(mid)) { l = mid; } else { r = mid; } } cout << l; }