HDU 1789 Doing Homework again

Source: Internet
Author: User

Problem Descriptionignatius have just come back school from the 30th ACM/ICPC. Now he had a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher would reduce his score of the final Test. And now we assume this doing everyone homework always takes one day. So Ignatius wants-to-help him-arrange the order of doing homework to minimize the reduced score. inputthe Inpu T contains several test cases. The first line of the input was a single integer T so is the number of test cases. T test Cases follow. Each test case start with a positive integer N (1<=n<=1000) which indicate the number of homework. Then 2 lines follow. The first line contains n integers this indicate the deadlines of the subjects, and the next line contains N integers that Indicate the reduced scores. outputfor each test case, you should output the smallest total reduced score, one line Per Test case.  Sample INPUT3 3 3 3 3 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4 sample Output0 3 5 //Oh, I feel so stupid, I don't want to see the puzzle To.. decided to brush up on the greedy recently, understand   understand well
#include <iostream>#include<algorithm>#include<cstring>using namespacestd;intans;structnode{intTime ; intFen;} work[1005];BOOLcmpConstNode &a,ConstNode &b) {    if(a.fen>B.fen)return true; Else if(a.fen==B.fen) {if(a.time<b.time)return true; Else        return false; }    Else return false;}intMain () {intT,n; intss[1005]; CIN>>T;  while(t--) {memset (ss,0,sizeof(ss)); Ans=0; CIN>>N;  for(intI=0; i<n;i++) Cin>>Work[i].time;  for(intI=0; i<n;i++) Cin>>Work[i].fen; Sort (Work,work+n,cmp); //for (int i=0;i<n;i++)//cout<<work[i].time<< "" <<work[i].fen<<endl;         for(intI=0; i<n;i++)        {            intj=Work[i].time;  while(j--)            {                if(ss[j]==0) {Ss[j]=1;  Break; }            }            if(ss[j]!=1) ans+=Work[i].fen; } cout<<ans<<Endl; }    return 0;}

HDU 1789 Doing Homework again

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.