正文
增加 7 行删除 7 行
15 行未改动1617181920212223244 行未改动2930313233343536373839404142434445464748495051525354555657585960616215 行未改动时间复杂度 $O(\max_{i = 1}^{N}{B_i} \cdot N \log N)$。Code:```cpp// template <typename typ>// inline bool up(typ &x, const typ &y) {// return x < y ? x = y, 1 : 0; }const int maxn = 1005;4 行未改动}signed main() {orh::useios();cin >> n >> k;for (rg int i = 1; i <= n; ++i) {cin >> a[i];up(mx, a[i]);}for (rg int t = 1; t <= mx; ++t) {int full = 0;for (rg int i = 1; i <= n; ++i)full += a[i] / t;if (full < (k >> 1)) break;if (full >= k) {up(ans, t * k >> 1);continue;}mod = t;sort(a + 1, a + n + 1, cmp);int tmp = (full - (k >> 1)) * t;for (rg int i = 1; i <= n && i + full <= k; ++i)tmp += a[i] % t;up(ans, tmp);}cout << ans << endl;return 0;}```15 行未改动1617181920212223244 行未改动2930313233343536373839404142434445464748495051525354555657585960616215 行未改动时间复杂度 $O(\max_{i = 1}^{N}{B_i} \cdot N \log N)$。Code:```cpp// template <typename typ>// inline bool up(typ &x, const typ &y) {// return x < y ? x = y, 1 : 0; }const int maxn = 1005;4 行未改动}signed main() {orh::useios();cin >> n >> k;for (rg int i = 1; i <= n; ++i) {cin >> a[i];up(mx, a[i]);}for (rg int t = 1; t <= mx; ++t) {int full = 0;for (rg int i = 1; i <= n; ++i)full += a[i] / t;if (full < (k >> 1)) break;if (full >= k) {up(ans, t * k >> 1);continue;}mod = t;sort(a + 1, a + n + 1, cmp);int tmp = (full - (k >> 1)) * t;for (rg int i = 1; i <= n && i + full <= k; ++i)tmp += a[i] % t;up(ans, tmp);}cout << ans << endl;return 0;}```