#P10094. [ROIR 2023] 矩形分割 (Day 1)

    ID: 10752 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学2023Special JudgeROIR(俄罗斯)

[ROIR 2023] 矩形分割 (Day 1)

Background

Translated from ROIR 2023 D1T1

Problem Description

There is a rectangle of size a×ba \times b made of unit grid cells. You need to split it into mm smaller rectangles using kk vertical or horizontal cuts. The smaller rectangles do not need to have the same size.

Each cut is not allowed to stop halfway: it must go from one side of the current rectangle to the opposite side. Cuts are only allowed along grid lines.

Input Format

The first line contains an integer tt, the number of test cases.

The next tt lines each contain one test case. Each test case has four integers a,b,k,ma, b, k, m, representing the rectangle size (length and width), the required number of cuts, and the required number of resulting smaller rectangles.

Output Format

For each test case, output in one line the number of horizontal cuts hh (0h<a0 \le h < a) and the number of vertical cuts vv (0v<b0 \le v < b) that can split the rectangle into mm smaller rectangles. If there are multiple ways, output the one with fewer horizontal cuts. If it is impossible to cut as required, output -1.

3
2 2 1 2
1 2 2 3
3 5 5 12
0 1
-1
2 3

Hint

This problem uses bundled testdata.

Subtask ID Score Special Property
11 1818 a=1a=1
22 1919 m105m \le 10^5
33 2020 1k1051 \le k \le 10^5
44 2121 m109m \le 10^9
55 2222 None

All testdata satisfy 1t1001 \le t \le 100, 1a,b1091 \le a, b \le 10^9, 0k2×1090 \le k \le 2 \times 10^9, 1m10181 \le m \le 10^{18}, and k<mk < m.

Translated by ChatGPT 5