Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cubes). Petya moves first. Petya's task is to get as many pairs of neighbouring cubes of the same color as possible. Vasya's task is to get as many pairs of neighbouring cubes of different colors as possible.
The number of Petya's points in the game is the number of pairs of neighboring cubes of the same color in the line, the number of Vasya's points in the game is the number of neighbouring cubes of the different color in the line. Your task is to calculate the score at the end of the game (Petya's and Vasya's points, correspondingly), if both boys are playing optimally well. To "play optimally well" first of all means to maximize the number of one's points, and second — to minimize the number of the opponent's points.
The only line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of red and blue cubes, correspondingly.
On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.
3 1
2 1
2 4
3 2
In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cube during his first move, then, provided that both boys play optimally well, Petya would get 1 point and Vasya would get 2 points.
可以证明当较少的颜色是单数是 先选较少的颜色,是双数时,再选较多的颜色。Vasya的得分是较少的颜色的个数,Petya的得分就是总个数减一减Vasya的个数。
附代码:
1 #include<iostream> 2 using namespace std; 3 4 int main(void) 5 { 6 int a, b, min, max, c, d; 7 int i=0; 8 cin>>a>>b; 9 min=a>b?b:a; 10 max=a>b?a:b; 11 c=min/2; 12 if( min%2==1) 13 { 14 d=max-min; 15 cout<<c*2+d<<' '<<min<<endl; 16 } 17 else 18 { 19 d=max-min; 20 cout<<c+c-1+d<<' '<<min<<endl; 21 } 22 return 0; 23 }