CF2276A.Perfect Sandwiches

入门

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp has aa slices of cheese and bb slices of sausage. He wants to make the maximum possible number of sandwiches for his friends from them.

Monocarp is very thrifty, so he must use all aa slices of cheese and all bb slices of sausage without any leftovers to make the sandwiches. In addition, he has the following rules for making sandwiches:

  • each sandwich must contain at least one slice of cheese and at least one slice of sausage;
  • each of the aa slices of cheese and each of the bb slices of sausage must be placed on exactly one sandwich;
  • for each sandwich, the number of slices of cheese must be strictly greater than the number of slices of sausage.

Help Monocarp determine the maximum number of sandwiches he can make, or determine that it is impossible to distribute all slices according to these rules.

莫诺卡普有 aa 片奶酪和 bb 片香肠。他想用这些材料为朋友们制作尽可能多的三明治。

莫诺卡普非常节俭,因此他必须恰好用完全部 aa 片奶酪和全部 bb 片香肠,不能有任何剩余。此外,他在制作三明治时还需遵守以下规则:

  • 每个三明治至少包含一片奶酪和一片香肠;
  • 所有 aa 片奶酪和所有 bb 片香肠都必须被恰好放置在某一个三明治上;
  • 对于每个三明治,其奶酪片数必须严格大于香肠片数。

请帮助莫诺卡普确定他最多能制作多少个三明治;若无法按上述规则分配所有食材,则判定为不可能。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The only line of each test case contains two integers aa and bb (1≤a,b≤1001 \le a, b \le 100) — the number of slices of cheese and sausage, respectively.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例仅一行,包含两个整数 aa 和 bb(1≤a,b≤1001 \le a, b \le 100)—— 分别表示奶酪片数和香肠片数。

输出格式

For each test case, print one integer — the maximum number of sandwiches that can be made. If it is impossible to distribute all pieces according to the described rules, print −1-1 instead.

对于每个测试用例,输出一个整数——最多可以制作的三明治数量。如果无法按照上述规则分配所有面包片,则输出 −1-1。

输入输出样例

  • 输入#1

    3
    6 4
    5 1
    4 5

    输出#1

    2
    1
    -1

说明/提示

In the first test case, it is possible to make 22 sandwiches. For example, each of the two sandwiches can be made from three slices of cheese and two pieces of sausage.

In the second test case, it is possible to make 11 sandwich from five slices of cheese and one slice of sausage.

In the third test case, it is impossible to make sandwiches while using all slices of cheese and sausage, so you have to print −1-1.

在第一个测试用例中,可以制作 22 个三明治。例如,每个三明治可由三片奶酪和两片香肠制成。

在第二个测试用例中,可以使用五片奶酪和一片香肠制作 11 个三明治。

在第三个测试用例中,无法在用完所有奶酪片和香肠片的前提下制作三明治,因此需要输出 −1-1。

输入解题思路,AI测评打分。不知道怎么写?

首页