atcoder#ARC144B. [ARC144B] Gift Tax
[ARC144B] Gift Tax
Score : points
Problem Statement
You are given positive integers and such that , and a sequence of positive integers .
On this sequence, you can perform the following operation any number of times (possibly zero):
- Choose distinct indices (). Add to and subtract from .
Find the maximum possible value of after your operations.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible value of after your operations.
3 2 2
1 5 9
5
Here is one way to achieve .
- Perform the operation with . becomes .
- Perform the operation with . becomes .
3 2 3
11 1 2
3
Here is one way to achieve .
- Perform the operation with . becomes .
- Perform the operation with . becomes .
- Perform the operation with . becomes .
- Perform the operation with . becomes .
3 1 100
8 5 6
5
You can achieve by not performing the operation at all.
6 123 321
10 100 1000 10000 100000 1000000
90688