#P15697. [2018 KAIST RUN Spring] Recipe

[2018 KAIST RUN Spring] Recipe

题目描述

Jaemin likes cooking. He wants to devise several recipes for NN days. He devises a recipe in the following order.

  1. Buy ingredients at a market and put them in a refrigerator.
  2. Think of a recipe.
  3. 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 ii-th day have freshness FiF_i. The freshness FiF_i 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 CiC_i on ii-th day. His cooking skill advances everyday, so 0<CiCj0 < C_i \le C_j for all i<ji < j. If he takes out the ingredients which freshness is FF from the refrigerator and cook with cooking skill CC, a dish with a flavor of F×CF \times C 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 LiL_i. If the ingredients don’t satisfy the requirement, Jaemin cannot cook that day. Jaehyun’s requirement varies everyday, and the requirements for NN days are given as L1,L2,,LNL_1, L_2, \dots, L_N.

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 NN-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 NN-th day because of Jaehyun’s particular requirements, print out “Impossible” (without quotes).

输入格式

Input consists of four lines.

First line contains NN.

Second line contains NN space-separated integers F1,F2,,FNF_1, F_2, \dots, F_N.

Third line contains NN space-separated integers C1,C2,,CNC_1, C_2, \dots, C_N.

Fourth line contains NN space-separated integers L1,L2,,LNL_1, L_2, \dots, L_N.

输出格式

Print the maximum sum of flavors of the dishes Jaemin cooks. If it is impossible to empty the refrigerator on the NN-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

提示

Constraints

  • 2N250,0002 \le N \le 250,000
  • 0<Fi50,0000 < F_i \le 50,000
  • 0<C1CN10,0000 < C_1 \le \dots \le C_N \le 10,000
  • 0Li50,0000 \le L_i \le 50,000