CF1929B.Sasha and the Drawing

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Even in kindergarten, Sasha liked a girl. Therefore, he wanted to give her a drawing and attract her attention.

As a drawing, he decided to draw a square grid of size n×nn \times n, in which some cells are colored. But coloring the cells is difficult, so he wants to color as few cells as possible. But at the same time, he wants at least kk diagonals to have at least one colored cell. Note that the square grid of size n×nn \times n has a total of 4n−24n - 2 diagonals.

Help little Sasha to make the girl fall in love with him and tell him the minimum number of cells he needs to color.

即使在幼儿园时,萨沙就喜欢一个女孩。因此,他想送她一幅画来吸引她的注意。

作为这幅画,他决定画一个 n×nn \times n 的方格网格,其中部分格子被涂色。但涂色很费力,所以他希望涂色的格子数量尽可能少。与此同时,他又希望至少有 kk 条对角线包含至少一个被涂色的格子。注意:一个 n×nn \times n 的方格网格总共有 4n−24n - 2 条对角线。

请帮小萨沙赢得女孩的芳心,并告诉他最少需要涂色多少个格子。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers nn and kk (2≤n≤1082 \leq n \leq 10^8, 1≤k≤4n−21 \leq k \leq 4n - 2) — the size of the square grid and the minimum number of diagonals in which there should be at least one colored cell.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 kk(2≤n≤1082 \leq n \leq 10^8,1≤k≤4n−21 \leq k \leq 4n - 2),分别表示正方形网格的大小以及要求至少有一个已着色格子的对角线的最小数量。

输出格式

For each test case, output a single integer — the minimum number of cells that need to be colored.

对于每个测试用例,输出一个整数——需要涂色的最少格子数。

输入输出样例

  • 输入#1

    7
    3 4
    3 3
    3 10
    3 9
    4 7
    7 11
    2 3

    输出#1

    2
    2
    6
    5
    4
    6
    2

说明/提示

In the pictures below, the colored cells are marked in black, and all diagonals are marked in purple.

In the first test case, you can color 22 cells so that 44 diagonals contain at least one colored cell:

In the third test case, you can color 66 cells so that all 1010 diagonals contain at least one colored cell:

在下面的图片中,彩色单元格以黑色标记,所有对角线均以紫色标记。

在第一个测试用例中,你可以给 22 个单元格染色,使得 44 条对角线上至少包含一个已染色的单元格:

在第三个测试用例中,你可以给 66 个单元格染色,使得全部 1010 条对角线上都至少包含一个已染色的单元格:

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

首页