14996 - Lucky Queue   

Description

A pay-to-win Roblox game is hosting an event, they want to gift their loyal gamers some Robux. They would like to surprise the players in the waiting room.

When the announcement is made, there are already groups waiting in the room. There are also groups still logging in, these groups join the back of the queue, in the order given, and are included in the draw.

You are the developer tasked to build the algorithm to determine which group and how many Robux the owner of the game have to gift.

Here are the rules:

  • Counting from the front of the queue, groups at positions 1, k+1, 2k+1, … win. (Every k-th group, starting with the first.)
  • Every player in a winning group receives 67 Robux.

Input

The first line is the current queue, given as pairs of a group name and its size: group1 size1 group2 size2 …

The second line is the incoming queue, in the same format. This line may be blank if no new groups are logging in.

The third line is an integer k.

This link may help you in processing the input: https://www.geeksforgeeks.org/python/zip-in-python/

Constraints:

  • The current queue contains at least 1 group.
  • Group names contain no spaces. Group names consist of letters and digits only.
  • 1 <= group size <= 100
  • 1 <= total number of groups <= 1000
  • 1 <= k <= 1000 (k may exceed the number of groups)

Output

The first line is a Python list of the names of the winning groups, in queue order.

The second line is the total amount of Robux the game owner has to spend.

Sample Input  Download

Sample Output  Download

Tags




Discuss