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"