Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
The Little Elephant from the Zoo of Lviv likes listening to music.
There are N songs, numbered from 1 to N, in his MP3-player. The song i is described by a pair of integers Bi and Li - the band (represented as integer) that performed that song and the length of that song in seconds. The Little Elephant is going to listen all the songs exactly once in some order.
The sweetness of the song is equal to the product of the length of that song and the number of different bands listened before (including the current playing song).
Help the Little Elephant to find the order that maximizes the total sweetness of all N songs. Print that sweetness.
Input
The first line of the input contains single integer T, denoting the number of test cases. Then T test cases follow. The first line of each test case contains single integer N, denoting the number of the songs. The next N lines describe the songs in the MP3-player. The i-th line contains two space-sparated integers Bi and Li.
Output
For each test, output the maximum total sweetness.
Constraints 1 ≤ T ≤ 5 1 ≤ N ≤ 100000 (105) 1 ≤ Bi, Li ≤ 1000000000 (109)
Example
Input:
2
3
1 2
2 2
3 2
3
2 3
1 2
2 4
Output:
12
16

What I have tried:

i didnt tried this question because i didnt underatand the project
Posted
Updated 19-Oct-16 10:53am
Comments
CHill60 21-Mar-16 9:45am    
This is something you should discuss with your tutor
HobbyProggy 21-Mar-16 9:49am    
We do not do your homework, is it set for you to understand what you have learned.
CPallini 19-Oct-16 16:25pm    
What do you didn't understand, exactly?
Did you understand the requirements?

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
So start by reading the question carefully, and work out what inputs you need. Then find what outputs you need. Then identify what happens in between.
Design the code to handle the inputs, and then start working out how to process them.
If you can't understand the question, then go back to your tutor and ask for clarification.
 
Share this answer
 
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.


Oops, didn't see the date.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900