View problem - Programming Contest (POI11_pro)

Time limitMemory limit# of submissions# of submitted usersSolved #Accepted user ratio
1000 ms32 MiB74201365.00%

Bartie and his friends compete in the Team Programming Contest. There are nn contestants on each team, and each team has access to nn computers. The contest lasts tt minutes, during which the contestants are to solve mm programming problems. Furthermore, penalties are imposed on the teams: solving a problem ss minutes since the beginning of the contest amounts to ss penal points. The team that solved the most problems wins the contest, with ties broken in favour of the team with smaller penalty.

On the contest day Bartie quickly glances over the problem statements and distributes them among his teammates. He knows his team so well that he can exactly assess who is able to solve which problem. Solving any problem takes any contestant that is able to solve it exactly rr minutes of using the computer.

Bartie's team did not fare well in this year's contest. Bartie is obsessed with the thought that it might be his fault, due to wrong decisions regarding the distribution of problems. He asks you to write a program that, given what Bartie knew at the beginning of the contest, determines the best possible result of Bytie's team, together with the assignment of problems to team members that attains the result.

Input

Five integers nn, mm, rr, tt, and kk (1n,m5001 \le n,m \le 500, 1r,t1,000,0001 \le r,t \le 1,000,000) are given in the first line of the standard input, separated by single spaces. These denote, respectively: the number of contestants on a team, the number of problems, the time it takes a contestant to solve a problem, the duration of the contest, and the number of contestant-problem pairs given on the input. Each of the following kk lines holds two integers aa and bb (1an,1bm1 \le a \le n, 1 \le b \le m), separated by a single space, denoting that the contestant aa is able to solve the problem bb. Each such pair appears at most once in the input.

In tests worth at least 30% of the points it additionally holds that n,m100n,m \le 100.

Output

In the first line of the standard output the best possible result of Bytie's team should be printed as two numbers separated by a single space: the number of solved problems zz and the total penal points. An exemplary assignment of problems that attains this result should be given in the following zz lines. Each of those should hold three integers aa, bb and cc (1an1 \le a \le n, 1bm1 \le b \le m, 0ctr0 \le c \le t-r), separated by single spaces, signifying that the contestant aa should start solving the problem bb at time cc (the contest starts at time 0). No contestant should be assigned a problem that they cannot solve. If more that one optimal assignment exists, your program can output any of them.

Example

For the input data:

2 4 3 15 4
1 1
2 3
1 4
1 3

the correct result is:

3 12
1 4 0
2 3 0
1 1 3

Task author: Tomasz Idziaszek.