Language: Java

#include "bits/stdc++.h"
using namespace std;
int N, X;
long long l[300010], r[300010], b[300010];

bool good(long long need) {
	long long extra = need % X;
	need /= X;
	if(need >= N) return true;

	long long sum = 0;
	vector <pair <long long, int>> v;
	for(int i = 1; i <= N; i++) {
		sum -= l[i] * b[i];
		v.emplace_back(r[i] * (X - b[i]) + l[i] * b[i], i);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for(int i = 0; i < need; i++) {
		sum += v[i].first;
	}
	if(extra == 0) return sum >= 0;
	long long ans = sum;
	for(int i = need; i < N; i++) {
		int id = v[i].second;
		long long diff = extra - b[id];
		ans = max(ans, sum + l[id] * diff + l[id] * b[id]);
		ans = max(ans, sum + r[id] * diff + l[id] * b[id]);
	}
	sum += v[need].first;
	for(int i = 0; i < need; i++) {
		int id = v[i].second;
		long long diff = extra - b[id];
		ans = max(ans, sum - r[id] * (X - b[id]) + l[id] * diff);
		ans = max(ans, sum - r[id] * (X - b[id]) + r[id] * diff);
	}
	return ans >= 0;
}

long long search(long long b, long long e) {
	if(b == e) {
		return b;
	}
	long long mid = (b + e) >> 1;
	if(good(mid)) {
		return search(b, mid);
	} else {
		return search(mid + 1, e);
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &N, &X);
	for(int i = 1; i <= N; i++) {
		scanf("%lld %lld %lld", &b[i], &l[i], &r[i]);
	}
	printf("%lld\n", search(0, 1LL * X * N));
	return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include "bits/stdc++.h"
^
Main.java:1: error: class, interface, enum, or record expected
#include "bits/stdc++.h"
         ^
Main.java:3: error: class, interface, enum, or record expected
int N, X;
^
Main.java:4: error: class, interface, enum, or record expected
long long l[300010], r[300010], b[300010];
^
Main.java:6: error: unnamed classes are a preview feature and are disabled by default.
bool good(long long need) {
^
  (use --enable-preview to enable unnamed classes)
Main.java:6: error: <identifier> expected
bool good(long long need) {
              ^
Main.java:8: error: class, interface, enum, or record expected
	need /= X;
	^
Main.java:9: error: class, interface, enum, or record expected
	if(need >= N) return true;
	^
Main.java:11: error: class, interface, enum, or record expected
	long long sum = 0;
	^
Main.java:12: error: class, interface, enum, or record expected
	vector <pair <long long, int>> v;
	^
Main.java:13: error: class, interface, enum, or record expected
	for(int i = 1; i <= N; i++) {
	^
Main.java:13: error: class, interface, enum, or record expected
	for(int i = 1; i <= N; i++) {
	               ^
Main.java:13: error: class, interface, enum, or record expected
	for(int i = 1; i <= N; i++) {
	                       ^
Main.java:15: error: class, interface, enum, or record expected
		v.emplace_back(r[i] * (X - b[i]) + l[i] * b[i], i);
		^
Main.java:16: error: class, interface, enum, or record expected
	}
	^
Main.java:18: error: class, interface, enum, or record expected
	reverse(v.begin(), v.end());
	^
Main.java:19: error: class, interface, enum, or record expected
	for(int i = 0; i < need; i++) {
	^
Main.java:19: error: class, interface, enum, or record expected
	for(int i = 0; i < need; i++) {
	               ^
Main.java:19: error: class, interface, enum, or record expected
	for(int i = 0; i < need; i++) {
	                         ^
Main.java:21: error: class, interface, enum, or record expected
	}
	^
Main.java:23: error: class, interface, enum, or record expected
	long long ans = sum;
	^
Main.java:24: error: class, interface, enum, or record expected
	for(int i = need; i < N; i++) {
	^
Main.java:24: error: class, interface, enum, or record expected
	for(int i = need; i < N; i++) {
	                  ^
Main.java:24: error: class, interface, enum, or record expected
	for(int i = need; i < N; i++) {
	                         ^
Main.java:26: error: class, interface, enum, or record expected
		long long diff = extra - b[id];
		^
Main.java:27: error: class, interface, enum, or record expected
		ans = max(ans, sum + l[id] * diff + l[id] * b[id]);
		^
Main.java:28: error: class, interface, enum, or record expected
		ans = max(ans, sum + r[id] * diff + l[id] * b[id]);
		^
Main.java:29: error: class, interface, enum, or record expected
	}
	^
Main.java:31: error: class, interface, enum, or record expected
	for(int i = 0; i < need; i++) {
	^
Main.java:31: error: class, interface, enum, or record expected
	for(int i = 0; i < need; i++) {
	               ^
Main.java:31: error: class, interface, enum, or record expected
	for(int i = 0; i < need; i++) {
	                         ^
Main.java:33: error: class, interface, enum, or record expected
		long long diff = extra - b[id];
		^
Main.java:34: error: class, interface, enum, or record expected
		ans = max(ans, sum - r[id] * (X - b[id]) + l[id] * diff);
		^
Main.java:35: error: class, interface, enum, or record expected
		ans = max(ans, sum - r[id] * (X - b[id]) + r[id] * diff);
		^
Main.java:36: error: class, interface, enum, or record expected
	}
	^
Main.java:38: error: class, interface, enum, or record expected
}
^
Main.java:43: error: class, interface, enum, or record expected
	}
	^
Main.java:45: error: class, interface, enum, or record expected
	if(good(mid)) {
	^
Main.java:47: error: class, interface, enum, or record expected
	} else {
	^
Main.java:49: error: class, interface, enum, or record expected
	}
	^
Main.java:55: error: class, interface, enum, or record expected
	for(int i = 1; i <= N; i++) {
	^
Main.java:55: error: class, interface, enum, or record expected
	for(int i = 1; i <= N; i++) {
	               ^
Main.java:55: error: class, interface, enum, or record expected
	for(int i = 1; i <= N; i++) {
	                       ^
Main.java:57: error: class, interface, enum, or record expected
	}
	^
Main.java:59: error: class, interface, enum, or record expected
	return 0;
	^
Main.java:60: error: class, interface, enum, or record expected
}
^
46 errors