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 <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <assert.h>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n, k;
    cin >> n >> k;
    set<ll> s;
    vector<ll> v(n);
    for (int i = 0; i < n; ++i) {
        s.emplace(i+k); s.emplace(n+i+k);
        v[i] = k+2*n+i;
    }
    for (int i = 0; i < n; ++i) {
        ll a = 0, b = 0;
        a = *s.begin();
        if(v[i]-a < 0){
            puts("-1");
            return 0;
        }
        auto x = --s.upper_bound(v[i]-a);
        if(x == s.begin()){
            puts("-1");
            return 0;
        }
        b = *x;
        if(v[i]-b < 0){
            puts("-1");
            return 0;
        }
        auto y = --s.upper_bound(v[i]-b);
        if(x == y) --y;
        a = *y;
        s.erase(a);
        s.erase(b);
        assert(a+b <= v[i]);
        printf("%lld %lld %lld\n", a, b, v[i]);
    }
    return 0;
}