记录编号 601792 评测结果 WWWWEWWEWW
题目名称 3097.[POJ 1456]超市 最终得分 0
用户昵称 Gravataryrtiop 是否通过 未通过
代码语言 C++ 运行时间 0.584 s
提交时间 2025-06-27 20:47:17 内存使用 3.74 MiB
显示代码纯文本
#include <bits/stdc++.h>
#define fir first
#define sec second

using pii = std::pair<int, int>;

int main() {
	freopen("supermarket.in", "r", stdin);
	freopen("supermarket.out", "w", stdout);
	std::cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	while (std::cin >> n) {
		std::vector<pii> a(n);
		for (int i = 0; i < n; ++i) {
			std::cin >> a[i].fir >> a[i].sec;
		}
		std::sort(a.begin(), a.end(), [&](const pii& lhs, const pii& rhs) {
			return lhs.sec > rhs.sec;
		});
		int idx = 0, d = a[0].sec, ans = 0;
		std::priority_queue<int> q;
		while (idx < n && d > 0) {
			while (idx < n && a[idx].sec == d) q.emplace(a[idx].fir), ++idx;
			if (!q.empty()) ans += q.top(), q.pop();
			d = (q.empty() && idx < n) ? std::min(a[idx].sec, d - 1) : d - 1;
		}
		std::cout << ans << '\n';
	}
	return 0;
}