CF1163A.Eating Soup

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...

What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now nn cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.

Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are mm cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?

Could you help her with this curiosity?

You can see the examples and their descriptions with pictures in the "Note" section.

三位朋友——Kuro、Shiro 和 Katie 再次相聚!是时候举办一场派对了……

当猫咪们齐聚一堂时,会做些什么呢?没错,它们要开派对!为了尽可能地享受欢乐,它们邀请了所有朋友。现在共有 nn 只猫咪在派对上围成一个圆圈喝汤。规则很简单:任何一只喝完汤的猫咪都会离开圆圈。

Katie 突然注意到,每当一只猫咪离开,它原先坐的位置就会变成一个空位,这意味着圆圈被分割成了若干个更小的、连续的猫咪群组(即相邻而坐的猫咪构成的连续段)。在 Katie 观察的此刻,已有 mm 只猫咪离开了圆圈。这引发了一个问题:此时圆圈最多可能被分割成多少个群组?

你能帮她解答这个疑问吗?

你可以在“注释”部分看到示例及其配图说明。

输入格式

The only line contains two integers nn and mm (2≤n≤10002 \leq n \leq 1000, 0≤m≤n0 \leq m \leq n) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.

唯一的一行包含两个整数 nn 和 mm(2≤n≤10002 \leq n \leq 1000,0≤m≤n0 \leq m \leq n),分别表示派对最初的小猫数量以及凯蒂观察时离开圆圈的小猫数量。

输出格式

Print a single integer — the maximum number of groups of cats at the moment Katie observes.

输出一个整数——Katie 观察时猫群的最大数量。

输入输出样例

  • 输入#1

    7 4

    输出#1

    3
  • 输入#2

    6 2

    输出#2

    2
  • 输入#3

    3 0

    输出#3

    1
  • 输入#4

    2 2

    输出#4

    0

说明/提示

In the first example, originally there are 77 cats sitting as shown below, creating a single group:

At the observed moment, 44 cats have left the table. Suppose the cats 22, 33, 55 and 77 have left, then there are 33 groups remaining. It is possible to show that it is the maximum possible number of groups remaining.

In the second example, there are 66 cats sitting as shown below:

At the observed moment, 22 cats have left the table. Suppose the cats numbered 33 and 66 left, then there will be 22 groups remaining (1,2{1, 2} and 4,5{4, 5}). It is impossible to have more than 22 groups of cats remaining.

In the third example, no cats have left, so there is 11 group consisting of all cats.

In the fourth example, all cats have left the circle, so there are 00 groups.

在第一个例子中,最初有 77 只猫按如下方式围坐,形成一个单一的组:

在观察时刻,已有 44 只猫离开了桌子。假设离开的猫编号为 22、33、55 和 77,则剩余 33 个组。可以证明,这是剩余组数的最大可能值。

在第二个例子中,有 66 只猫按如下方式围坐:

在观察时刻,已有 22 只猫离开了桌子。假设离开的猫编号为 33 和 66,则将剩下 22 个组(1,2{1, 2} 和 4,5{4, 5})。不可能剩下超过 22 个猫组成的组。

在第三个例子中,没有猫离开,因此所有猫构成 11 个组。

在第四个例子中,所有猫均已离开圆圈,因此剩下 00 个组。

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

首页