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;
}

Permutation(构造+思维)的更多相关文章

  1. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  2. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  3. D. Make a Permutation!(思维)

    D. Make a Permutation! time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. 5.5 省选模拟赛 B Permutation 构造 贪心

    LINK:Permutation 对于这种构造神题 我自然是要补的.为啥就我没想出来哇. 30分还是很好写的 注意8!实际上很小 不需要爆搜 写bfs记录状态即可.至于判断状态是否出现与否 可以开ma ...

  5. CF R 209 div 2 CF359B Permutation 构造

    LINK:Permutation 休闲一下 开了一道构造题. 看起来毫无头绪 其实仔细观察第二个条件 0<=2k<=n. 容易想到当n是奇数的时候 k的范围更小 再手玩一下第一个条件 容易 ...

  6. Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造

    B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  7. codeforces 622C. Optimal Number Permutation 构造

    题目链接 假设始终可以找到一种状态使得值为0, 那么两个1之间需要隔n-2个数, 两个2之间需要隔n-3个数, 两个3之间隔n-4个数. 我们发现两个三可以放到两个1之间, 同理两个5放到两个3之间. ...

  8. Codeforces 482 - Diverse Permutation 构造题

    这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ....... ...

  9. CF359B Permutation 构造

    正解:构造 解题报告: 这个是传送门! 昂直接讲思路趴?毕竟这种构造题的话除了思路也没什么好说的只要想明白辽还是通常来说难度不大的QwQ 首先提供一个对正解毫无启发的由正解启发而来的想法QAQ 就首先 ...

随机推荐

  1. App测试从入门到精通之App分类和场景操作系统

    App概要 APP是application的缩写.通常指的是手机软件上的应用,或称为手机客户端.手机app就是手机的应用程序.随着智能手机的越发普及,用户越发依赖手机软件商品店,app开发的需求与发展 ...

  2. 20169219 实验四Android程序设计

    一.实现Linux下dc的功能,计算后缀表达式的值 public int evaluate(String expr) { int op1, op2, result = 0; String token; ...

  3. [转]windows7远程桌面连接失败:发生身份验证错误。要求的函数不受支持

    转至:https://jingyan.baidu.com/article/d169e18604ca86436611d821.html 系统升级后出现远程连接报错,“发生身份验证错误.要求的函数不受支持 ...

  4. 使用 Windows Phone 8 文件和 URI 关联的自动启动应用

    更详细,猛撸这里:http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/jj206987(v=vs.105).aspx 在WMApp ...

  5. JMeter Bean Shell

    1.什么是bean Shell BeanShell是一种脚本语言,一种完全符合java语法的java脚本语言,并且又拥有自己的一些语法和方法,beanShell是一种松散类型的脚本语言(这点和JS类似 ...

  6. 「BZOJ 1924」「SDOI 2010」所驼门王的宝藏「Tarjan」

    题意 一个\(r\times c\)的棋盘,棋盘上有\(n\)个标记点,每个点有三种类型,类型\(1\)可以传送到本行任意标记点,类型\(2\)可以传送到本列任意标记点,类型\(3\)可以传送到周围八 ...

  7. { "result": null, "log_id": 304592860300941982, "error_msg": "image check fail", "cached": 0, "error_code": 222203, "timestamp": 1556030094 }

    这个是人脸识别时无法检测到图片报的错,有时候我们检测一张图片是否在库里面,当一张图片明显在里面,还检测不到,如下面是我的代码 package Test1; import java.io.IOExcep ...

  8. python中局部变量和全局变量

    局部变量,就是在函数内部定义的变量 不同的函数,可以定义相同的名字的局部变量,但是各用个的不会产生影响 局部变量的作用,为了临时保存数据需要在函数 在函数外边定义的变量叫做全局变量 全局变量能够在所有 ...

  9. shell传参给matlab问题解决办法

    之前需要通过shell脚本传参给matlab程序,但是遇到一些问题,现将我遇到的问题分享出来,给遇到同样问题的人一些借鉴. shell部分脚本Execl.sh: /usr/bin/python /ho ...

  10. 【转】C#中静态方法和非静态方法的区别

    源地址:https://www.cnblogs.com/amoshu/p/7477757.html 备注:静态方法不需要类的实例化就能调用,因为它是一直保存在内存中,不像非静态方法一样要放在实例化类时 ...