Eating Soup

Posted karshey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Eating Soup相关的知识,希望对你有一定的参考价值。

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 n 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 m 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.

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

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

Examples

Input
7 4
Output
3
Input
6 2
Output
2
Input
3 0
Output
1
Input
2 2
Output
0

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

在这里插入图片描述

At the observed moment, 4 cats have left the table. Suppose the cats 2, 3, 5 and 7 have left, then there are 3 groups remaining. It is possible to show that it is the maximum possible number of groups remaining.

在这里插入图片描述

In the second example, there are 6 cats sitting as shown below:
在这里插入图片描述

At the observed moment, 2 cats have left the table. Suppose the cats numbered 3 and 6 left, then there will be 2 groups remaining ({1,2} and {4,5}). It is impossible to have more than 2 groups of cats remaining.
在这里插入图片描述

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

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

画一个圆试试即可。

#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	
	if(m==0) cout<<1;//没人走 
	else if(m==n) cout<<0;//全走了 
	//走了一部分 
	else if(n-m>=m) cout<<m;
	else cout<<n-m;
	return 0;
}

以上是关于Eating Soup的主要内容,如果未能解决你的问题,请参考以下文章

启用以使用 Beautiful Soup 获取特定网站的 img 标签

[luoguP2896] [USACO08FEB]一起吃饭Eating Together(DP)

LeetCode 875. Koko Eating Bananas

eating throughout Bali

USACO 2008 FEB Eating Together

GroupClass-Eating out