大样例能够,52分
查看原帖
大样例能够,52分
1073203
zhiyintm666楼主2023/10/14 20:31

求助QwQ

#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;
}
2023/10/14 20:31
加载中...