Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Supervillains are tired of Toronto condo rental prices, so they are leaving Toronto for Mississauga. Luckily, we have n valiant superheroes that can deal with

Supervillains are tired of Toronto condo rental prices, so they are leaving Toronto for Mississauga. Luckily, we have n valiant superheroes that can deal with them. The i-th superhero (0 <= i < n) has a name name[i], an intelligence score in[i], and a strength score s[i]. There are m supervillains flocking to Mississauga. After thorough investigation, Detective Zingaro has determined that the supervillains can be classified into three categories for how to deal with them: A type 1 supervillain has an intelligence score int. Detective Zingaro needs to assign a superhero whose intelligence is at least as much as int to this supervillain. Moreover, to be efficient with his resources, he must assign the superhero with the minimum intelligence who satisfies this requirement. A type 2 supervillain has a strength score st. The detective needs to assign a superhero whose strength is at least as much as st to this supervillain. Similar to above, he must assign the superhero with the minimum strength that meets this requirement. Finally, a type 3 supervillain has a mixed score g, meaning that the superhero x assigned to them needs to have in[x] + s[x] >= g. Again, the detective is interested in the superhero with the smallest in[x] + s[x] that satisfies this requirement.

Detective Zingaro has asked for your help. For each of the supervillains, tell him the name of the superhero that should deal with that supervillain.

Note: A superhero can be assigned to multiple supervillains (or none at all).

Note: whenever there are multiple superheroes that satisfy the given requirements for a supervillain, report the one whose name is lexicographically smallest (i.e. the one that's the smallest according to Python's ordering of strings). It's guaranteed that superheroes have distinct names.

Hint: Tuples of multiple elements may be helpful here. In python, you can compare two tuples (a, b) and (c, d). If a and c are different, the result is the same as comparing a and c. If a and c are equal, the result is the same as comparing b and d. You can even sort these tuples!

Filename

Your filename for this question must be q3.py.

Input

The first line of the input contains a single integer n denoting the number of superheroes.

The next three lines describe the superheroes. The first line contains n space-separated strings, specifying the names of the superheroes. The second line contains n space-separated integers, specifying the list in. Finally, the third line specifies the list s.

The next line contains a single integer m denoting the number of supervillains. m lines will follow describing them, one per line. Each of these lines starts with an integer t denoting the type of the villain (1, 2, or 3), followed by an integer specifying the corresponding threshold.

Output

Your output should consist of m strings separated by spaces. The i-th one should be the name of the superhero assigned to the i-th supervillain. If no superhero meets the requirements for a supervillain, output none for that supervillain instead.

Constraints

  • 1 <= n, m <= 150000
  • Intelligence scores, strength scores, and thresholds are all in range [1, 500000].
  • Superhero names are between 1 and 6 characters long and contain only lowercase English letters.
  • No two superheroes have the same name.
  • No superhero's name is "none"

Time Limit

Your program must finish running on any valid input within 5 seconds.

Sample Input 1

5 batman catman pacman peach mario 1 3 7 10 8 4 7 7 3 1 4  1 4 2 7 3 11 1 11

Sample Output 1

pacman catman peach none

Sample 1 Explanation

  • The first line indicates that there are 5 superheroes.
  • Lines 2-4 describe the superheroes. For instance, the second one is named "catman" and has an intelligence score of 3 and a strength score of 7.
  • Line 5 indicates that there are 4 supervillains to deal with. These supervillains are described in the following 4 lines.
  • For the second supervillain, both catman and pacman satisfy the requirements of Detective Zingaro. However, catman is lexicographically smaller than pacman, so you should report catman as the answer.

Sample Input 2

5 a b c d e 1 2 3 5 8 8 5 3 2 1 6  1 5 3 7 2 1 2 8 3 6 1 4

Sample Output 2

d b e a c d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To solve this problem you can follow the steps 1 Read the input values such as the number of superheroes their names intelligence scores strength scor... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elementary Principles of Chemical Processes

Authors: Richard M. Felder, Ronald W. Rousseau

3rd Edition

978-0471687573, 9788126515820, 978-0-471-4152, 0471720631, 047168757X, 8126515821, 978-0471720638

More Books

Students also viewed these Programming questions

Question

In your opinion, is mental illness currently overdiagnosed?

Answered: 1 week ago