8627: Black Magic

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

HoshiYo is learning Black Magic with n blocks. The left and right sides of each block are painted black or white. HoshiYo arranges the blocks in a row in a certain order without rotating them and then releases the Black Magic. Here's what happens next:For any two adjacent blocks, if the right side of the left block and the left side of the right block are both painted black, then the two sides will be pasted together making the two blocks into one.
HoshiYo wants to know the minimum and maximum blocks he can get after releasing the Black Magic.

输入格式

The first line contains an integer T 1T4×103), indicating the number of test cases.

Each test case contains four integers E,L,R,B 0E,L,R,B105,E+L+R+B1), indicating the number of blocks.

  • E: the number of blocks whose both sides are painted white.
  • L the number of blocks whose left side is painted black and right side is painted white.
  • R: the number of blocks whose right side is painted black and left side is painted white.
  • B: the number of blocks whose both sides are painted black.
It guaranteed that the sum of E+L+R+B over all test cases won't exceed 106.

输出格式

For each test case, output two integers in a single line, indicating the minimum and maximum blocks HoshiYo can get.

输入样例 复制

3
1 1 1 1
1 2 3 4
3 4 5 6

输出样例 复制

2 4
4 8
8 16

数据范围与提示

Let's denote a block by (x,y), where xx indicates the color on the left side, and y indicates the color on the right side. We use 00 to represent white and 11 to represent black.

For the first test case in the sample, here is a possible solution to get the minimum number of blocks:

(0,0)(0,1)(1,1)(1,0)

As shown above, the last three blocks will be pasted into one.

And here is a possible solution to get the maximum number of blocks:

(0,0)(1,0)(1,1)(0,1)

As shown above, any two blocks will not be pasted together.