Language: C++

#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
    long long n, m;
    while(1){
        cin >> n;
        cin >> m;
        if(n == 0 && m ==0){
            break;
        }

        vector<pair <long long, long long>> data(n);
        long long total_encounter = 0;
        long long d, p;
        for(long long i = 0 ; i < n; i++){
            cin >> d;
            cin >> p;
            data[i] = make_pair(p, d);
            total_encounter += d * p;
        }
        
        sort(data.begin(), data.end());
        reverse(data.begin(), data.end());
        
        long long cost = 0;
        long long index = 0;
        while(1){
            if(cost + data[index].second > m){
                total_encounter -= (m - cost) * data[index].first;
                break;
            }
            cost += data[index].second;
            total_encounter -= data[index].first * data[index].second;
            index++;
        }
        cout << total_encounter << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:9: error: 'vector' was not declared in this scope
   17 |         vector<pair <long long, long long>> data(n);
      |         ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | 
a.cc:17:42: error: expected primary-expression before '>' token
   17 |         vector<pair <long long, long long>> data(n);
      |                                          ^~
a.cc:17:49: error: no matching function for call to 'data(long long int&)'
   17 |         vector<pair <long long, long long>> data(n);
      |                                             ~~~~^~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:312:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&) [with _Container = long long int]':
a.cc:17:49:   required from here
   17 |         vector<pair <long long, long long>> data(n);
      |                                             ~~~~^~~
/usr/include/c++/14/bits/range_access.h:313:24: error: request for member 'data' in '__cont', which is of non-class type 'long long int'
  313 |     -> decltype(__cont.data())
      |                 ~~~~~~~^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&) [with _Container = long long int]':
a.cc:17:49:   required from here
   17 |         vector<pair <long long, long long>> data(n);
      |                                             ~~~~^~~
/usr/include/c++/14/bits/range_access.h:324:24: error: request for member 'data' in '__cont', which is of non-class type 'const long long int'
  324 |     -> decltype(__cont.data())
      |                 ~~~~~~~^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:   template argument deduction/substitution failed:
a.cc:17:49: note:   mismatched types '_Tp [_Nm]' and 'long long int'
   17 |         vector<pair <long long, long long>> data(n);
      |                                             ~~~~^~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note:   template argument deduction/substitution failed:
a.cc:17:49: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |         vector<pair <long long, long long>> data(n);
      |                                             ~~~~^~~
a.cc:23:17: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   23 |             data[i] = make_pair(p, d);
      |                 ^
a.cc:27:19: error: overloaded function with no contextual type information
   27 |         sort(data.begin(), data.end());
      |                   ^~~~~
a.cc:27:33: error: overloaded function with no contextual type information
   27 |         sort(data.begin(), data.end());
      |                                 ^~~
a.cc:28:22: error: overloaded function with no contextual type information
   28 |         reverse(data.begin(), data.end());
      |                      ^~~~~
a.cc:28:36: error: overloaded function with no contextual type information
   28 |         reverse(data.begin(), data.end());
      |                                    ^~~
a.cc:33:27: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   33 |             if(cost + data[index].second > m){
      |                           ^
a.cc:34:53: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   34 |                 total_encounter -= (m - cost) * data[index].first;
      |                                                     ^
a.cc:37:25: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   37 |             cost += data[index].second;
      |                         ^
a.cc:38:36: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   38 |             total_encounter -= data[index].first * data[index].second;
      |                                    ^
a.cc:38:56: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   38 |             total_encounter -= data[index].first * data[index].second;
      |                                                        ^