Vasya and the Bus
2013-12-22 22:33
357 查看
Description
One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..."
The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.
The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k(k > 0) children, pays overall k rubles:
a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.
We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.
Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.
Input
The input file consists of a single line containing two space-separated numbers n and m(0 ≤ n, m ≤ 105) — the number of the grown-ups and the number of the children in the bus, correspondingly.
Output
If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.
Otherwise, print "Impossible" (without the quotes).
Sample Input
Input
1 2
Output
2 2
Input
0 5
Output
Impossible
Input
2 2
Output
2 3
#include<stdio.h>
int main()
{
int m,n,max,min;
while(~scanf("%d%d",&n,&m))
{
if(n==0)
{
if(m==0)
{printf("0 0\n");}
else
{printf("Impossible\n");}
continue;
}
else if(n<=m)
{max=m+n-1; min=m;}
else if(m==0)
{max=n;min=n;}
else
{max=m+n-1;min=n;}
printf("%d %d\n",min,max);
}
return 0;
}
One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..."
The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.
The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k(k > 0) children, pays overall k rubles:
a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.
We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.
Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.
Input
The input file consists of a single line containing two space-separated numbers n and m(0 ≤ n, m ≤ 105) — the number of the grown-ups and the number of the children in the bus, correspondingly.
Output
If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.
Otherwise, print "Impossible" (without the quotes).
Sample Input
Input
1 2
Output
2 2
Input
0 5
Output
Impossible
Input
2 2
Output
2 3
#include<stdio.h>
int main()
{
int m,n,max,min;
while(~scanf("%d%d",&n,&m))
{
if(n==0)
{
if(m==0)
{printf("0 0\n");}
else
{printf("Impossible\n");}
continue;
}
else if(n<=m)
{max=m+n-1; min=m;}
else if(m==0)
{max=n;min=n;}
else
{max=m+n-1;min=n;}
printf("%d %d\n",min,max);
}
return 0;
}
相关文章推荐
- A. Vasya and the Bus
- A. Vasya and the Bus
- Vasya and the Bus
- CF190A:Vasya and the Bus(易错题)
- A. Vasya and the Bus
- 【CF1016C】Vasya And The Mushrooms(模拟)
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
- 【CF1016D】Vasya And The Matrix(构造)
- The Bus and the Subway Train
- Arduino and the SPI bus
- EventBusException: Subscriber class *** and its super classes have no public methods with the @Subsc
- EventBusException: Subscriber class *** and its super classes have no public methods with the @Subsc
- EventBusException: Subscriber class *** and its super classes have no public methods with the @Subsc
- Codeforces Round #435 (Div. 2) B. Mahmoud and Ehab and the bipartiteness
- Spring Cloud(2) |No plugin found for prefix 'docker' in the current project and in the plugin groups
- hdu1029——Ignatius and the Princess IV
- cf-Luba And The Ticket
- POJ 1912 A highway and the seven dwarfs (凸包)
- what's is the different between git rebase and git meger.