Dorayaki
InterviewTime limit2sMemory limit2048 MB
Given tastiness values for N fillings and M skins, sum (a+b) times max(a,b) over every filling and skin pair.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
JOI is making dorayaki.
Each dorayaki is made from exactly one filling and one skin. Every filling and skin has a tastiness value, which is a positive integer. There are N kinds of fillings numbered 1 to N, and the tastiness of filling i is Ai. There are M kinds of skins numbered 1 to M, and the tastiness of skin j is Bj.
JOI tries every combination of filling and skin, making N × M dorayaki. The tastiness of each dorayaki is the sum of its filling and skin tastiness, multiplied by the larger of those two values.
Find the total tastiness of all N × M dorayaki.
Input
The input is given in the following format.
N M
A1 A2 … AN
B1 B2 … BM
Output
Print the total tastiness of all N × M dorayaki.
Print only the answer. Do not print any prompt or other text.
Constraints
1 ≦ N ≦ 100.1 ≦ M ≦ 100.1 ≦ Ai ≦ 100(1 ≦ i ≦ N).1 ≦ Bj ≦ 100(1 ≦ j ≦ M).- All input values are integers.