A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of ndistinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.

Simon has a positive integer n and a non-negative integer k, such that 2k ≤ n. Help him find permutation a of length 2n, such that it meets this equation: .

Input

The first line contains two integers n and k (1 ≤ n ≤ 50000, 0 ≤ 2k ≤ n).

Output

Print 2n integers a1, a2, ..., a2n — the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.

Examples

Input

1 0

Output

1 2

Input

2 1

Output

3 2 1 4

Input

4 0

Output

2 7 4 6 1 3 5 8

Note

Record |x| represents the absolute value of number x.

In the first sample |1 - 2| - |1 - 2| = 0.

In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.

In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.

题意:找1-n的数,组成

的式子,使得最后的结果为2*k

我们可以来构造数列解决:设前2*k个数对前项比后项多1,2*k到2*n个数前项比后项小1,则式子的结果为

k+(n-k)-|k-(n-k)因为题目中说2*k<=n所以2*k符合题目要求

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#define MAX 300005
using namespace std;typedef long long ll;
int a[MAX];
int main()
{int n,k;cin>>n>>k;for(int t=1;t<=2*k;t+=2){a[t]=t;a[t+1]=t+1;}for(int t=2*k+1;t<=2*n;t+=2){a[t]=t+1;a[t+1]=t;}for(int t=1;t<=2*n;t++){cout<<a[t]<<" ";}return 0;} 

转载于:https://www.cnblogs.com/Staceyacm/p/10781800.html

Permutation(构造+思维)相关推荐

  1. 【CodeForces - 483C】Diverse Permutation(思维构造)

    题干: Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of ndistinct posit ...

  2. CodeForces - 287C Lucky Permutation(构造)

    题目链接:点击查看 题目大意:构造一个合法的排列,满足 ppi=n−i+1p_{p_{i}}=n-i+1ppi​​=n−i+1 题目分析:因为第四个样例的存在降低了本题的难度,不然感觉还是有点难度的一 ...

  3. CF构造思维题练习(1200-1400)

    目录 CF1706A Another String Minimization Problem 1 CF1705B Mark the Dust Sweeper 2 CF1700B Palindromic ...

  4. K Co-prime Permutation 构造,gcd,互质(2020.12.南京)

    题意 : 求构造一个n的排列,满足其中恰好k个元素与下标互质,如果不能则输出-1 思路 : 让前k个与下标偏移1,后面的都与下标相同即可 当且仅当k=0时,无解,输出-1 #include <i ...

  5. Polycarp Recovers the Permutation 构造(1000)

    题意 : 对于一个长度为n的排列和一个空序列ans,每次取当前最左边或者最右边中最小的值,如果取的是最左边,插入序列ans的最左边,然后在排列中删除这个数,如果取的是最右边,插入最右边,删除 现在给出 ...

  6. Special Permutation 构造,min_element,贪心(900)

    题意 : 构造一个n(偶数)的全排列,使得全排列的前半部分最小值等于a,后半部分最大值等于b,如果不能构造,则输出-1 思路一 : 直接构造,将a放最前,b放最后,中间从大到小放,然后构造后判断是否合 ...

  7. CodeForces - 1494E A-Z Graph(构造+思维)

    题目链接:https://vjudge.net/problem/CodeForces-1494E 题目大意:给出一个初始时只有 nnn 个点的有向带权图,需要执行 mmm 次操作,每次操作分为下列三种 ...

  8. CodeForces - 1174D Ehab and the Expected XOR Problem(构造+思维+位运算)

    题目链接:点击查看 题目大意:给出一个 n,再给出一个 x,要求构造一个数列,满足该数列的所有子串的异或和都不等于 0 且都不等于 x,在满足上面的条件下尽可能长 题目分析:因为这个题目最终的目标是需 ...

  9. CodeForces - 1265D Beautiful Sequence(贪心+构造+思维)

    题目链接:点击查看 题目大意:给出a个0,b个1,c个2,d个3,要求构造一种序列,使得数列两两之间绝对值之差等于1,若不能构造输出NO 题目分析:首先我们需要稍微讨论一下特殊情况,那就是对于两端的数 ...

最新文章

  1. Case Study: 利用JS设计高级检索功能通过PHP获取MySQL数据
  2. 移动通信网络频段大全,含5G、4G,各种公开频段汇总
  3. LinQ中Skip()方法和Take()方法的使用
  4. Python 模块之 string.py
  5. php+转义实体字符,PHP针对HTML实体字符的转义函数
  6. Javascript基础 对象与方法的识别
  7. cocos2d(CCSprite 用贝塞尔做抛物线,足球精灵并且同时做旋转放大效果)
  8. .Net报文请求转义
  9. ubuntu 18.04 安装 LNMP
  10. SQLyog注册激活码
  11. ERStudio 8.0 连接Oracle进行反向工程
  12. ORA-12514问题解决方法
  13. SQL2008 视频教程 SQL Server 2008高级视频教程
  14. 概率计算机在线,高斯正态分布(概率)计算公式与在线计算器_三贝计算网_23bei.com...
  15. php注册登录课件,登录注册验证(javascript)-php教学课件5.pdf
  16. R5 4650G和R5 5600G差距
  17. Node开发实践总结-定时脚本的设计与实现
  18. 前沿重器[7] | 小布助手登顶百度千言短文本相似度的秘诀
  19. 英语语法总结--动词不定式
  20. 要在某一房间中两台计算机之间,关于局域网、广域网和互联网的组建和因特网的接入,回答下列问题。要在某一房间中两台计算机之间实现网络通信,下列方法不可行的是...

热门文章

  1. python两个字符串数据可以复制吗_无论如何,是否要将Python pandas数据框中的单个数据中的数据复制到字符串或列表中以进行进一步处理?...
  2. editor.md国产markdown编辑器使用实例
  3. Linux笔记-配置本地光盘未yum源
  4. Android逆向笔记-使用Android Studio调试Smali代码(方式一)
  5. SoapUI笔记-使用SoapUI测试WebService服务端
  6. Java工作笔记-生成及解析Json字符串
  7. Spring Boot静态资源映射规则
  8. C++与QML信号交互(非Q_PROPERTY法)
  9. 职工工资信息系统 c语言题,工资信息管理系统C语言设计.doc
  10. java $ class_java文件编译后额外生成的$1.class是怎么一回事