Untitled
user_7227489
plain_text
a month ago
884 B
4
Indexable
Never
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef vector<int> vi; int main() { int chargers, sockets; cin >> chargers >> sockets; vi a(chargers); for (int i = 0; i < chargers; ++i) { cin >> a[i]; } if (chargers == 1 || sockets == 1) { cout << 1 << '\n'; return 0; } int l = 1, r = chargers + 1; sort(a.begin(), a.end()); while (l + 1 < r) { int m = (l + r) / 2; vi cnt(3); LL x = 0; for(int i = 0; i < m-2; i++){ x += a[i] / 3; cnt[a[i] % 3]++; } int k = min(cnt[1], cnt[2]); x += k; x += (cnt[1] - k + 1) / 2; x += cnt[2] - k; if (x <= sockets - 2) l = m; else r = m; } cout << l << '\n'; return 0; }
Leave a Comment