#P15697. [2018 KAIST RUN Spring] Recipe
[2018 KAIST RUN Spring] Recipe
题目描述
Jaemin likes cooking. He wants to devise several recipes for days. He devises a recipe in the following order.
- Buy ingredients at a market and put them in a refrigerator.
- Think of a recipe.
- Take out ingredients from the refrigerator and cook.
He can devise a recipe with such a simple way. He wants to cook delicious food as much as possible.
There are new ingredients in the market daily. The ingredients sold on -th day have freshness . The freshness of the ingredients in the refrigerator decreases by 1 everyday. If the ingredients are in the refrigerator, he doesn’t buy more ingredients until he cooks with them.
He has cooking skill on -th day. His cooking skill advances everyday, so for all . If he takes out the ingredients which freshness is from the refrigerator and cook with cooking skill , a dish with a flavor of is made. When he cooks, he invites his friend Jaehyun, who is very hygienic, so Jaemin hopes that the ingredients in the refrigerator have freshness greater than or equal to . If the ingredients don’t satisfy the requirement, Jaemin cannot cook that day. Jaehyun’s requirement varies everyday, and the requirements for days are given as .
After he cooks a new dish, he goes to the market the next day to buy new ingredients and think of a new recipe again. Everyday, he may go to the market to buy ingredients, cook, or do nothing for devising a recipe (It is also possible to cook on the day he purchases the ingredients). On the first day, there aren’t any ingredients in the refrigerator, he goes to the market to buy some ingredients. On the -th day, he must cook and empty the refrigerator. Let’s find the maximum sum of a flavor of the dishes he cooks. If it is impossible to empty the refrigerator on the -th day because of Jaehyun’s particular requirements, print out “Impossible” (without quotes).
输入格式
Input consists of four lines.
First line contains .
Second line contains space-separated integers .
Third line contains space-separated integers .
Fourth line contains space-separated integers .
输出格式
Print the maximum sum of flavors of the dishes Jaemin cooks. If it is impossible to empty the refrigerator on the -th day, print out “Impossible” (without quotes).
3
10 1 1
1 2 3
1 1 1
24
3
10 1 1
1 2 3
10 10 10
Impossible
10
3 4 1 5 9 2 6 5 3 5
10 11 12 13 14 15 16 17 18 19
1 4 1 4 2 1 3 5 6 2
526