Cooking
시간 제한1초메모리 제한512 MB
각 요리 i가 정확히 a_i번 등장하도록 요리 두 개(같아도 됨)를 짝지어 총 조리 시간을 최소화하고, 불가능하면 -1을 출력한다.
문제
Stephen and Sergey are enrolled at the university and live on campus. So now they need to learn to cook.
The friends have learned to cook different dishes. After buying all the necessary food, the guys have decided that before they go shopping next time, they will cook the -th dish exactly times.
Each day Sergey and Stephen choose two dishes and and cook them, cooking takes units of time. It's possible that , that means that the -th dish is cooked twice on that day.
The guys are quite lazy, so they want to minimize the total cooking time for all the days before the next shopping. Help them to do it!
입력
The first line contains a single integer () --- the number of dishes that the guys can cook.
The second line contains positive integers () --- the number of times it must be cooked for each dish.
The next lines contain space separated integers (), the -th number in the -th line denotes cooking time of pair of dishes and . It is guaranteed that .
출력
Print one integer: the minimum total time of cooking, or , if it is impossible to make a cooking plan such that the -th dish is cooked exactly times.
힌트
In the first test case it is optimal to cook the following pairs of dishes: , , .