Educational Codeforces Round 106 (Rated for Div. 2) A

A. Domino on Windowsill

原题链接

题面

You have a board represented as a grid with 2×n cells.

The first k1 cells on the first row and first k2 cells on the second row are colored in white. All other cells are colored in black.

You have w white dominoes (2×1 tiles, both cells are colored in white) and b black dominoes (2×1 tiles, both cells are colored in black).

You can place a white domino on the board if both board’s cells are white and not occupied by any other domino. In the same way, you can place a black domino if both cells are black and not occupied by any other domino.

Can you place all w+b dominoes on the board if you can place dominoes both horizontally and vertically?

Input

The first line contains a single integer t (1≤t≤3000) — the number of test cases.

The first line of each test case contains three integers n, k1 and k2 (1≤n≤1000; 0≤k1,k2≤n).

The second line of each test case contains two integers w and b (0≤w,b≤n).

Output

For each test case, print YES if it’s possible to place all w+b dominoes on the board and NO, otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

Example

Input

5
1 0 1
1 0
1 1 1
0 0
3 0 0
1 3
4 3 1
2 2
5 4 3
3 1

Output

NO
YES
NO
YES
YES

Note

n the first test case, n=1, k1=0 and k2=1. It means that 2×1 board has black cell (1,1) and white cell (2,1). So, you can’t place any white domino, since there is only one white cell.

In the second test case, the board of the same size 2×1, but both cell are white. Since w=0 and b=0, so you can place 0+0=0 dominoes on the board.

In the third test case, board 2×3, but fully colored in black (since k1=k2=0), so you can’t place any white domino.

In the fourth test case, cells (1,1), (1,2), (1,3), and (2,1) are white and other cells are black. You can place 2 white dominoes at positions ((1,1),(2,1)) and ((1,2),(1,3)) and 2 black dominoes at positions ((1,4),(2,4)) ((2,2),(2,3)).

题意

两个相邻且相同颜色的格子可以放置一个多米诺骨牌,简而言之就是一个面积为2的白色或者黑色区域就可以占据一个牌的位置,求所给的区域能否放置样例足够的骨牌

思路

求出区域能够能够放置最多的白色或黑色骨牌,是否大于或等于所给的骨牌。因为是2*n的面积,我们可以看出白色面积就是k1+k2,黑色面积就是2n-k1-k2

代码如下

#include <iostream>
 
using namespace std;
 
 
 
int main(void)
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k1,k2,w,b;
        cin >> n >> k1 >> k2;
        cin >> w >> b;
        
        int sumw = k1 + k2,sumb = 2*n - sumw;//白色黑色面积
        
        int w1,b1;
        w1 = sumw / 2;//白色可以放置的最大数
        b1 = sumb / 2;//黑色可以放置的最大数
        if(w1>=w&&b1>=b)cout << "yes" << endl;//判断是否满足条件
        else cout << "no" << endl;
    }
    
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值