Aquarium
Time limit1sMemory limit128 MB
For each query, decide if a fish survives x days when each day fish act largest first and each eats the smallest smaller fish to gain half its mass.
- Level
Medium6 of 10
- Topics
- Simulation, Sorting, Two pointers, Math
- Solved
- No attempts yet
Problem
Kozik keeps an aquarium of African fish. Each fish has a mass and an age, and every day it must satisfy its hunger by eating one other, smaller fish; a fish that cannot eat dies at the end of that day.
Each day the fish act one at a time. The hungry fish with the greatest mass acts first; if several fish share the greatest mass, the oldest of them acts first. The acting fish devours the smallest fish currently in the aquarium; if several fish share the smallest mass, the youngest of them is eaten. When a fish devours another, its mass grows by half of the eaten fish's mass, and it is no longer hungry that day. If, when it is a fish's turn, no smaller fish is left to eat, that fish starves and dies at the end of the day.
Fish are compared first by mass, and for equal masses the younger fish counts as smaller. All ages are distinct, so this order is total, while masses may repeat. A fish can only devour a fish that is smaller than itself under this order.
For a chosen fish and a number of days , decide whether fish is still alive after days, where means right now.
Input
The first line contains an integer (), the number of fish.
Each of the next lines contains two integers and (), the mass and the age of the -th fish.
The next line contains an integer (), the number of queries.
Each of the next lines contains two integers and (, ), asking whether fish is still alive after days.
Output
For each query, print TAK if fish is still alive after days, or NIE otherwise. Here TAK means yes and NIE means no. Print one answer per line, in the order of the queries.