Balloons
Time limit1sMemory limit128 MB
Given stock counts for n balloon colors and m orders, decide whether each child can receive the requested number of distinct-colored balloons.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Math, Combinatorics
- Solved
- No attempts yet
Problem
A group of children came to a toy store. Each of them wants to buy some balloons. The children like variety, so none of them wants to own two balloons of the same colour. In other words, all balloons bought by a single child must have different colours. Help the shop assistant decide whether every child's order can be filled from the store's current stock.
Write a program that:
- reads the store's stock and the children's orders from standard input,
- checks whether all children can be satisfied,
- writes the result to standard output.
Input
The first line contains two integers and (, ), separated by a single space, where is the number of distinct balloon colours in the store and is the number of children.
The second line contains integers (), separated by spaces, giving the stock of each colour.
The third line contains integers (), separated by spaces, giving the children's orders. means the -th child wants to buy balloons, all of different colours.
Output
Print TAK (Polish for yes) on the only line if every child's order can be filled, and NIE (Polish for no) otherwise.