Doing Homework again

Source: Internet
Author: User

Doing Homework again

Description

Ignatius has just come back school from the 30th ACM/ICPC. now he has 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 will reduce his score of the final test. and now we assume that doing everyone homework always takes one day. so Ignatius wants you to help him to arrange the order of doing homework to minimize the specified CED score.

Input

The input contains several test cases. The first line of the input is a single integer T that 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 that indicate the deadlines of the subjects, and the next line contains N integers that indicate the specified CED scores.

Output

For each test case, you shocould output the smallest total 0000ced score, one line per test case.

Sample Input

 333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4 

Sample Output

 035 

// After reading some other people's code, I started to really have some ideas. I plan to sort by time (from small to large) in the sorting process, if the time is the same, the results are sorted by scores in ascending order. The results show that this is a little troublesome. If the time cannot be written, I will change it later. I feel that the results are sorted by scores (from large to small) relatively simple. If the scores are the same, they are sorted by time in ascending order.
# Include
 
  
# Include
  
   
# Define deusing namespace std; struct zy {int day; int score ;}; bool compare (zy x, zy y) {if (x. score = y. score) return x. day
   
    
Y. score; // sort scores in ascending order} int main () {int T; cin> T; zy a [2000]; while (T --) {int n, I, j; cin> n; int flag [2000] = {0}; // indicates no task for (I = 0; I
    
     
> A [I]. day; for (I = 0; I
     
      
> A [I]. score; sort (a, a + n, compare); int sum = 0; for (I = 0; I
      
        = 1; j --) {if (flag [j] = 0) {flag [j] = 1; // indicates that a break has been executed on the j-day ;}} if (j = 0) // indicates that the task has not been completed sum + = a [I]. score;} cout <
       
        

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.