Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1).B. Vasya and Cornfield

本文介绍了一个编程问题,Vasya需要判断草蜢是否位于其拥有的一块特定形状的玉米地中。通过输入玉米地的尺寸和草蜢的位置坐标,程序将输出草蜢是否在玉米地内或边界上的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Vasya and Cornfield

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya owns a cornfield which can be defined with two integers nn and dd. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,n−d)(0,d),(d,0),(n,n−d) and (n−d,n)(n−d,n).

An example of a cornfield with n=7n=7 and d=2d=2.

Vasya also knows that there are mm grasshoppers near the field (maybe even inside it). The ii-th grasshopper is at the point (xi,yi)(xi,yi). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).

Input

The first line contains two integers nn and dd (1≤d<n≤1001≤d<n≤100).

The second line contains a single integer mm (1≤m≤1001≤m≤100) — the number of grasshoppers.

The ii-th of the next mm lines contains two integers xixi and yiyi (0≤xi,yi≤n0≤xi,yi≤n) — position of the ii-th grasshopper.

Output

Print mm lines. The ii-th line should contain "YES" if the position of the ii-th grasshopper lies inside or on the border of the cornfield. Otherwise the ii-th line should contain "NO".

You can print each letter in any case (upper or lower).

Examples

input

Copy

7 2
4
2 4
4 1
6 3
4 5

output

Copy

YES
NO
NO
YES

input

Copy

8 7
4
4 4
2 8
8 1
6 1

output

Copy

YES
NO
YES
YES

Note

The cornfield from the first example is pictured above. Grasshoppers with indices 11 (coordinates (2,4)(2,4)) and 44 (coordinates (4,5)(4,5)) are inside the cornfield.

The cornfield from the second example is pictured below. Grasshoppers with indices 11 (coordinates (4,4)(4,4)), 33 (coordinates (8,1)(8,1)) and 44(coordinates (6,1)(6,1)) are inside the cornfield.

#include<bits/stdc++.h>
using namespace std;
#define maxn 300005
#define ll long long
#define M(a) memset(a,0,sizeof(a))

int main()
{
    int t,n,d;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    while(cin>>n>>d)
    {
        int m,x,y;
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>x>>y;
            if((x+y>=d)&&(x+y<=2*n-d)&&(y-x>=-d)&&(y-x<=d)) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值