QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279152#7744. ElevatorSnowNorthRE 0ms3820kbC++141.2kb2023-12-08 12:08:092023-12-08 12:08:09

Judging History

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

  • [2023-12-08 12:08:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3820kb
  • [2023-12-08 12:08:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long ;

void solve() {
	ll n, k;
	cin >> n >> k;
	
	vector<array<int, 2>> tmp, vec;
	 
	for (int i = 1; i <= n; i++) {
		int c, w, f;
		cin >> c >> w >> f;
		if (w == 1) tmp.push_back({f, c});
		else vec.push_back({f, c});
	}
	
	sort(tmp.begin(), tmp.end());
	
	for (int i = int(tmp.size()) - 1; i > 0; i--) {
		if (!tmp[i][1]) continue ;
		
		if (tmp[i][1] & 1) {
			tmp[i][1]++;
			tmp[i - 1][1]--;
		}
		vec.push_back({tmp[i][0], tmp[i][1] / 2});
	}
	if (tmp[0][1]) vec.push_back({tmp[0][0], (tmp[0][1] + 1) / 2});
	
	k /= 2;
	
	sort(vec.begin(), vec.end());
	
	ll ans = 0;
	for (int i = int(vec.size()) - 1; i >= 0; i--) {
		
		int cnt = vec[i][1] / k;
		vec[i][1] %= k;
		
		ans += (ll)vec[i][0] * cnt;
		
		if (vec[i][1]) {
			int j = i, sum = vec[i][1];
		
			while (j > 0 && sum + vec[j - 1][1] <= k) {
				sum += vec[--j][1];
			}
			
			if (j > 0) vec[j - 1][1] -= k - sum;
			ans += vec[i][0];
			
			i = j;
		}
	}
	
	cout << ans << '\n';
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	while (T--)
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: