Time Limit:2 Sec
Memory limit:256 MB
Topic Connection
Http://codeforces.com/gym/100187/problem/K
Description
The world famous scientist Innokentiy almost finished the creation of Perpetuum Mobile. Its main part was the energy generator which allows, the other mobile's parts work. The generator consists of the long parallel plates with n lasers on one of the them and N receivers on another. The generator is considered to being working if each laser emits the beam-some receiver such that exactly one beam is emit Ted to each receiver.
It is obvious this some beams emitted by distinct lasers can intersect. If the beams intersect each other, one joule of energy is released per second because of the interaction of the beams. The more beams intersect and the more energy is released. Innokentiy noticed that if the energy generator releases exactly k joules per second, the Perpetuum Mobile would work up to Ten times longer. The scientist can direct any laser at no receiver, but he hasn ' t thought of such a construction that would give exactly th E Required amount of energy yet. You should help the scientist to tune up the generator.
Input
The only line contains-integers n and K (1≤n≤200000,) separated by space-the number of lasers in the energy Gen Erator and the power of the generator innokentiy wants to reach.
Output
Output n integers separated by spaces. i-th number should is equal to the number of receiver which the i-th laser should is directed at. Both lasers and receivers is numbered from 1 to N. It's guaranteed that the solution exists. If There is several solutions, you can output any of them.
Sample Input
4 5
Sample Output
4 2 3 1
HINT
Test instructions
Give you the number of n, let you construct a sequence of K reverse order number
Exercises
Find a way to n-1 ...... Down
Code
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <Set>8#include <vector>9#include <queue>Ten#include <map> One#include <stack> A #defineMOD 1000000007 - #defineMAXN 32001 - using namespacestd; the typedef __int64 LL; - inline ll read () - { -ll x=0, f=1;CharCh=GetChar (); + while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} + returnx*F; A } at //******************************************************************* -ll a[200101]; -ll q[200101]; - intMain () - { - ll N; in ll K; -N=read (), k=read (); to for(LL i=1; i<=n; i++) +a[i]=i; - if(k==0) the { * for(LL i=1; i<=n; i++) $printf"%i64d", A[i]);Panax Notoginseng return 0; - } thell j=1; +ll x=0; All kk=1; thell nn=N; + while(k) - { $ if(k>=n-j) $ { -q[++x]=A[nn]; -nn--; thek=k-(nj); - }Wuyi Else the { -q[++x]=A[KK]; Wukk++; - } AboutJ + +; $ } -j--; - for(LL i=1; i<=x; i++) - { Aprintf"%i64d", Q[i]); + } the for(ll I=kk; i<nn+1; i++) -printf"%i64d", A[i]); $ return 0; the}
Codeforces Gym 100187K K. Perpetuum Mobile Construction