Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:精简后的优良代码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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator