Language: C++

#include <bits/stdc++.h>
using namespace std;
void mergesort(vector<int> s
,vector<int> t,int le,int ri ){
  if(le+1<ri){
    int mid;
    mid=(ri+le)/2;
    mergesort(s,t,le,mid);
    mergesort(s,t,mid,ri);
    merge(s,t,le,mid,ri);
  }
}

int merge(vector<int> s
,vector<int> t,int le,int mid, int ri ){
vector<int> n(le-mid+1);
vector<int> n1(le-mid+1);
for(int i=0;i<le-mid;i++){
n.at(i)=s.at(le+i);
n1.at(i)=t.at(le+i);
}
vector<int> m(mid-ri+1);
vector<int> m1(mid-ri+1);
for(int i=0;i<le-mid;i++){
m.at(i)=s.at(mid+i);
m1.at(i)=s.at(mid+i);
} 
int j=0;
int k=0;
for(int i=le;i<ri;i++){
if(n.at(j)<=m.at(k)){
s.at(i)=n.at(j);
t.at(i)=n1.at(j);
}
else{
s.at(i)=m.at(k);
t.at(i)=m1.at(k);
}
}
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> pri(n);
  vector<int> ma(n);
  vector<int> che(n,0);
  for(int i=0;i<n;i++)
    cin >> pri.at(i) >> ma.at(i);
  long long ans=0;
  int con =0;
  mergesort(pri,ma,0,n-1)
  int x=0;
  while(con<m){
    int y=min(ma.at(x),m-con);
    ans+=(long)y*pri.at(x);
    con+=y;
    x++;
  }
  cout << ans << endl; 
}
  

Compiler output:
a.cc: In function 'int merge(std::vector<int>, std::vector<int>, int, int, int)':
a.cc:40:1: warning: no return statement in function returning non-void [-Wreturn-type]
   40 | }
      | ^
a.cc: In function 'int main()':
a.cc:52:26: error: expected ';' before 'int'
   52 |   mergesort(pri,ma,0,n-1)
      |                          ^
      |                          ;
   53 |   int x=0;
      |   ~~~                     
a.cc:55:21: error: 'x' was not declared in this scope
   55 |     int y=min(ma.at(x),m-con);
      |                     ^
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of '_OutputIterator std::__merge(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare) [with _InputIterator1 = vector<int>; _InputIterator2 = int; _OutputIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/14/bits/stl_algo.h:4876:37:   required from '_OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter) [with _IIter1 = vector<int>; _IIter2 = int; _OIter = int]'
 4876 |       return _GLIBCXX_STD_A::__merge(__first1, __last1,
      |                                     ^
a.cc:10:10:   required from here
   10 |     merge(s,t,le,mid,ri);
      |     ~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4820:15: error: invalid type argument of unary '*' (have 'int')
 4820 |               *__result = *__first2;
      |               ^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4820:27: error: invalid type argument of unary '*' (have 'int')
 4820 |               *__result = *__first2;
      |                           ^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4825:15: error: invalid type argument of unary '*' (have 'int')
 4825 |               *__result = *__first1;
      |               ^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4825:27: error: no match for 'operator*' (operand type is 'std::vector<int>')
 4825 |               *__result = *__first1;
      |                           ^~~~~~~~~
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)'
  418 |     operator*(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:418:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:4826:15: error: no match for 'operator++' (operand type is 'std::vector<int>')
 4826 |               ++__first1;
      |               ^~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = int; _Iterator2 = std::vector<int>]':
/usr/include/c++/14/bits/stl_algo.h:4818:14:   required from '_OutputIterator std::__merge(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare) [with _InputIterator1 = vector<int>; _InputIterator2 = int; _OutputIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 4818 |           if (__comp(__first2, __first1))
      |               ~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4876:37:   required from '_OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter) [with _IIter1 = vector<int>; _IIter2 = int; _OIter = int]'
 4876 |       return _GLIBCXX_STD_A::__merge(__first1, __last1,
      |                                     ^
a.cc:10:10:   required from here
   10 |     merge(s,t,le,mid,ri);
      |     ~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:16: error: invalid type argument of unary '*' (have 'int')
   45 |       { return *__it1 < *__it2; }
      |                ^~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:25: error: no match for 'operator*' (operand type is 'std::vector<int>')
   45 |       { return *__it1 < *__it2; }
      |                         ^~~~~~
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, co