Language: C++

#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <iterator>
using namespace std;

typedef pair<int, int> P;
int N;
P A[300000];
multiset<int> os;

bool f(long long X) {
  multiset<long long> s(os);
  multiset<int> g;
  long long t = 0;
  for (int i=0; i<X-1; i++) {
    int x = A[i].second;
    s.erase(s.find(x));
    g.insert(x);
    t += x;
  }

  for (int i=0; i<N-X+1; i++) {
    int x = A[i].second;
    long long b = (long long)A[i].first * X - x;
    auto it = s.find(x);
    if (it != s.end()) s.erase(it);
    else {
      auto it2 = g.find(x);
      if (it2 != g.end()) {
        g.erase(it2);
        long long d = *s.begin();
        s.erase(s.begin());
        t += t - x + d;
        g.insert(d);
      }
    }
    if (t <= b) return true;
  }
  return false;
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    int a, b;
    cin >> a >> b;
    A[i] = P(b, a);
  }
  sort(A, A+N);
  for (int i=0; i<N; i++) os.insert(A[i].second);

  int lo = 0, hi = N+1;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (f(mid)) lo = mid;
    else        hi = mid;
  }
  cout << lo << "\n";
  return 0;
}

Compiler output:
a.cc: In function 'bool f(long long int)':
a.cc:14:27: error: no matching function for call to 'std::multiset<long long int>::multiset(std::multiset<int>&)'
   14 |   multiset<long long> s(os);
      |                           ^
In file included from /usr/include/c++/14/set:64,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_multiset.h:269:9: note: candidate: 'template<class _InputIterator> std::multiset<_Key, _Compare, _Alloc>::multiset(_InputIterator, _InputIterator, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  269 |         multiset(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:269:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:204:9: note: candidate: 'template<class _InputIterator> std::multiset<_Key, _Compare, _Alloc>::multiset(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  204 |         multiset(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:204:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:188:9: note: candidate: 'template<class _InputIterator> std::multiset<_Key, _Compare, _Alloc>::multiset(_InputIterator, _InputIterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  188 |         multiset(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:188:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:263:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(std::initializer_list<_Tp>, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  263 |       multiset(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:263:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:257:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(std::multiset<_Key, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
  257 |       multiset(multiset&& __m, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:257:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:252:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(const std::multiset<_Key, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
  252 |       multiset(const multiset& __m,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:252:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:248:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  248 |       multiset(const allocator_type& __a)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:248:38: note:   no known conversion for argument 1 from 'std::multiset<int>' to 'const std::multiset<long long int>::allocator_type&' {aka 'const std::allocator<long long int>&'}
  248 |       multiset(const allocator_type& __a)
      |                ~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_multiset.h:240:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(std::initializer_list<_Tp>, const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  240 |       multiset(initializer_list<value_type> __l,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:240:45: note:   no known conversion for argument 1 from 'std::multiset<int>' to 'std::initializer_list<long long int>'
  240 |       multiset(initializer_list<value_type> __l,
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_multiset.h:228:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(std::multiset<_Key, _Compare, _Alloc>&&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  228 |       multiset(multiset&&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:228:16: note:   no known conversion for argument 1 from 'std::multiset<int>' to 'std::multiset<long long int>&&'
  228 |       multiset(multiset&&) = default;
      |                ^~~~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:219:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(const std::multiset<_Key, _Compare, _Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  219 |       multiset(const multiset&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:219:16: note:   no known conversion for argument 1 from 'std::multiset<int>' to 'const std::multiset<long long int>&'
  219 |       multiset(const multiset&) = default;
      |                ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:174:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset(const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  174 |       multiset(const _Compare& __comp,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:174:32: note:   no known conversion for argument 1 from 'std::multiset<int>' to 'const std::less<long long int>&'
  174 |       multiset(const _Compare& __comp,
      |                ~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:165:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::multiset() [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  165 |       multiset() = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_multiset.h:165:7: note:   candidate expects 0 arguments, 1 provided