#P9762. [ROIR 2021] 分割数表 (Day 1)

[ROIR 2021] 分割数表 (Day 1)

Background

Translated from ROIR 2021 Day1 T2 Разбиение таблицы

Problem Description

There is an n×mn \times m number table aa, where ai,j=(i1)×m+ja_{i,j} = (i - 1) \times m + j.

Now split this table into two tables x,yx, y so that max{x,y}\max\{\sum x, \sum y\} is minimized.

More concretely, you may choose an ii, then make one vertical cut between column i1i - 1 and column ii, or make one horizontal cut between row i1i - 1 and row ii. The two resulting tables are xx and yy.

Please construct one valid plan.

Input Format

This problem has multiple test cases.

The first line contains an integer tt.

The next tt lines each contain two integers n,mn, m, representing the size of the table in this query.

Output Format

For each query, output a character cc and an integer xx.

If you want to cut vertically, let cc be V, and let xx be your chosen ii.

If you want to cut horizontally, let cc be H, and let xx be your chosen ii.

If there are multiple solutions, output a vertical cut. If there are still multiple solutions, output the one with the smallest xx.

5
1 3
4 7
1 10
3 3
3 5
V 3
V 5
V 8
H 3
V 4

Hint

Constraints:

For all subtasks, 1t1051 \le t \le 10^5, 1n,m1091 \le n, m \le 10^9, 2n×m1092 \le n \times m \le 10^9.

Subtask ID Constraints Score
11 t=1t = 1, n,m100n, m \le 100 2020
22 t=1t = 1, n,m2×103n, m \le 2 \times 10^3 1414
33 t=1t = 1, n,m107n, m \le 10^7 1515
44 t103t \le 10^3, n×m104n \times m \le 10^4 1616
55 n=1n = 1 1515
66 No special constraints 2020

Translated by ChatGPT 5