Yet Another Contest 1 P1 - Mixed Doubles

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 0.3s
Java 1.0s
Python 1.0s
Memory limit: 256M

Author:
Problem types

Mike is in charge of coaching a tennis club, and the mixed doubles tournament against other clubs is soon approaching!

The club contains N men and N women, and Mike must form N pairs; each pair must contain a man and a woman, such that each player is in exactly one pair.

The i-th man has a skill level of ai, and the i-th woman has a skill level of bi. If the i-th man and j-th woman are paired, then the skill level of the pair is ai×bj. Mike wants the team to do well as a whole, so he aims to maximise the total skill level of all pairs.

There are K minutes before the tournament starts. In each minute, Mike can train exactly one man or woman, increasing their skill level by 1.

What is the maximum possible sum of the skill level of all pairs once the tournament starts? Because the answer may be very large, output the answer modulo 109+7.

Constraints

1N2×105

0K109

1ai,bi2×109

Subtask 1 [10%]

K=0

1ai,bi2×105

Subtask 2 [40%]

K2×105

1ai,bi2×105

Subtask 3 [50%]

No additional constraints.

Input Specification

The first line contains two space separated integers N, K.

The next line contains N space separated integers, a1,a2,,aN, representing the initial skill level of the men.

The next line contains N space separated integers, b1,b2,,bN, representing the initial skill level of the women.

Output Specification

On a single line, print the maximum possible sum of the skill levels of all pairs, modulo 109+7.

Sample Input

Copy
3 2
4 7 6
2 5 6

Sample Output

Copy
94

Explanation

In the first minute, Mike can increase the skill level of the second man.

In the second minute, Mike can increase the skill level of the third woman.

Mike can then pair the first man and the first woman, the second man and the third woman, as well as the third man and the second woman.

The total sum of skill levels of all pairs would be 4×2+8×7+6×5=94. It can be shown that this is the maximum possible total skill level.


Comments

There are no comments at the moment.