我是靠谱客的博主 会撒娇白开水,最近开发中收集的这篇文章主要介绍A. Eating Soup,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

A. Eating Soup
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output

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

outpu

0

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
int main(){
	ll n,m;
	while(scanf("%lld %lld",&n,&m)!=EOF){
		if(m==0||m==1){
			cout<<"1"<<endl;
		}
		else if(n==m||n<m){
			cout<<"0"<<endl;
		}
		else{
			ll b=n-n/2;
			if(b>m){
				cout<<m<<endl;
			}
			else if(b==m){
				cout<<n/2<<endl;
			}
			else{
				n=n-m;
				cout<<n<<endl;
			}
		}
	}
}

最后

以上就是会撒娇白开水为你收集整理的A. Eating Soup的全部内容,希望文章能够帮你解决A. Eating Soup所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部