14809 - Trump's Tariff   

Description

Donald Trump: Latest News, Top Stories & Analysis - POLITICO

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 FF(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 v means return x + v
  •     sub v means return x  - v
  •     mul v means return x * v
  •     div v means return x / v
  •     mod v means return x % v

Your task is to create a function composition of these functions. For example, you are given: 

add 2
mul 2
div 3
sub 0
mod 0

 

Your F function will equal:

F(x) = (((((x + 2) * 2) / 3) - 0) % 0)
 
> Note: remember to handle zero division error, for example x / 0 and x % 0, just return x
 

Hint

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 <= 1000
  • N <= 1000
  • number can be negative
  • country_money is 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