QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#279153#7744. ElevatorSnowNorthRE 1ms3476kbC++141.2kb2023-12-08 12:10:332023-12-08 12:10:34

Judging History

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

  • [2023-12-08 12:10:34]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3476kb
  • [2023-12-08 12:10:33]
  • 提交

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]) {
		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;
			ll 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3476kb

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: