6 solutions
-
0
二分
#include<iostream> using namespace std; #define ll long long const int N = 1e7 + 5; ll n, k, Max; ll a[N]; bool check(ll x) { ll cnt = 0; for (ll i = 1; i <= n; ++i) { cnt += a[i] / x; } return cnt >= k; } int main() { scanf("%lld%lld", &n, &k); for (ll i = 1; i <= n; ++i) { scanf("%lld", &a[i]); if (a[i] > Max)Max = a[i]; } ll l = 0, r = Max, mid; while (l < r) { mid = (l + r) >> 1; if (check(mid))l = mid + 1; else r = mid; } printf("%lld\n", r - 1); return 0; }
Information
- ID
- 281
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 141
- Accepted
- 73
- Uploaded By