| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14809 | Trump's Tariff |
|
| 14810 | Gyro Zeppeli |
|
Description
![]()
Trump is on the move. Tariff after tariff, he put on other countries.
You, a good American citizen, will help Trump automate his tariff using a combination of functions.
Given T countries that have money and their old tariff. You are given N simple functions that define a function composition F, F(old_tariff_rate) is the new tariff rate. Trump wants you to calculate the potential money that he will get for the great USA. Which is the sum of all countries new_tariff_rate * money.
Given this code:
class Country:
def __init__(self, money, tariff):
self.money = money
self.tariff = tariff
def func_comp(*funcs):
# Do something here
return F
t, n = map(int, input().split())
countries = {}
for _ in range(t):
line = input().split()
country_name, money, tariff_start = \
line[0], float(line[1]), float(line[2])
countries[country_name] = Country(money, tariff_start)
function_list = []
for _ in range(n):
line = input().split()
command = line[0]
num = int(line[1])
if command == "add":
# Do something
pass
elif command == "sub":
# Do something
pass
elif command == "div":
# Do something
pass
elif command == "mul":
# Do something
pass
elif command == "mod":
# Do something
pass
F = func_comp(*function_list)
# Continue this code
For each country:
- Let
new_tariff_rate = F(old_tariff_rate), (rate is a percentage, so for example if rate is 25, it means 25%) - The money each country has to pay is
min(country_money, country_money * (new_tariff_rate / 100))
You will receive N lines of either one of these mini-functions:
-
add vmeans return x + v -
sub vmeans return x - v -
mul vmeans return x * v -
div vmeans return x / v -
mod vmeans return x % v
Your task is to create a function composition of these functions. For example, you are given:
mul 2
div 3
sub 0
mod 0
Your F function will equal:
> Note: remember to handle zero division error, for example x / 0 and x % 0, just return xHint
func_comp function returns a function
Input
The first line contains T and N,
T = the number of countries you will need to put a tariff on
N = the number of mini functions you will get to recalculate the next tariff rate
The next T lines you will get: country_name, country_money, country_old_tariff_rate
where:
- country_name is unique for each country
- country_money is a floating number
- country_old_tariff_rate is a floating number
The next N lines you will get: command, number
where:
- command is either add | sub | mul | div | mod
- number is an integer
Constraints
T<= 1000N<= 1000numbercan be negativecountry_moneyis never negative
Output
Output T countries and their money after the tariff is paid.
Output Trump's money, which is the sum of the money paid by all T countries
Format all floating numbers to 1 decimal place in the output.
e.g. 2.6667 = 2.7
Sample Input Download
Sample Output Download
Tags
Discuss
Description

Gyro Zeppeli is a Jojo character who utilizes "Golden ratio" to fight enemies. "Golden ratio" is the ratio you get when you divide a number in a Fibonacci sequence, Fn+1/Fn for n = infinity. The ratio is 1.618.
Given N commands and K length, you are asked to implement a list of numbers and generators that get manipulated by N commands and output the first K numbers.
The list's element is either:
- An integer
- A generator
Given this code:
# You need to implement this
pass
def filter_gen(gen, condition):
for x in gen:
if condition(x):
yield x
Implement:
- fib_gen() function, which is a generator function for a Fibonacci sequence. (use yield)
e.g. 0, 1, 1, 2, 3, 5, 8, 12, ... - fib index limit: It appends a
limitedFibonacci sequence generator to the list at the givenindex. - push index value: It appends an integer
valueto the list at the givenindex. - pop index: It removes an integer or a whole generator from the list at the given
index. - filter comparison value: It filters all the integers inside the list (including the generators) based on the
comparisonand thevaluegiven.
For example, in sample input two:
10 10, means we are given 10 commands, and 10 numbers to output
fib 0 100, means push the first 100 Fibonacci generator to index 0. Your list now should look like this: [fib(0 to 100)]
push 1 10, means push the integer 10 to index 1. Your list now should look like this: [fib(0 to 100), 10]
push 0 15, means push the integer 15 to index 0. Your list now should look like this: [15, fib(0 to 100), 10]
push 0 150, means push the integer 150 to index 0. Your list now should look like this: [150, 15, fib(0 to 100), 10]
pop 1, means remove the index 1. Your list now should look like this: [150, fib(0 to 100), 10]
filter higher 20, means filter everything in your list only to remain every number that is higher than 20. Your list now should look like this: [150, filter(fib_gen(0 to 100, higher than 20))]
fib 0 15, means push the first 15 Fibonacci generator to index 0. Your list now should look like this: [fib(0 to 15), 150, filter(fib(0 to 100, higher than 20))]
filter lower 100, means filter everything in your list only to remain every number that is lower than 100. Your list now should look like this: [filter(fib(0 to 15), lower than 100), filter(filter(fib(0 to 100, higher than 20)), lower than 100)]
pop 0, means remove the index 0. Your list now should look like this: [filter(filter(fib(0 to 100, higher than 20)), lower than 100)]
push 0 100, means push the integer 100 to index 0. Your list now should look like this: [100, filter(filter(fib(0 to 100, higher than 20)), lower than 100)]
Therefore, your first 10 numbers should be 100, 34, 55, 89
Input
The first line is 2 integers, N and K, where:
N= the number of commandsK= the number of numbers you have to output. (generator is not a number)
The next N line will be either of these commands, in this format:
fib index limitpush index valuepop indexfilter comparison value
Constraints
comparisonis eitherlower|higherindexis never out of bounds.limit<= 5000valueis an integer
>Note: lower is < and higher is > (not equal to)
Output
Output K number from the list starting from the front.
If K > len(list), output len(list) numbers.