Codeforces Round #433 (2)B :Maxim Buys an Apartment

时间:2021-02-01 14:58:28


Maxim Buys an Apartment

Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house hasn apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by1. 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 exactlyk 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 andk (1 ≤ n ≤ 109,0 ≤ 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 indices1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.


 

    题意: n 个房间,其中有 k 个已经被出租,定义一个空房间左边或者右边有被出租的房子为好房子,求好房子的最大和最小情况。


   思路:  其实是个水题,然而自己没想好就瞎写,最后还被Hack 了,第一次被Hack ,还是记录一下。考虑 用最少的1  来得到满足条件的最大的 0 ,其实就是 1001001001 这中序列,直接算出 n/3  +1  即 n 中满足这种序列需要多少个1 ,然后跟k 比较,比 k 大就直接  2*k,比 k 小就是  n-k.


Codeforces Round #433 (2)B :Maxim Buys an Apartment


:(:(:(:(:(




#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        if(n<=k)
            printf("0 0\n");
        else if(k==0)
            printf("0 0\n");
        else
        {
            int mx,mn;
            int tem=n/3+1;
            if(k>=tem)   mx=n-k;
            else mx=2*k;
            mn=1;
            printf("%d %d\n",mn,mx);
        }
    }
    return 0;
}