PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000046. Phân ca tài xế xe buýt (The Bus Driver Problem)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân ca tài xế xe buýt (The Bus Driver Problem)

The Bus Driver Problem

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A city has nn drivers, nn morning routes and nn evening routes. Each driver must receive one of each. A total route length exceeding dd incurs overtime of rr per excess unit. Minimize total overtime cost.

Input

Line 1: n,d,rn,d,r. Line 2: nn morning lengths. Line 3: nn evening lengths.

Output

Print the minimum total overtime cost.

Subtasks

  • Subtask 1 (20 points): 1≤n≤31\le n\le 3; 1≤d≤100001\le d\le 10000; 1≤r≤51\le r\le 5; all route lengths are in [1,10000][1,10000].
  • Subtask 2 (30 points): 1≤n≤201\le n\le 20; 1≤d≤100001\le d\le 10000; 1≤r≤51\le r\le 5; all route lengths are in [1,10000][1,10000].
  • Subtask 3 (50 points): 1≤n≤1001\le n\le 100; 1≤d≤100001\le d\le 10000; 1≤r≤51\le r\le 5; all route lengths are in [1,10000][1,10000].

Examples

Input

2 20 5
10 15
10 15

Output

50

Explanation

Pair the 10 and 15 routes twice. Each driver exceeds 20 by 5, incurring 5⋅5=255\cdot5=25. Total cost is 50.