社区讨论

大样例能够,52分

P9742 「KDOI-06-J」贡献系统参与者 10已保存回复 11

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
11 条
当前快照
1 份
快照标识符
@lo12wlyi
此快照首次捕获于
2023/10/22 14:19
2 年前
此快照最后确认于
2023/11/02 13:48
2 年前
查看原帖
求助QwQ
CPP
#include <bits/stdc++.h>

using namespace std;

int t, n;

long long ans;

struct per {
	long long r, c;
}p[200010];

bool cmp (per x, per y) {
	return x.r > y.r;
}

int main () {
	ios::sync_with_stdio (false);
	cin.tie (nullptr);
	cout.tie (nullptr);
	cin >> t;
	while (t--) {
		ans = 0;
		cin >> n;
		for (int i = 1; i <= n; i++)
			cin >> p[i].r;
		for (int i = 1; i <= n; i++)
			cin >> p[i].c;
		sort (p + 1, p + n + 1, cmp);
		priority_queue <long long, vector <long long>, greater <long long> > q;
		q.push (p[1].c);
		for (int i = 2; i <= n; i++) {
			long long x = q.top ();
			if (p[i].c >= x) {
				ans += p[i].c - x;
				q.pop ();
				q.push (p[i].c * 2);
				q.push (0);
			}
			else q.push (p[i].c);
		}
		cout << ans << endl;
	}
	return 0;
}

回复

11 条回复,欢迎继续交流。

正在加载回复...