#P9499. 「RiOI-2」change
「RiOI-2」change
Background
Little E finally got back her New Year’s money that her mom had been keeping for her today.
As a far-sighted collector, Little E knows that if she starts collecting things from now on, they will become valuable in the future.
In Little E’s world, there are some banknotes. She knows their future value, but unfortunately, these banknotes can only be exchanged from smaller to larger. What should she do?
Problem Description
You are given types of items. For each item , its value is and its quantity is .
Define the total value as . You may perform some (possibly ) operations to maximize the total value.
One operation is: choose an such that , set , and .
Output the maximum total value modulo .
Note: You need to maximize the total value first, and then take modulo , rather than maximizing “(total value modulo )”.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , indicating the subtask ID of this testdata.
The second line contains a positive integer , indicating the number of test cases. For each test case:
- The input consists of four lines.
- The first line contains a positive integer , the number of types of money.
- The second line contains non-negative integers: .
- The third line contains non-negative integers: .
- The fourth line contains positive integers: .
Output Format
Output lines. Each line contains one integer, the maximum total value of the items. All answers are taken modulo .
0
2
2
1 5
5 1
4
10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
11
172998509
Hint
Sample Explanation
For the first test case of the sample, , , . You can choose and perform one operation. Then , and the total value is . It can be proven that this is the maximum.
Constraints and Notes
This problem uses bundled tests.
Below are the special properties of each Subtask. A slash indicates no special restriction in that column.
| Special Property | Score | |||
|---|---|---|---|---|
| / | Special Property A | |||
| Special Property B | ||||
| Special Property C | ||||
| / | ||||
| / | ||||
| / | ||||
- Special Property A: .
- Special Property B: .
- Special Property C: all are generated uniformly at random in ; all are generated uniformly at random in .
For all testdata, , , , , .
upd: One more hack testdata set was added, with equal to .
Translated by ChatGPT 5