Problem:
Score : 700 points

Problem Statement

Given are positive integers N and K.

Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one of those triples.

For every integer i from 1 to N, a_i + b_i \leq c_i holds.

If the answer is yes, construct one such partition.

Constraints

1 \leq N \leq 10^5

1 \leq K \leq 10^9

Input

Input is given from Standard Input in the following format:

N K

Output

If it is impossible to partition the integers satisfying the condition, print -1. If it is possible, print N triples in the following format:

a_1 b_1 c_1
:
a_N b_N c_N

Sample Input 1

1 1

Sample Output 1

1 2 3

Sample Input 2

3 3

Sample Output 2

-1

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5;

typedef pair<int,int> pii;

int find_par(int x, int *par){
	if(par[x] == x) return x;
	return par[x] = find_par(par[x], par);
}

int n,k;

int li[2*N+5];
vector<pii> isi;
int last[2*N+5];

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=2*n;i++){
		li[i]=k+i-1;
		last[i] = i;
	}
	int idx = 2*n;
	for(int i=n;i>=1;i--){
		int butuh = k+2*n+i-1 - li[idx];
		if(butuh < li[1]){
			printf("-1\n");
			return 0;
		}
		butuh = min(butuh,li[idx-1]);
//		cout << ">> " << butuh << endl;
		int id = butuh - k + 1;
//		cout << id << endl;
		id = find_par(id,last);
		if(id == 0){
			printf("-1\n");
			return 0;
		}
		isi.push_back(make_pair(li[idx] , li[id]));
		last[id] = id-1;
    last[idx] = idx-1;
		idx = find_par(idx,last);
	}
	
	int id = 0;
	for(int i=k+3*n-1;i>k+2*n-1;i--){
		printf("%d %d %d\n",isi[id].first,isi[id].second,i);
//		assert(isi[id].first + isi[id].second <= i);
		id++;
	}
	return 0;
}