No.3409 How Many Gift Boxes?
Problem Statement
In one section of Santa Claus's warehouse, cube-shaped gift boxes are stacked.
This section is a grid of $H$ cells in the north-south direction and $W$ cells in the east-west direction, and each cell has the same size as a gift box.
Each cell of the grid has $0$ or more gift boxes stacked on it.
Viewing this grid from the west reveals that, for the cells lined up in the east-west direction in the $i$-th row from the north $(1\le i\le H)$, the maximum number of gift boxes stacked is $A_i$.
Similarly, viewing this grid from the south reveals that, for the cells lined up in the north-south direction in the $j$-th column from the west $(1\le j\le W)$, the maximum number of gift boxes stacked is $B_j$.
Find the minimum and maximum among the possible total numbers of gift boxes stacked in the grid.
Since the answers can be very large, output them modulo $10^9+7$.
Constraints
- $1\le H\le 10^5$
- $1\le W\le 10^5$
- $0\le A_i,B_j\le 10^9$
- There exists a way of stacking gift boxes that satisfies the conditions
- All inputs are integers
Input
The input is given from standard input in the following format.
$H\ W$ $A_1\ A_2\ \dots\ A_H$ $B_1\ B_2\ \dots\ B_W$
Output
Output $2$ lines.
On line $1$, output the minimum.
On line $2$, output the maximum.
Sample
Sample 1
Input
3 5 1 3 2 0 1 3 2 1
Output
7 17
When the numbers of gift boxes stacked on the cells are as follows, the total number of gift boxes is $7$. The total number of gift boxes cannot be $6$ or less.
0 1 0 0 10 0 3 0 00 0 0 2 0
When the numbers of gift boxes stacked on the cells are as follows, the total number of gift boxes is $17$. The total number of gift boxes cannot be $18$ or more.
0 1 1 1 10 1 3 2 10 1 2 2 1
Sample 2
Input
4 3 100000000 100000000 100000000 100000000 100000000 100000000 100000000
Output
400000000 199999993
Note that you must output the values modulo $10^9+7$.
Sample 3
Input
5 4 1 1 1 1 4 1 2 2 4
Output
12 25
Sample 4
Input
12 16 54 70 63 91 44 64 56 75 62 69 49 74 82 43 72 3 63 82 56 91 56 4 47 1 54 64 79 48
Output
1288 8899
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tetra4