Time limit
2s
Memory limit
128 MB
For N cars that traveled along a road, you are given N recorded entry times and N recorded exit times. The records were shuffled, so it is unknown which entry time belongs to which exit time.
Each car must be matched to one entry time and one exit time, and the exit time must be strictly later than the entry time. Every time must be used exactly once. If it is impossible to make N such pairs, the input is impossible.
Suppose a car takes S seconds to pass through the road, and the speeding threshold is T seconds. If S < T, the fine is min((T - S)^2, F). If S >= T, there is no fine.
Among all valid matchings, find the minimum and maximum possible total fine.
The first line contains the number of cars N. N is a positive integer not greater than 50.
The second line contains N entry times separated by spaces.
The third line contains N exit times separated by spaces.
Every time is an integer between 0 and 1000, inclusive.
The fourth line contains the speeding threshold T. The fifth line contains the maximum fine F that can be charged for one car. T is a positive integer between 1 and 1000, inclusive, and F is an integer between 0 and 10000, inclusive.
Print two integers separated by a space: the minimum possible total fine and the maximum possible total fine.
If the given times cannot form N valid pairs, print -1.