No.149 Moving Go Stones
タグ : / 解いたユーザー数 499
作問者 :
nmnmnmnmnmnmnm
Problem Statement
There are two opaque bags, bag A and bag B.
Each of bag A and bag B contains Go stones.
Bag A contains $A_w$ white stones and $A_b$ black stones.
Bag B contains $B_w$ white stones and $B_b$ black stones.
First, $C$ stones are taken out of bag A without looking at their colors and moved to bag B.
Next, $D$ stones are taken out of bag B, again without looking at their colors, and moved to bag A.
When the white stones in bag A are counted at the end,
what is the maximum possible number of white stones?
Input
$A_w$ $A_b$ $B_w$ $B_b$ $C$ $D$
$0 \le A_w,A_b \le 100000$.
$0 \le B_w,B_b \le 100000$.
$0 \le C \le 200000$.
$0 \le D \le 400000$.
$C,D$ are always given as numbers of stones that can actually be taken.
Output
Output on one line the maximum possible number of white stones in bag A after the moves.
Do not forget the newline at the end.
Sample
Sample 1
Input
2 1 1 2 2 3
Output
3
Bag A contains $2$ white stones and $1$ black stone.
Bag B contains $1$ white stone and $2$ black stones.
For example, if the $2$ stones moved from bag A to bag B are both white,
and then the $3$ stones moved from bag B to bag A are all white,
bag A ends up with at most $3$ white stones.
Sample 2
Input
2 0 0 3 2 1
Output
1
The $2$ stones first moved from bag A to bag B are always white.
Then, if the $1$ stone moved from bag B to bag A is white,
bag A ends up with at most $1$ white stone.
Sample 3
Input
3 0 2 3 0 5
Output
5
First, $0$ stones are moved from bag A to bag B. (That is, the numbers of stones do not change.)
Next, the $5$ stones moved from bag B to bag A consist of $2$ white stones and $3$ black stones,
so bag A ends up with at most $5$ white stones.
Sample 4
Input
43682 82641 54647 3647 92674 64591
Output
98240
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。