Under construction

Still being built. Things may change

Way Home

Time limit1sMemory limit1024 MB

Summary
Find the minimum number of performances needed to fly from city 1 to city n with starting money p, where each city pays a fixed amount per performance.
Level

Medium6 of 10

Topics
Graph, Shortest path, Greedy
Solved
No attempts yet

Statement

The famous magician Borya Budini was traveling through a country X made up of nn cities. Unfortunately, he was robbed in city 1. Now he has a long road ahead to get home to city nn.

He travels by plane. The country has mm flights. The ii-th flight goes from aia_i to bib_i and costs sis_i. To take a flight, Borya must be in city aia_i and have at least sis_i money on hand, which he spends on the flight.

After the robbery he has only pp rubles left. He does not give up, though. While in city ii, he can give a performance every day, and each performance earns him wiw_i rubles.

Help the magician find out whether he can get home, and if so, the minimum number of performances he must give to do it.

Input

The first line contains four integers nn, mm, pp, and gg (2≤n≤8002 \le n \le 800, 1≤m≤30001 \le m \le 3000, 0≤p≤1090 \le p \le 10^9, 0≤g≤60 \le g \le 6): the number of cities, the number of flights, the initial money, and the test group number.

The second line contains nn integers w1,w2,…,wnw_1, w_2, \ldots, w_n (1≤wi≤1091 \le w_i \le 10^9), the profit from one performance in each city.

Each of the next mm lines contains three integers aia_i, bib_i, and sis_i (1≤ai,bi≤n1 \le a_i, b_i \le n, 1≤si≤1091 \le s_i \le 10^9): the departure city, the destination city, and the price of the ii-th flight.

Output

Print a single integer: the minimum number of performances Borya must give to get home, or −1-1 if it is impossible.

Hint

In the first example, the best plan is to give 4 performances in city 1, which leaves Borya with 2+7⋅4=302 + 7 \cdot 4 = 30 rubles. He then flies the route 1−3−2−41-3-2-4, spending 6+8+11=256+8+11=25 rubles.

In the second example, the best plan is to give 15 performances in city 1, fly to city 3, give 9 performances there, and then fly on to city 4.

Examples4

  1. Example 1

    Input
    4 4 2 0
    7 4 3 1
    1 2 21
    3 2 6
    1 3 8
    2 4 11
    
    Expected output
    4
    
  2. Example 2

    Input
    4 4 10 0
    1 2 10 1
    1 2 20
    2 4 30
    1 3 25
    3 4 89
    
    Expected output
    24
    
  3. Example 3

    Input
    4 4 7 0
    5 1 6 2
    1 2 5
    2 3 10
    3 4 50
    3 4 70
    
    Expected output
    10
    
  4. Example 4

    Input
    4 1 2 0
    1 1 1 1
    1 3 2
    
    Expected output
    -1