Problem Statement
Ferris Wheel
Implementation
void solve() {
ll n, x;
cin >> n >> x;
map<ll, ll> mp;
rep(i, n) {
ll xx;
mp[xx]++;
}
ll ans = 0;
while (sz(mp)) {
auto it_min = mp.begin();
auto it_mx = mp.upper_bound(x - it_min->f);
if (--it_mx != mp.begin()) {
// exist
if (it_mx->f == it_min->f) {
// same
if (it_mx->s > 1) {
mp[it_mx->f]--;
}
}
else {
mp[it_mx->f]--;
}
if (mp[it_mx->f] == 0) {
mp.erase(it_mx);
}
}
ans++;
mp[it_min->f]--;
if (mp[it_min->f] > 0) mp.erase(it_min);
}
cout << ans << "\n";
}