Nanyang OJ 757 Final Exam "Priority queue +sort Sort"

Source: Internet
Author: User

Describe
Soon the exam, little T has a lot of homework to do, and each teacher gave out the assignment to pay the deadline, if not handed in within the specified period of homework will deduct the final score, assuming that the completion of each homework need a day, you can help small t deduction of the smallest score?
Input
Enter N, which represents N-gate homework (n<2000), next n lines, two numbers per line, A, B, respectively, indicating the deadline for the delivery of the job, and the late deduction of the score.
(End of file)
Output
the minimum fraction of the output deduction.
Sample input
33 103 53 131 63 21 371 34 26 14 72 64 53 4
Sample output
035


#include <cstdio> #include <queue> #include <algorithm>using namespace std;struct exam{int gra,date;} Arr[1002];bool CMP (Exam A,exam b) {if (a.date==b.date) return A.gra<b.gra;return a.date<b.date;} Exam temp;priority_queue<int,vector<int>,greater<int> >q;int Main () {int t,n,i;while (~scanf ("%d", &t)) {while (!q.empty ()) Q.pop ();//queue initialization for (i=0;i<t;++i) {scanf ("%d%d", &arr[i].date,&arr[i].gra);} Sort (arr,arr+t,cmp); int sum=0;//int day=0;for (i=0;i<t;++i) {if (Q.size () <arr[i].date) Q.push (Arr[i].gra);// Q.size () as the number of days else//will be deducted, but to try to buckle at least {if (Q.top () <arr[i].gra) {sum + = Q.top (); Q.pop (); Q.push (Arr[i].gra);} Else{sum+=arr[i].gra;}} ++day;} printf ("%d\n", sum);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nanyang OJ 757 Final Exam "Priority queue +sort Sort"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.