Language: C++

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define fi first
#define se second

const int N = 1e5 + 5, inf = 1e18 + 123;
int n, x, b[N], l[N], r[N];

bool check (int lim) {
    int dist = 0;
    for (int i = 0; i < n; ++i) dist += 1LL * l[i] * b[i];
    vector< pair<int, int> > vec;
    for (int i = 0; i < n; ++i) vec.pb( { 1LL * (r[i] - l[i]) * b[i] - 1LL * x * r[i], i } );
    sort(vec.begin(), vec.end() );
    int lst = lim / x; lim %= x;

    if (lst < n) {
        int sum = 0, minn = inf;
        for (int i = 0; i <= lst; ++i) sum += vec[i].fi;
        for (int i = 0; i < n; ++i) {
            int tmp;
            if (lim >= b[ vec[i].se ]) tmp = (r[ vec[i].se ] - l[ vec[i].se ]) * b[ vec[i].se ] - lim * r[ vec[i].se ];
            else tmp = -lim * l[ vec[i].se ];
            if (i <= lst) minn = min(minn, sum - vec[i].fi + tmp);
            else minn = min(minn, sum - vec[lst].fi + tmp);
        }
        dist += minn;
    }
    else {
        for (int i = 0; i < n; ++i) dist += vec[i].fi;
    }

    return dist <= 0;
}

int32_t main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> x;
    for (int i = 0; i < n; ++i) cin >> b[i] >> l[i] >> r[i];

    int L = 0, R = 1e10;
    while (L < R) {
        int mid = (L + R) >> 1;
        if (check(mid) ) R = mid;
        else L = mid + 1;
    }

    cout << L;

    return 0;
}
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define fi first
#define se second

const int N = 1e5 + 5, inf = 1e18 + 123;
int n, x, b[N], l[N], r[N];

bool check (int lim) {
    int dist = 0;
    for (int i = 0; i < n; ++i) dist += 1LL * l[i] * b[i];
    vector< pair<int, int> > vec;
    for (int i = 0; i < n; ++i) vec.pb( { 1LL * (r[i] - l[i]) * b[i] - 1LL * x * r[i], i } );
    sort(vec.begin(), vec.end() );
    int lst = lim / x; lim %= x;

    if (lst < n) {
        int sum = 0, minn = inf;
        for (int i = 0; i <= lst; ++i) sum += vec[i].fi;
        for (int i = 0; i < n; ++i) {
            int tmp;
            if (lim >= b[ vec[i].se ]) tmp = (r[ vec[i].se ] - l[ vec[i].se ]) * b[ vec[i].se ] - lim * r[ vec[i].se ];
            else tmp = -lim * l[ vec[i].se ];
            if (i <= lst) minn = min(minn, sum - vec[i].fi + tmp);
            else minn = min(minn, sum - vec[lst].fi + tmp);
        }
        dist += minn;
    }
    else {
        for (int i = 0; i < n; ++i) dist += vec[i].fi;
    }

    return dist <= 0;
}

int32_t main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> x;
    for (int i = 0; i < n; ++i) cin >> b[i] >> l[i] >> r[i];

    int L = 0, R = 1e10;
    while (L < R) {
        int mid = (L + R) >> 1;
        if (check(mid) ) R = mid;
        else L = mid + 1;
    }

    cout << L;

    return 0;
}
v

Compiler output:
a.cc:66:11: error: redefinition of 'const long long int N'
   66 | const int N = 1e5 + 5, inf = 1e18 + 123;
      |           ^
a.cc:10:11: note: 'const long long int N' previously defined here
   10 | const int N = 1e5 + 5, inf = 1e18 + 123;
      |           ^
a.cc:66:24: error: redefinition of 'const long long int inf'
   66 | const int N = 1e5 + 5, inf = 1e18 + 123;
      |                        ^~~
a.cc:10:24: note: 'const long long int inf' previously defined here
   10 | const int N = 1e5 + 5, inf = 1e18 + 123;
      |                        ^~~
a.cc:67:5: error: redefinition of 'long long int n'
   67 | int n, x, b[N], l[N], r[N];
      |     ^
a.cc:11:5: note: 'long long int n' previously declared here
   11 | int n, x, b[N], l[N], r[N];
      |     ^
a.cc:67:8: error: redefinition of 'long long int x'
   67 | int n, x, b[N], l[N], r[N];
      |        ^
a.cc:11:8: note: 'long long int x' previously declared here
   11 | int n, x, b[N], l[N], r[N];
      |        ^
a.cc:67:11: error: redefinition of 'long long int b [100005]'
   67 | int n, x, b[N], l[N], r[N];
      |           ^
a.cc:11:11: note: 'long long int b [100005]' previously declared here
   11 | int n, x, b[N], l[N], r[N];
      |           ^
a.cc:67:17: error: redefinition of 'long long int l [100005]'
   67 | int n, x, b[N], l[N], r[N];
      |                 ^
a.cc:11:17: note: 'long long int l [100005]' previously declared here
   11 | int n, x, b[N], l[N], r[N];
      |                 ^
a.cc:67:23: error: redefinition of 'long long int r [100005]'
   67 | int n, x, b[N], l[N], r[N];
      |                       ^
a.cc:11:23: note: 'long long int r [100005]' previously declared here
   11 | int n, x, b[N], l[N], r[N];
      |                       ^
a.cc:69:6: error: redefinition of 'bool check(long long int)'
   69 | bool check (int lim) {
      |      ^~~~~
a.cc:13:6: note: 'bool check(long long int)' previously defined here
   13 | bool check (int lim) {
      |      ^~~~~
a.cc:96:9: error: redefinition of 'int32_t main()'
   96 | int32_t main () {
      |         ^~~~
a.cc:40:9: note: 'int32_t main()' previously defined here
   40 | int32_t main () {
      |         ^~~~
a.cc:113:1: error: 'v' does not name a type
  113 | v
      | ^