|
| 1 | +# A fashion show rates participants according to their level of hotness. Two different fashion shows were organized, one |
| 2 | +# for men and the other for women. A date for the third is yet to be decided ;) . |
| 3 | +# |
| 4 | +# Now the results of both fashion shows are out. The participants of both the fashion shows have decided to date each |
| 5 | +# other, but as usual they have difficuly in choosing their partners. The Maximum Match dating serive (MMDS) comes to |
| 6 | +# their rescue and matches them in such a way that that maximizes the hotness bonds for all couples. |
| 7 | +# |
| 8 | +# If a man has been rated at hotness level x and a women at hotness level y, the value of their hotness bond is x*y. |
| 9 | +# |
| 10 | +# Both fashion shows contain N participants each. MMDS has done its job and your job is to find the sum of hotness |
| 11 | +# bonds for all the couples that MMDS has proposed. |
| 12 | +# |
| 13 | +# Input |
| 14 | +# |
| 15 | +# The first line of the input contains an integer t, the number of test cases. t test cases follow. |
| 16 | +# |
| 17 | +# Each test case consists of 3 lines: |
| 18 | +# |
| 19 | +# The first line contains a single integer N (1 <= N <= 1000). |
| 20 | +# The second line contains N integers separated by single spaces denoting the hotness levels of the men. |
| 21 | +# The third line contains N integers separated by single spaces denoting the hotness levels of the women. |
| 22 | +# All hotness ratings are on a scale of 0 to 10. |
| 23 | +# |
| 24 | +# Output |
| 25 | +# |
| 26 | +# For each test case output a single line containing a single integer denoting the sum of the hotness bonds for all |
| 27 | +# pairs that MMDS has proposed. |
| 28 | +# |
| 29 | +# Example |
| 30 | +# |
| 31 | +# Input: |
| 32 | +# 2 |
| 33 | +# 2 |
| 34 | +# 1 1 |
| 35 | +# 3 2 |
| 36 | +# 3 |
| 37 | +# 2 3 2 |
| 38 | +# 1 3 2 |
| 39 | +# |
| 40 | +# Output: |
| 41 | +# 5 |
| 42 | +# 15 |
| 43 | + |
| 44 | +testCases = int(input()) |
| 45 | +for _ in range(testCases): |
| 46 | + check = int(input()) |
| 47 | + men = sorted(map(int, input().split()))[::-1] |
| 48 | + women = sorted(map(int, input().split()))[::-1] |
| 49 | + result = 0 |
| 50 | + for i in range(0, check): |
| 51 | + result += men[i] * women[i] |
| 52 | + |
| 53 | + print(result) |
0 commit comments