#P8365. [LNOI2022] 吃
[LNOI2022] 吃
Problem Description
Little A really likes eating.
There are portions of food in front of Little A. The -th portion has parameters and . Little A can eat these portions in any order. When she eats the food numbered , she may choose to multiply her weight by , or add to her weight. Each portion of food must be eaten exactly once.
Little A's initial weight is . Please find the maximum weight she can reach after eating all portions of food. The answer may be very large; you only need to output it modulo .
Note: You need to maximize the weight first, and then take the maximum value modulo , rather than maximizing the value of (weight modulo ).
Input Format
The first line contains an integer , the number of portions of food. The second line contains integers , and the third line contains integers , describing the parameters of each portion.
Output Format
Output one integer, the maximum weight Little A can obtain modulo .
5
1 2 3 4 5
100 200 300 400 500
18060
Hint
[Sample Explanation #1]
The following plan can achieve the maximum weight:
- Eat the first portion and choose to increase the weight by , making the weight .
- Eat the second portion and choose to increase the weight by , making the weight .
- Eat the third portion and choose to multiply the weight by , making the weight .
- Eat the fourth portion and choose to multiply the weight by , making the weight .
- Eat the fifth portion and choose to multiply the weight by , making the weight .
[Sample #2]
See food/food2.in and food/food2.ans in the attachment.
This sample satisfies and special property E.
[Sample #3]
See food/food3.in and food/food3.ans in the attachment.
This sample satisfies and special property E.
[Sample #4]
See food/food4.in and food/food4.ans in the attachment.
This sample satisfies .
[Sample #5]
See food/food5.in and food/food5.ans in the attachment.
This sample satisfies special property A.
[Sample #6]
See food/food6.in and food/food6.ans in the attachment.
This sample satisfies special property C.
[Sample #7]
See food/food7.in and food/food7.ans in the attachment.
This sample satisfies special property D.
[Sample #8]
See food/food8.in and food/food8.ans in the attachment.
This sample satisfies special property B.
[Sample #9]
See food/food9.in and food/food9.ans in the attachment.
[Constraints]
For of the testdata, , .
| Test Point ID | Special Properties | |
|---|---|---|
| DE | ||
| E | ||
| AE | ||
| E | ||
| DE | ||
| E | ||
| D | ||
| None | ||
| BD | ||
| B | ||
| C | ||
| None | ||
Special property A: .
Special property B: .
Special property C: are generated independently and uniformly at random within .
Special property D: .
Special property E: .
Translated by ChatGPT 5