#futurecontest2022quala. [future_contest_2022_qual_a]Project Leader

[future_contest_2022_qual_a]Project Leader

Story

You have been hired as a project leader of F Corporation. Your job is to assign tasks to team members appropriately. The current project consists of a number of tasks. The expected number of days for a team member to complete a task depends on skill levels of the team member and required skill levels for the task. You are highly experienced and can accurately estimate the required skill levels for each task, but since you have just joined the team, you do not yet know the skill levels of each team member at all. Please assign tasks appropriately while gradually evaluating the skill levels of team members.

Problem Statement

You want to assign NN tasks to MM team members. You can assign each task to at most one team member, and once you assign a task to a team member, you cannot assign another task to him/her until he/she completes the task. There are KK types of skills. Each team member jj has a non-negative integer vector bmsj=(sj,1,cdots,sj,K)\\bm{s_j} = (s_{j,1},\\cdots,s_{j,K}) representing skill levels, and each task ii has a non-negative integer vector bmdi=(di,1,cdots,di,K)\\bm{d_i} = (d_{i,1},\\cdots,d_{i,K}) representing required skill levels. Among these, the skill levels bms1,cdots,bmsM\\bm{s_1},\\cdots,\\bm{s_M} are not given as input.

We define wi,j:=sumk=1Kmax(0,di,ksj,k)w_{i,j}:=\\sum_{k=1}^K \\max(0,d_{i,k}-s_{j,k}). Then, it takes ti,jt_{i,j} days for team member jj to complete task ii, where ti,jt_{i,j} is defined as follows.

  1. If wi,j=0w_{i,j}=0, ti,j=1t_{i,j}=1.
  2. If wi,j>0w_{i,j}>0, ti,j=max(1,wi,j+ri)t_{i,j}=\\max(1,w_{i,j}+r_i), where rir_i is a uniform random integer between \-3\-3 and 33, inclusive.

When a task taking tt days is started on day dd, the task will be completed at the end of day d+t1d+t-1. There are dependencies between tasks, and before starting a task, all of its dependent tasks must have been completed by the end of the previous day. Please complete all tasks in as few days as possible.

Input and Output

For the range of each input value, see Input Generation.

At the start of the execution, the number of tasks NN, the number of team members MM, the number of skills KK, the number of dependencies RR, required skill levels for each task bmd1,cdots,bmdN\\bm{d_1},\\cdots,\\bm{d_N}, and a list of pairs of dependent tasks (u1,v1),cdots,(uR,vR)(u_1,v_1),\\cdots,(u_R,v_R) are given from Standard Input in the following format.

NN MM KK RR d1,1d_{1,1} cdots\\cdots d1,Kd_{1,K} vdots\\vdots dN,1d_{N,1} cdots\\cdots dN,Kd_{N,K} u1u_1 v1v_1 vdots\\vdots uRu_R vRv_R

(ui,vi)(u_i,v_i) indicates that the task viv_i (1leqvileqN1\\leq v_i\\leq N) depends on the task uiu_i (1lequileqN1\\leq u_i\\leq N) and that uiu_i must be completed before starting viv_i. It satisfies ui<viu_i<v_i, and the same (ui,vi)(u_i,v_i) pair appears at most once in the input.

Then, starting from day 1, do the following two processes every day.

First, output to Standard Output a list of pairs (a1,b1),cdots,(am,bm)(a_1,b_1),\\cdots,(a_m,b_m) such that team member aia_i (1leqaileqM1\\leq a_i\\leq M) starts task bib_i (1leqbileqN1\\leq b_i\\leq N) on that day in one line in the following format.

mm a1a_1 b1b_1 cdots\\cdots ama_m bmb_m

After the output, you have to flush Standard Output. Otherwise, the submission might be judged as TLE