Roy and Trending Topics
Practice
4.1 (25 votes)
Approved
Data structures
Easy
Heaps
Implementation
Open
Priority queue
Sorting
Trees
Problem
82% Success 6692 Attempts 20 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Roy is trying to develop a widget that shows Trending Topics (similar to Facebook) on the home page of HackerEarth Academy.
He has gathered a list of N Topics (their IDs) and their popularity score (say z-score) from the database. Now z-score change everyday according to the following rules:

  1. When a topic is mentioned in a 'Post', its z-score is increased by 50.
  2. A 'Like' on such a Post, increases the z-score by 5.
  3. A 'Comment' increases z-score by 10.
  4. A 'Share' causes an increment of 20.

Now the Trending Topics are decided according to the change in z-score. One with the highest increment comes on top and list follows.
Roy seeks your help to write an algorithm to find the top 5 Trending Topics.
If change in z-score for any two topics is same, then rank them according to their ID (one with higher ID gets priority). It is guaranteed that IDs will be unique.

Input format:
First line contains integer N
N lines follow
Each contains 6 space separated numbers representing Topic ID, current z-score - Z, Posts - P, Likes - L, Comments - C, Shares - S

Output format:
Print top 5 Topics each in a new line.
Each line should contain two space separated integers, Topic ID and new z-score of the topic.

Constraints:
1 ≤ N ≤ 106
1 ≤ ID ≤ 109
0 ≤ Z, P, L, C, S ≤ 109

Sample Test Explanation:
enter image description here

Now sort them according to the change in z-score. Change in z-score for IDs 999, 1001, 1002, 1003 is 100, so sort them according to their ID (one with the higher ID gets priority). Similarly proceed further.

After you get the top 5 list of Topic IDs according to the above criteria, find the new z-score from the table for each ID.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
Data StructuresPriority queueTrees
Points:20
25 votes
Tags:
Data StructuresEasyHash MapsHash TablesHeapsPriority queueTrees
Points:20
29 votes
Tags:
ApprovedData StructuresEasyMapsOpenPriority QueuePriority queueTrees