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

STL水过,RE请注意输入为0的情况

Posted by yousiki at 2016-07-27 09:58:00 on Problem 1456
代码:
#include<queue>
#include<cstdio>
using namespace std;
int n, ans, tail;
priority_queue< pair<int, int> > a;
priority_queue< int > b;
signed main(void) {
	while (scanf("%d",&n) != EOF) {
		if (n == 0) {
			puts("0");
			continue;
		}
		while (!a.empty())a.pop();
		while (!b.empty())b.pop();
		for (int i = 1, x, y; i <= n; i++)
			scanf("%d%d", &x, &y),
			a.push(make_pair(y, x));
		for (ans = 0, tail = a.top().first; tail; tail--) {
			while (!a.empty()&&a.top().first >= tail)b.push(a.top().second), a.pop();
			if (!b.empty())ans += b.top(), b.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