Language: C++

#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int2(n, x);
    vp low(n), up(n);
    vi num(n);
    vector<pair<pii, int>> data(n);
    int score = 0;
    rep(i, n) {
        cin >> num[i];
        int input = num[i];
        cin >> low[i].fir >> up[i].fir;
        low[i].sec = i; up[i].sec = i;
        score += input * low[i].fir;
        data[i].ffir = up[i].fir * (x - input) + input * low[i].fir;
        data[i].fsec = -low[i].fir;
        data[i].sec = i;
    }

    //std::cout << "score : " << score << std::endl;

    sort(all(data)); reverse(all(data));
/*
    rep(i, data.size())
        cout << data[i].ffir << " " << data[i].fsec << "," 
        << data[i].sec << endl;
    cout << endl;
*/
    int l = 0, r = x * n;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        vi used(n, 0);
        int i = 0;
        while (mid >= x) {
            score -= data[i].ffir;
            i++; mid -= x;
            used[i] = data[i].sec;
        }

        int yui = score;
        rep(j, n) {
            if (!used[i]) {
                if (mid < num[i]) {
                    yui = min(yui, yui - mid * low[i].fir);
                } else {
                    yui = min(yui, yui - num[i].fir * low[i].fir - 
                            (mid - num[i].fir) * up[i].fir);
                }
            }
        }
        if (yui >= 0) {
            r = mid;
        } else {
            l = mid;
        }
    }
    std::cout << r << std::endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:13: error: request for member 'first' in 'num.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
   26 | #define fir first
      |             ^~~~~
a.cc:84:49: note: in expansion of macro 'fir'
   84 |                     yui = min(yui, yui - num[i].fir * low[i].fir -
      |                                                 ^~~
a.cc:26:13: error: request for member 'first' in 'num.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
   26 | #define fir first
      |             ^~~~~
a.cc:85:43: note: in expansion of macro 'fir'
   85 |                             (mid - num[i].fir) * up[i].fir);
      |                                           ^~~