Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<iterator>

using namespace std;
bool sortit(pair<long int,long int>&a, pair<long int,long int>&b){
	return (a.first < b.first);
}
int main(){
	int n,m;
	cin >> n >> m;
  	// insertion into two arrays
  	long int arr1[n], arr2[n];
  vector<pair<long int,int>> vec;
  	for (int i = 0 ; i < n; i++)
    {
      cin >> arr1[i] >> arr2[i];
      vec.push_back(make_pair(arr1[i],arr2[i]));
    }
  	// sorting vector on basis of first element
  	sort(vec.begin(), vec.end(), sortit);
  // main code
  long long int res =0;
  int i = 0;
  while (m != 0){
  	if(vec[i].second < m) {
    	res += (vec[i].first)*(vec[i].second);
      m = m - vec[i].second;
    }
    else {
    	res += (vec[i].first)*m;
      	m = 0;
    }
    ++i;
  }
  cout << res<<'\n';
  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 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::pair<long int, int>*, std::vector<std::pair<long int, int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<long int, int>*, std::vector<std::pair<long int, int> > >; _Compare = bool (*)(std::pair<long int, long int>&, std::pair<long int, long int>&)]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = bool (*)(pair<long int, long int>&, pair<long int, long int>&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:23:8:   required from here
   23 |         sort(vec.begin(), vec.end(), sortit);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: cannot bind non-const lvalue reference of type 'std::pair<long int, long int>&' to an rvalue of type 'std::pair<long int, long int>'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/stl_pair.h:779:19: note:   after user-defined conversion: 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = long int; _U2 = int; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = true; _T1 = long int; _T2 = long int]'
  779 |         constexpr pair(const pair<_U1, _U2>& __p)
      |                   ^~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = std::pair<long int, int>; _Iterator = __gnu_cxx::__normal_iterator<std::pair<long int, int>*, std::vector<std::pair<long int, int> > >; _Compare = bool (*)(std::pair<long int, long int>&, std::pair<long int, long int>&)]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = bool (*)(pair<long int, long int>&, pair<long int, long int>&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:23:8:   required from here
   23 |         sort(vec.begin(), vec.end(), sortit);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: cannot bind non-const lvalue reference of type 'std::pair<long int, long int>&' to an rvalue of type 'std::pair<long int, long int>'
  240 |         { return bool(_M_comp(__val, *__it)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:779:19: note:   after user-defined conversion: 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = long int; _U2 = int; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = true; _T1 = long int; _T2 = long int]'
  779 |         constexpr pair(const pair<_U1, _U2>& __p)
      |                   ^~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<long int, int>*, std::vector<std::pair<long int, int> > >; _Value = std::pair<long int, int>; _Compare = bool (*)(std::pair<long int, long int>&, std::pair<long int, long int>&)]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Distance = long int; _Tp = pair<long int, int>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:247:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Distance = long int; _Tp = pair<long int, int>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
  247 |       std::__push_heap(__first, __holeIndex, __topIndex,
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248 |                        _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:356:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long int, int>*, vector<pair<long int, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<long int, long int>&, pair<long int, long int>&)>]'
  356 |           std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
      |           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357 |