Language: C++

#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using vpii = vector<pii>;

int main(){
  long N, K;
  cin >> N >> K;
  vl A(N), F(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];

  stable_sort(A.begin(), A.end());
  stable_partition(F.begin(), F.end(), greater<long>());

  long left = 0, right = 0;

  rep(i, N) right = max(right, A[i]*F[i]);

  long ans = 0;

  while(left <= right){
    long mid = left + (right - left) / 2;
    long cnt = 0;

    rep(i, N){
      if(A[i]*F[i] > mid) cnt += (A[i]*F[i] - mid - 1) / F[i] + 1;
    }

    if(cnt > K){
      left = mid + 1;
    }
    else{
      ans = mid;
      right = mid - 1;
    }
  }

  cout << ans << endl;
  
  return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<long int*, std::vector<long int> >; _Predicate = std::greater<long int>]':
/usr/include/c++/14/bits/stl_algo.h:1488:16:   required from '_ForwardIterator std::__stable_partition_adaptive(_ForwardIterator, _ForwardIterator, _Predicate, _Distance, _Pointer, _Distance) [with _ForwardIterator = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Pointer = long int*; _Predicate = __gnu_cxx::__ops::_Iter_pred<greater<long int> >; _Distance = long int]'
 1488 |             if (__pred(__first))
      |                 ~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1543:34:   required from '_ForwardIterator std::__stable_partition(_ForwardIterator, _ForwardIterator, _Predicate) [with _ForwardIterator = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<greater<long int> >]'
 1543 |         std::__stable_partition_adaptive(__first, __last, __pred,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
 1544 |                                          _DistanceType(__buf.requested_size()),
      |                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1545 |                                          __buf.begin(),
      |                                          ~~~~~~~~~~~~~~
 1546 |                                          _DistanceType(__buf.size()));
      |                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1578:37:   required from '_BIter std::stable_partition(_BIter, _BIter, _Predicate) [with _BIter = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Predicate = greater<long int>]'
 1578 |       return std::__stable_partition(__first, __last,
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1579 |                                      __gnu_cxx::__ops::__pred_iter(__pred));
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:37:19:   required from here
   37 |   stable_partition(F.begin(), F.end(), greater<long>());
      |   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:318:30: error: no match for call to '(std::greater<long int>) (long int&)'
  318 |         { return bool(_M_pred(*__it)); }
      |                       ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/string:49:
/usr/include/c++/14/bits/stl_function.h:394:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = long int]'
  394 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_function.h:394:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_negate<_Predicate>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<long int*, std::vector<long int> >; _Predicate = std::greater<long int>]':
/usr/include/c++/14/bits/stl_algobase.h:2107:14:   required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Predicate = __gnu_cxx::__ops::_Iter_negate<greater<long int> >]'
 2107 |           if (__pred(__first))
      |               ~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:112:28:   required from '_InputIterator std::__find_if_not(_InputIterator, _InputIterator, _Predicate) [with _InputIterator = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<greater<long int> >]'
  112 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
  113 |                             __gnu_cxx::__ops::__negate(__pred),
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114 |                             std::__iterator_category(__first));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1530:35:   required from '_ForwardIterator std::__stable_partition(_ForwardIterator, _ForwardIterator, _Predicate) [with _ForwardIterator = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<greater<long int> >]'
 1530 |       __first = std::__find_if_not(__first, __last, __pred);
      |                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1578:37:   required from '_BIter std::stable_partition(_BIter, _BIter, _Predicate) [with _BIter = __gnu_cxx::__normal_iterator<long int*, vector<long int> >; _Predicate = greater<long int>]'
 1578 |       return std::__stable_partition(__first, __last,
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1579 |                                      __gnu_cxx::__ops::__pred_iter(__pred));
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:37:19:   required from here
   37 |   stable_partition(F.begin(), F.end(), greater<long>());
      |   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:395:31: error: no match for call to '(std::greater<long int>) (long int&)'
  395 |         { return !bool(_M_pred(*__it)); }
      |                        ~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_function.h:394:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = long int]'
  394 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_function.h:394:7: note:   candidate expects 2 arguments, 1 provided