QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#676244#7744. ElevatorRaislinSnowRE 0ms3520kbC++202.0kb2024-10-25 20:46:282024-10-25 20:46:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 20:46:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3520kb
  • [2024-10-25 20:46:28]
  • 提交

answer

#pragma GCC optimize(3, "Ofast", "inline")
#define FOR(i, a, b) for(int i = (a); i <= (b); i ++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i --)
#define debug(x) cerr << (#x) << ": " << (x) << '\n'
#define pb push_back
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef array<int, 2> pii;
typedef array<ll, 2> pll;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

int n, k;

void solve(int T) {
	cin >> n >> k;
	vector<array<int, 3>> a(n + 1, {0, 0, 0});
	FOR(i, 1, n) {
		cin >> a[i][2] >> a[i][1] >> a[i][0];
	}
	sort(a.begin() + 1, a.end());
	int now = 0, mx = 0, ans = 0;
	int t1 = n, t2 = n;
	while(t1 != 0 || t2 != 0) {
		while(t1 > 0 && (a[t1][1] != 1 || a[t1][2] == 0)) t1 --;
		while(t2 > 0 && (a[t2][1] != 2 || a[t2][2] == 0)) t2 --;
		// debug(t1), debug(t2), debug(now), debug(mx), debug(ans);
		if(t1 > t2) {
			if(a[t1][2] * a[t1][1] + now < k) {
				now += a[t1][2] * a[t1][1], mx = max(mx, a[t1][0]);
				t1 --;
				continue;
			}
			int t = k - now;
			if(now > 0) ans += mx;
			else ans += a[t1][0];
			a[t1][2] -= t, mx = now = 0;
			t = a[t1][2] / k;
			ans += t * a[t1][0];
			a[t1][2] -= t * k;
			if(a[t1][2]) now += a[t1][2] * a[t1][1], mx = max(mx, a[t1][0]);
			t1 --;
		}
		else {
			if(a[t2][2] * a[t2][1] + now < k) {
				now += a[t2][2] * a[t2][1], mx = max(mx, a[t2][0]);
				t2 --;
				continue;
			}
			int t = (k - now) / 2;
			if((k - now & 1) && t1 > 0) a[t1][2] --;
			if(now > 0) ans += mx;
			else ans += a[t2][0];
			a[t2][2] -= t, mx = now = 0;
			t = a[t2][2] / (k / 2);
			ans += t * a[t2][0];
			a[t2][2] -= t * (k / 2);
			if(a[t2][2]) now += a[t2][2] * a[t2][1], mx = max(mx, a[t2][0]);
			t2 --;
		}
	}
	if(now != 0) ans += mx;
	cout << ans << '\n';
}

void init() {

}

signed main() {
	IOS;
	int t = 1;
	cin >> t;
	init();
	FOR(T, 1, t) {
		solve(T);
	}
  	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

input:

2
4 6
1 1 8
7 2 5
1 1 7
3 2 6
8 1200000
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345

output:

24
100000

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

5501
8 104
5 2 3
6 2 4
5 2 3
6 2 9
8 2 4
2 1 3
7 2 4
8 2 8
1 290
3 1 1
12 12
6 1 2
1 2 2
1 1 2
1 2 4
6 1 1
1 2 5
6 1 4
4 1 4
6 2 4
6 2 5
4 2 5
4 1 4
5 334
1 1 4
1 2 3
4 2 1
5 1 1
2 1 2
13 218
5 2 3
5 1 4
1 2 1
1 2 5
3 2 2
1 1 3
4 2 2
1 2 5
2 2 1
2 1 5
3 2 1
5 2 1
1 1 4
10 260
7 2 1
5 1 1
5 2 4
6 1 6...

output:


result: