CodeForces - 1118 E Yet Another Ball Problem【水】

E. Yet Another Ball Problem

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The king of Berland organizes a ball! nn pair are invited to the ball, they are numbered from 11 to nn. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from 11 to kk, inclusive.

Let bibi be the color of the man's costume and gigi be the color of the woman's costume in the ii-th pair. You have to choose a color for each dancer's costume (i.e. values b1,b2,…,bnb1,b2,…,bn and g1,g2,…gng1,g2,…gn) in such a way that:

  1. for every ii: bibi and gigi are integers between 11 and kk, inclusive;
  2. there are no two completely identical pairs, i.e. no two indices i,ji,j (i≠ji≠j) such that bi=bjbi=bj and gi=gjgi=gj at the same time;
  3. there is no pair such that the color of the man's costume is the same as the color of the woman's costume in this pair, i.e. bi≠gibi≠gifor every ii;
  4. for each two consecutive (adjacent) pairs both man's costume colors and woman's costume colors differ, i.e. for every ii from 11 to n−1n−1 the conditions bi≠bi+1bi≠bi+1 and gi≠gi+1gi≠gi+1 hold.

Let's take a look at the examples of bad and good color choosing (for n=4n=4 and k=3k=3, man is the first in a pair and woman is the second):

Bad color choosing:

  • (1,2)(1,2), (2,3)(2,3), (3,2)(3,2), (1,2)(1,2) — contradiction with the second rule (there are equal pairs);
  • (2,3)(2,3), (1,1)(1,1), (3,2)(3,2), (1,3)(1,3) — contradiction with the third rule (there is a pair with costumes of the same color);
  • (1,2)(1,2), (2,3)(2,3), (1,3)(1,3), (2,1)(2,1) — contradiction with the fourth rule (there are two consecutive pairs such that colors of costumes of men/women are the same).

Good color choosing:

  • (1,2)(1,2), (2,1)(2,1), (1,3)(1,3), (3,1)(3,1);
  • (1,2)(1,2), (3,1)(3,1), (2,3)(2,3), (3,2)(3,2);
  • (3,1)(3,1), (1,2)(1,2), (2,3)(2,3), (3,2)(3,2).

You have to find any suitable color choosing or say that no suitable choosing exists.

Input

The only line of the input contains two integers nn and kk (2≤n,k≤2⋅1052≤n,k≤2⋅105) — the number of pairs and the number of colors.

Output

If it is impossible to find any suitable colors choosing, print "NO".

Otherwise print "YES" and then the colors of the costumes of pairs in the next nn lines. The ii-th line should contain two integers bibi and gigi — colors of costumes of man and woman in the ii-th pair, respectively.

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

Examples

input

Copy

4 3

output

Copy

YES
3 1
1 3
3 2
2 3

input

Copy

10 4

output

Copy

YES
2 1
1 3
4 2
3 4
4 3
3 2
2 4
4 1
1 4
3 1

input

Copy

13 4

output

Copy

NO

 

k中颜色最多有(k-1)*k种组合,当n大于这个值的时候puts no

之后按照 1,2 2,1 1,3 3,1……

#include "bits/stdc++.h"
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    if(k*(k-1)<n){
        puts("NO");
        return 0;
    }
    else puts("YES");
    int cnt=0;
    for (int i = 1; i <= k; ++i) {
        for (int j = i+1; j <= k; ++j) {
            printf("%d %d\n",i,j);
            cnt++;
            if(cnt==n)return 0;
            printf("%d %d\n",j,i);
            cnt++;
            if(cnt==n)return 0;
        }
    }
}

依次输出n对即可。。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值