Codeforces Round #433 (Div. 2)

来源:互联网 发布:潘多拉淘宝 编辑:程序博客网 时间:2024/06/04 19:55
B. Maxim Buys an Apartment
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.

Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.

Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.

Input

The only line of the input contains two integers: n and k (1 ≤ n ≤ 1090 ≤ k ≤ n).

Output

Print the minimum possible and the maximum possible number of apartments good for Maxim.

Example
input
6 3
output
1 3
Note

In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 12 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 13and 5 were inhabited. In this case all other apartments: 24 and 6 are good.

题意:

有n个房间排成一排,门牌号从 1 到 n ,已知有k个房间已经住了人,求最少和最多适合Maxim的房间的个数

思路:

一个有人住的房间可以产生两个适合Maxim的房间,所以最多适合Maxim的房间数为 min(k*2,n-k)个,最少为1(所有住人的房间都相连排在一边)或0(所有房间都住人了或都没住人)

#include<iostream>#include<string.h>#include<stdio.h>#include<math.h>#define LL long longusing namespace std;int main(){    LL n,k;    scanf("%lld%lld",&n,&k);    if(k==n||k==0) {printf("0 0");return 0;}    printf("1 %lld",min(k*2,n-k));    return 0;}


原创粉丝点击