Fjnu 1157 fat Brother's Ruozhi Magic (fat Brother's mentally handicapped)

Source: Internet
Author: User

Fjnu 1157 fat Brother's Ruozhi Magic (fat Brother's mentally handicapped)

Time limit:1000ms Memory limit:257792k

"Description"

"title description"

Fat Brother I s a powerful magician. Both He and his enemy have N soldiers and each soldier have IQ. When both soldier is in PK, the one whose IQ is exactly higher than the another one would win. He can use Ruozhi magic to decrease his enemy's soldiers ' IQ, using Ruozhi magic one time, all of his enemy ' s soldiers ' IQ would decrease 1. Fat Brother is a perfectionists, so he want him all soldiers to win and uses Ruozhi magic at least the number of times. So what should help Fat Brother calculate how many times he should use Ruozhi magic?

Fat Brother is a powerful mage. He and his enemies have n creeps, each with a certain IQ. When the creeps are 22 PK, the higher IQ wins. He can reduce the IQ of enemy creeps by using the mentally retarded technique, which reduces the IQ of all enemy soldiers by 1 points at a time. Fat is a perfectionist, so he wants his own soldiers to win over and use the mentally retarded as little as possible. So it's up to you to help the fat guy. What is the minimum number of mentally handicapped patients he needs to use?

"Input"

Input

There is multiple test cases. The first line of input contains an integer t (t <=) indicating the number of test cases. For each test case:

The first line contains one integer N (1 <= N <= 100000) means number of soldiers.

The next line contains N number Ai means Fat Brother ' s soldiers IQ,

The next line contains N number Bi means enemy ' s soldiers IQ,

Ai and Bi fit in 32-bits signed integer

Multiple sets of test cases.

The first line is an integer t (T <= 20) that represents the number of test cases. For each test case:

The first line is an integer n (1 <= n <= 100000) that represents the number of creeps.

The next line has an n number of AI, which indicates the IQ of Fat Brother soldier.

The next line has n-number bi, which indicates the IQ of the fat Brother's creep.

AI and bi are integers between 32.

"Output"

Output

Each case print a number means at least the number of times Fat Brother should use Ruozhi magic

Each use case outputs the minimum number of uses of the Fat Elder mentally handicapped.

"Sample Input-Enter sample"

"Sample output-Output sample"

2

5

1 3 2) 4 5

3 3 3) 3 3

3

2-9-5

5-2-7

3

4

"Hint"

Prompted

First

case, use 3 times Ruozhi magic, his enemy ' s soliders ' IQ would

Become 0 0 0 0 0, all enemy's soliders ' IQ lower than fat brother ' s, so all fat Brother's soliders would win

Second

case, use 4 times Ruozhi magic, his enemy ' s soliders ' IQ would

Become 1-6 -11, so Fat Brother ' s first solidier win enemy ' s first Solidier, second win third, third win second.

The first use case,

With 3 of this mental retardation, enemy creep IQ will become 0 0 0 0 0, and all enemy creeps have a lower IQ than the fat brother, so their soldiers win.

A second use case,

With 4 times of mental retardation, enemy creep IQ will become 1-6-11, using fat Brother's first soldier to defeat the enemy first, the second to win the third, and the third to win the second one.

Exercises

From the test sample can be seen that we have its 22 PK choice, and need to win, so the best horse vs the top horse, inferior horse vs inferior horse, the order is good.

"Code C + +"

1#include <cstdio>2#include <algorithm>3 #defineLL Long Long4LL s1[100005], s2[100005];5 intMain () {6     intT, n, I;7 LL sum;8      while(~SCANF ("%d", &t)) {9          while(t--){Tenscanf"%d", &n); One              for(i =0; I < n; ++i) scanf ("%lld", &s1[i]); A              for(i =0; I < n; ++i) scanf ("%lld", &s2[i]); -Std::sort (S1, S1 + N); Std::sort (s2, s2 +n); -              for(i = sum =0; I < n; ++i) { the                 if(S1[i] + sum <= s2[i]) sum + = S2[i]-s1[i]-sum +1; -             } -printf"%lld\n", sum); -         } +     } -     return 0; +}

Fjnu 1157 fat Brother's Ruozhi Magic (fat Brother's mentally handicapped)

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.