Doing Homework Again

Source: Internet
Author: User

Description
Test instructions is a hdu of God's cattle from the world final heroic return. Then he has to mend his homework. A total of n jobs will take one day to complete each job. However, each job has a due date if it exceeds the due date, it will deduct the due date of n jobs and if it is more than the cutoff date to calculate the order of how to do the work of the least calculate the minimum deduction score input
The input 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.
Output
For the should output of the smallest total reduced score, one line per test case.
Sampleinput
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sampleoutput
035
First, according to the order of the points from the big to the small, the same score according to the cutoff date from small to large order. Then, in order, start looking for the time that is not occupied from the due date. If you can't find it, add it to the penalty point.
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 Const intmaxn=1010;7 8 structNode9 {Ten     intd,s; One }NODE[MAXN]; A  - BOOLused[10000]; -  the BOOLCMP (Node a,node B) - { -     if(a.s==B.S) -     { +         returna.d<B.D; -     }     +     returnA.s>B.S; A }         at  - intMain () - { -     intT; -     intN; -     intJ; inscanf"%d",&T); -      while(t--) to     { +scanf"%d",&n); -          for(intI=0; i<n;i++) scanf ("%d",&node[i].d); the          for(intI=0; i<n;i++) scanf ("%d",&node[i].s); *Sort (node,node+n,cmp); $memset (Used,false,sizeof(used));Panax Notoginseng         intans=0; -          for(intI=0; i<n;i++) the         { +              for(j=node[i].d;j>0; j--) A             { the                 if(!Used[j]) +                 { -used[j]=true; $                      Break; $                 }     -             }     -             if(j==0) theans+=Node[i].s; -         }    Wuyiprintf"%d\n", ans); the     }     -     return 0; Wu}
View Code

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.