Time limit for final exams:MS | Memory limit:65535 KB Difficulty:2
-
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
Place data in priority queue, prioritize team list team order according to score from large to small, set array vis[] to mark the corresponding date whether there is idle time,
If there is no idle time, the current score must be discarded:
#include <stdio.h> #include <cstring> #include <queue>using namespace std;struct node{int time;int score;friend bool Operator < (node A,node b) {return a.score<b.score;}}; int main () {int N,m,j,i,t;int vis[2100];while (scanf ("%d", &t)!=eof) {memset (vis,0,sizeof (VIS));p Riority_queue <node>q;node x;for (i=0;i<t;i++) {scanf ("%d%d", &n,&m); X.time=n;x.score=m;q.push (x);} int Sum=0;for (i=0;i<t;i++) {x=q.top (); for (j=x.time;j>=1;j--) {if (vis[j]==0) {vis[j]=1;break;}} if (j==0) Sum+=x.score;q.pop ();} printf ("%d\n", sum);} return 0;}
Nyoj 757 Final Exam "Priority queue + greedy"