Language: C++

#include <bits/stdc++.h>

using namespace std;

struct P {
  int v, c, i;
};

struct comp
{
    bool operator()(const P &r, const P &l)
    {
        return r.v < l.v;
    }
};


P newP(int v, int c, int i) {
  P p;
  p.v = v;
  p.c = c;
  p.i = i;
  return p;
}

typedef long long ll;
const int mxn = 2e5;
int x,n, k;
set<P,comp> a;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> k;
  int temp;
  for (int i = 0;i<n;i++) {
    cin >> temp;
    a.insert(newP(temp, 0, temp));
  }

  while (k>0) {
    auto it = a.rend();
    int v = (*it).i - ((*it).i/(*it).c)*((*it).c-1);
    P p = newP(v, (*it).c+1,(*it).i);
    a.erase((*it));
    a.insert(p);
  }
  auto it = a.rend();
  cout << (*it).v <<endl;





}


Compiler output:
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = P; _Val = P; _KeyOfValue = std::_Identity<P>; _Compare = comp; _Alloc = std::allocator<P>; _Const_Link_type = const std::_Rb_tree_node<P>*]':
/usr/include/c++/14/bits/stl_tree.h:2116:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = P; _Val = P; _KeyOfValue = std::_Identity<P>; _Compare = comp; _Alloc = std::allocator<P>; key_type = P]'
 2116 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                                                ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:2169:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = P; _Key = P; _Val = P; _KeyOfValue = std::_Identity<P>; _Compare = comp; _Alloc = std::allocator<P>]'
 2169 |         = _M_get_insert_unique_pos(_KeyOfValue()(__v));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:523:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = P; _Compare = comp; _Alloc = std::allocator<P>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<P, P, std::_Identity<P>, comp, std::allocator<P> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<P>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<P>, P>::rebind<P>; typename _Alloc::value_type = P; value_type = P]'
  523 |           _M_t._M_insert_unique(std::move(__x));
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:40:13:   required from here
   40 |     a.insert(newP(temp, 0, temp));
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: error: static assertion failed: comparison object must be invocable as const
  768 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: note: 'std::is_invocable_v<const comp&, const P&, const P&>' evaluates to false