Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:精简后的优良代码

Posted by yousiki at 2016-07-27 10:36:10 on Problem 1456
In Reply To:STL水过,RE请注意输入为0的情况 Posted by:yousiki at 2016-07-27 09:58:00
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
pair<int, int> a[10005];
priority_queue<int> pq;
signed main(void) {
	int n, ans, i, j;
	while (scanf("%d",&n)!=EOF) {
		for (i = 1; i <= n; i++)scanf("%d%d", &a[i].second, &a[i].first);
		sort(a + 1, a + 1 + n); while (!pq.empty())pq.pop();
		for (i = a[n].first, j = n, ans = 0; i; i--) {
			while (j&&a[j].first >= i)pq.push(a[j--].second);
			if (!pq.empty())ans += pq.top(), pq.pop();
		}
		printf("%d\n", ans);
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator