#K41017. Least Productive Team

    ID: 26772 Type: Default 1000ms 256MiB

Least Productive Team

Least Productive Team

You are given n employees and k projects. Each employee has a percentage of project completion for each project. You are also provided with several queries. Each query specifies a list of project indices in a given priority order. For each query, your task is to determine the least productive team based on the following rules:

  • For the first project in the query, identify the minimum completion percentage among all employees. Only consider those employees whose completion percentage equals this minimum.
  • Then for the next project in the query, among the remaining employees, only keep those with the minimum completion percentage for that project.
  • If at any point a single employee remains, that employee is the answer.
  • If after processing all projects in the query more than one employee remain, choose the employee with the smallest total sum of the given projects' completion percentages.
  • The employee ID is 1-indexed.

The mathematical formulation for selecting the team in each query is as follows:

Let \(R\) be the set of candidate employees. For each project \(p_i\) in the query, update \[ R = \{ r \in R \mid percentage(r, p_i) = \min_{s \in R} percentage(s, p_i) \}. \] If \(|R| > 1\) after processing all projects, select the employee \(r\) for which \(\sum_{p_i \in Q} percentage(r, p_i)\) is minimum.

inputFormat

The input is read from standard input (stdin) in the following format:

  1. The first line contains two integers \(n\) and \(k\), representing the number of employees and the number of projects.
  2. The next \(n\) lines each contain \(k\) integers. The \(j\)-th integer in the \(i\)-th line represents the completion percentage of project \(j\) by employee \(i\).
  3. The following line contains a single integer \(q\), the number of queries.
  4. The next \(q\) lines describe the queries. Each query begins with an integer \(x\) (the number of projects in this query), followed by \(x\) distinct integers representing the project indices in the priority order.

outputFormat

For each query, output the unique ID (1-indexed) of the least productive team on a separate line to standard output (stdout).

## sample
4 4
75 60 80 55
65 75 60 85
80 70 50 60
90 55 65 75
3
2 1 2
3 2 3 4
1 4
2

4 1

</p>