Created
October 10, 2016 23:39
-
-
Save ferreiro/8f3ca152aafcd195e786d3b0dbd9bfe8 to your computer and use it in GitHub Desktop.
Problem 1237
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python version: 3 | |
# how to execute? In a bash shell: python3 problem1.py < testCases.txt > testCases.mio | |
import sys | |
total_cases = int(input()) # reads the total cases from stdin | |
solution = "" | |
for i in range(0, total_cases): | |
db_size = int(input()) | |
elements = [] | |
for j in range(0, db_size): | |
entry = str(input()) # read the model from | |
tokens = entry.split(" ") # separate [BRAND, LOW_PRICE, HIGH_PRICE] | |
# Push the element to the database (elements) | |
elements.append({ | |
"name": tokens[0], | |
"low": int(tokens[1]), | |
"high": int(tokens[2]) | |
}) | |
total_queries = int(input()) | |
for j in range(0, total_queries): | |
query = int(input()) | |
result = list(filter(lambda x: query in range(x["low"], x["high"] + 1), elements)) | |
if len(result) == 1: | |
solution += str(result[0]["name"]) | |
else: | |
solution += str("UNDETERMINED") | |
if j < total_queries - 1: | |
solution += "\n" | |
if i < total_cases - 1: | |
solution += "\n\n" | |
sys.stdout.write(solution) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment