The main idea: a classmate to complete the homework assigned by the teacher. Each job has a deadline and corresponding deduction points. If the deadline is not completed, the corresponding points will be deducted. Q: How to arrange the order of homework to make the total score of the deduction minimum (1 days to complete a job)Idea: According to the greedy thought, priority to deduct a lot of homework, first deal with them. To do this, sort the jobs in descending order by the number of snaps. From the most points of the job start, it is scheduled to the deadline of its completion day, if the day has been occupied, then move forward one day, if the previous days are occupied, then this job can only give up, must be deducted points.
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace
Std
struct Node {int deadline;
int score;
}A[1002];
int isdone[2000];
BOOL CMP (node A,node b) {return a.score>b.score;}
int main () {int case,n;
cin>>case;
while (case--) {memset (isdone,0,sizeof (IsDone));
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i].deadline;
for (int i=1;i<=n;i++) cin>>a[i].score;
Sort (a+1,a+n+1,cmp);
int sum=0;
for (int i=1;i<=n;i++) {int flag=0; for (int j=a[i].deadline;j>=1;j--) {if (!
Isdone[j]) {isdone[j]=1;
flag=1;
Break
}} if (!flag) Sum+=a[i].score;
} cout<<sum<<endl;
} return 0; }