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

#BS0000351. Đường đến rạp chiếu phim (Road to Cinema)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đường đến rạp chiếu phim (Road to Cinema)

Road to Cinema

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Vasya wants to travel from a car rental service to a cinema before his film starts in tt minutes. The straight road is ss km long, from coordinate 00 to coordinate ss. There are kk fuel stations where refuelling is free and instantaneous, subject to the tank capacity.

The rental service has nn cars. Car ii costs cic_i to rent and has a tank holding viv_i litres. Each car starts with a full tank. Vasya can switch between the following driving modes whenever he wants:

  • Normal: one kilometre takes 22 minutes and uses 11 litre of fuel.
  • Accelerated: one kilometre takes 11 minute and uses 22 litres of fuel.

Determine the cheapest rental that allows Vasya to arrive no later than the start of the film.

Input

  • The first line contains integers n,k,s,tn,k,s,t: the numbers of cars and fuel stations, the road length in km and the time available in minutes.
  • Each of the following nn lines gives ci,vic_i,v_i, the rental price and tank capacity of car ii.
  • The last line contains the kk station coordinates g1,g2,…,gkg_1,g_2,\ldots,g_k in arbitrary order.

Output

Print the minimum rental price as an integer, or -1 if no car can meet the deadline.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 1≤k≤81\le k\le 8; 2≤s≤1092\le s\le 10^9; 1≤t≤2⋅1091\le t\le 2\cdot10^9; 1≤ci,vi≤1091\le c_i,v_i\le 10^9 for all 1≤i≤n1\le i\le n; 1≤gj≤s−11\le g_j\le s-1 for all 1≤j≤k1\le j\le k; the gjg_j are pairwise distinct.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 1≤k≤10001\le k\le 1000; 2≤s≤1092\le s\le 10^9; 1≤t≤2⋅1091\le t\le 2\cdot10^9; 1≤ci,vi≤1091\le c_i,v_i\le 10^9 for all 1≤i≤n1\le i\le n; 1≤gj≤s−11\le g_j\le s-1 for all 1≤j≤k1\le j\le k; the gjg_j are pairwise distinct.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤k≤2000001\le k\le 200000; 2≤s≤1092\le s\le 10^9; 1≤t≤2⋅1091\le t\le 2\cdot10^9; 1≤ci,vi≤1091\le c_i,v_i\le 10^9 for all 1≤i≤n1\le i\le n; 1≤gj≤s−11\le g_j\le s-1 for all 1≤j≤k1\le j\le k; the gjg_j are pairwise distinct.

Examples

Input 1

3 1 8 10
10 8
5 7
11 9
3

Output 1

10

Explanation

The station divides the road into lengths 33 and 55. The car costing 1010 can drive the first 33 km in accelerated mode in 33 minutes using 66 litres. After refuelling, it drives 22 km normally and 33 km accelerated, taking 4+3=74+3=7 minutes and using 2+6=82+6=8 litres. Total: 1010 minutes. The cheaper car has only 77 litres; at most 22 km of the second leg can be accelerated, so the trip takes at least 3+8=113+8=11 minutes. The remaining car is more expensive.

Input 2

2 2 10 18
10 4
20 6
5 3

Output 2

20

Explanation

The legs have lengths 3,2,53,2,5. The car costing 1010 cannot cross the final 55 km with a 44-litre tank. With the car costing 2020, the first two legs take 3+2=53+2=5 minutes in accelerated mode. On the last leg, accelerating for 11 km and driving normally for 44 km uses 66 litres and takes 1+8=91+8=9 minutes. Total time is 1414, within 1818.