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≠gi for 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
 #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
ll n,k;
cin>>n>>k;
if(n>k*(k-)) cout<<"NO\n"<<endl;
else{
cout<<"YES\n"<<endl;
int cnt=;
for( ll i=; i<=k; i++ ){
for( ll j=i+; j<=k; j++ ){
cout<<i<<" "<<j<<endl;
cnt++;
if(cnt>=n) return ;
cout<<j<<" "<<i<<endl;
cnt++;
if(cnt>=n) return ;
}
}
}
return ;
}

Yet Another Ball Problem的更多相关文章

  1. Yet Another Ball Problem CodeForces - 1118E (简单构造)

    大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...

  2. HDU 4362 Dragon Ball 贪心DP

    Dragon Ball Problem Description   Sean has got a Treasure map which shows when and where the dragon ...

  3. SK-Learn使用NMF(非负矩阵分解)和LDA(隐含狄利克雷分布)进行话题抽取

    英文链接:http://scikit-learn.org/stable/auto_examples/applications/topics_extraction_with_nmf_lda.html 这 ...

  4. [转]"Windows Phone 7程序设计”完全版电子书可以免费下载了

    本文转自:http://www.cnblogs.com/salam/archive/2010/10/29/1864246.html 现在学习Windows Phone 7开发资料十分有限,除了MSDN ...

  5. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  6. Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization【转】

    https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Proto ...

  7. Dragon Ball--hdoj

    Dragon Ball Problem Description Five hundred years later, the number of dragon balls will increase u ...

  8. 【补题记录】ZJU-ICPC Summer Training 2020 部分补题记录

    补题地址:https://zjusummer.contest.codeforces.com/ Contents ZJU-ICPC Summer 2020 Contest 1 by Group A Pr ...

  9. 2016北京集训测试赛(十六)Problem C: ball

    Solution 这是一道好题. 考虑球体的体积是怎么计算的: 我们令\(f_k(r)\)表示\(x\)维单位球的体积, 则 \[ f_k(1) = \int_{-1}^1 f_{k - 1}(\sq ...

随机推荐

  1. .net core安装及初体验

    .net core安装及初体验 .net core 作为微软的新一代技术,在开发跨平台.微服务等方面有很大的优势,也更贴近现代的编码习惯.在2.0版发布很久以后,近期终于决定进行学习和体验. 安装 作 ...

  2. mysql 正则表达式判断是否数字

    select ('123a' REGEXP '[^0-9.]'); --‘123a'中含有字符'a' 输出结果为1 mysql中常量true输出为1 false输出为0

  3. 您的第一个C++Builder程序(Hello, world!)

    最近有些老旧的项目是C++Builder开发的,虽然和Delphi的IDE的界面和操作十分相似,但是还是找本<C++ Builder 5 Developer's Guide>来看看熟悉下, ...

  4. [开源]开放域实体抽取泛用工具 NetCore2.1

    开放域实体抽取泛用工具 https://github.com/magicdict/FDDC 更新时间 2018年7月16日 By 带着兔子去旅行 开发这个工具的起源是天池大数据竞赛,FDDC2018金 ...

  5. centos7 安装curl-7.51.0

    curl简介curl是一个广泛使用的用来上传和下载的命令行工具,当然严格来讲,它还可以有别的用途.对于测试来讲,它是Web相关测试非常实用的工具,包括debugging,使用起来非常方便.而且另一方面 ...

  6. simHash 简介以及 java 实现

    传统的 hash 算法只负责将原始内容尽量均匀随机地映射为一个签名值,原理上相当于伪随机数产生算法.产生的两个签名,如果相等,说明原始内容在一定概 率 下是相等的:如果不相等,除了说明原始内容不相等外 ...

  7. CentOS 安装 Redis 5

    https://redis.io/download下载最新stable版,当前最新版为redis-5.0.3.tar.gz cd /usr/local/src && wget http ...

  8. HDU 5095--Linearization of the kernel functions in SVM【模拟】

    Linearization of the kernel functions in SVM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  9. vivado和modelsim联合调试仿真

    vivado和modelsim联合调试仿真 0赞 发表于 2017/5/10 19:10:59 阅读(881) 评论(0) 使用vivado和modelsim联合调试仿真时,在破解完modelsim后 ...

  10. logrus日志使用详解

    1.logrus特点 golang标准库的日志框架很简单,logrus框架的特点: 1)完全兼容标准日志库 六种日志级别:debug, info, warn, error, fatal, panic ...