题意:
思路:
史上最水
G
G
G题,没有之一。
考虑最小的情况如何构造,显然就是让
a
,
b
a,b
a,b都
1
−
n
1-n
1−n依次排列即可,这样的最小值为
n
∗
(
n
+
1
)
2
\frac{n*(n+1)}{2}
2n∗(n+1),如果
m
m
m小于他,显然无解,否则一定能构造一组解。
考虑将
a
a
a置为从
1
−
n
1-n
1−n的排列,让后
b
b
b初始也为
1
−
n
1-n
1−n的排列,即
a
,
b
=
1
,
2
,
.
.
.
,
n
a,b=1,2,...,n
a,b=1,2,...,n。考虑将
b
b
b的最后一个数
x
x
x从
a
a
a的
x
−
1
x-1
x−1的位置向前移动,一直到
b
b
b已经填完的位置之前,每移动一位即可将贡献增加
1
1
1,所以一直这样移动,最后从
1
−
n
1-n
1−n填上空位置即可。
// Problem: G. Running in Pairs
// Contest: Codeforces - Codeforces Round #592 (Div. 2)
// URL: https://codeforces.com/contest/1244/problem/G
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
LL n,m;
int a[N],b[N];
int vis[N];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
cin>>n>>m;
if(m<n*(n+1)/2) puts("-1");
else {
LL sum=0;
for(int i=1;i<=n;i++) a[i]=i;
int st=0,ed=n;
m-=n*(n+1)/2;
for(int i=n;i>=1;i--) {
int now=i-1;
if(now<=st) break;
int cnt=now-st;
if(m-cnt>=0) m-=cnt,b[++st]=i;
else {
b[now-m+1]=i;
for(int j=1,t=1;j<=n;j++) if(!b[j]) b[j]=t++;
break;
}
}
int now=1;
for(int i=1;i<=n;i++) if(!b[i]) b[i]=now++;
for(int i=1;i<=n;i++) sum+=max(b[i],a[i]);
printf("%lld\n",sum);
for(int i=1;i<=n;i++) printf("%d ",a[i]); puts("");
for(int i=1;i<=n;i++) printf("%d ",b[i]); puts("");
}
return 0;
}
/*
*/