Delicacy

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

There are nn cities numbered from 11 to nn. The delicacy at city ii may provide c_ic\_i units of happiness. The cities are connected by mm one-directional roads, and the roads are numbered from 11 to mm. Road ii begins in city u_iu\_i and ends in city v_iv\_i. It takes w_iw\_i days to travel along road ii. In other words, if one departs from city u_iu\_i and travels along road ii on day dd, then the person will arrive at city v_iv\_i on day d+w_id + w\_i.

W is planning a trip lasting TT days. More specifically, he will depart from city 11 on day 00, travel TT days, and return to city 11 on day TT exactly and finish the trip. Since W is an epicure, once W arrives in a city (including city 11 on day 00 and day TT), he will try the delicacies in that city and gain some units of happiness. If W visits a city multiple times, he is able to gain the units of happiness multiple times. Notice that W may not stop at any city, which means if he arrives in a city and the trip hasn't ended, he must depart the city on the same day.

For the above example, a possible itinerary lasting 1111 days for W is 1212311 \to 2 \to 1 \to 2 \to 3 \to 1. The total units of happiness of the trip is 1313.

Moreover, there are kk food festivals happening at different times. More formally, the ii-th food festival is hosted in city x_ix\_i on day t_it\_i. If W is in city x_ix\_i on t_it\_i-th day, then he will obtain an additional y_iy\_i units of happiness for tasting the delicacies in city x_ix\_i. Now W wants to know the maximum possible units of happiness he may get from the trip.

입력

The input begins with four integers n,m,T,Kn,m,T,K, denoting the number of cities, the number of roads, the length of the trip, and the number of food festivals. The second line contains nn integers c_ic\_i denoting the units of happiness W may obtain from tasting the delicacies in each city. The following mm lines contain three integers u_i,v_i,w_iu\_i,v\_i,w\_i each denoting the start, end, and the days required to travel along road ii. The last kk lines contain three integers t_i,x_i,y_it\_i,x\_i,y\_i on each line, denoting the time of the food festival, the host city, and the additional units of happiness the food festival can provide.

The data guarantees: for all ii, we have u_iv_iu\_i \ne v\_i. However, there might be parallel one-directional roads, or in other words, there may exist 1i<jm1 \le i < j \le m such that u_i=u_ju\_i = u\_j and v_i=v_jv\_i = v\_j. For each city, there exists a road departing the city. The time of the food festivals t_it\_i are distinct.

출력

The output contains only one integer, denoting the maximum possible level of happiness W may obtain from the trip. If W cannot return to city 11 on day TT, output -1.

제한

For all test cases, 1n501 \le n \le 50nm501n \le m \le 5010k2000 \le k \le 2001t_iT1091 \le t\_i \le T \le 10^9. 1w_i51 \le w\_i \le 51c_i525011 \le c\_i \le 525011u_i,v_i,x_in1 \le u\_i, v\_i, x\_i \le n1y_i1091 \le y\_i \le 10^9