exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 220b4d24f15a53fa133fec90454d726e | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
static class DSU {
private int[] parent;
private int[] size;
private int totalGroup;
private int maxSize = 1;
public DSU(int n) {
parent = new int[n];
totalGroup = n;
for (int i = 0; i < n; i++) {
parent[i] = i;
}
size = new int[n];
Arrays.fill(size, 1);
}
public boolean union(int a, int b) {
int parentA = findParent(a);
int parentB = findParent(b);
if (parentA == parentB) {
return false;
}
totalGroup--;
if (parentA < parentB) {
this.parent[parentB] = parentA;
this.size[parentA] += this.size[parentB];
maxSize = Math.max(this.size[parentA], maxSize);
} else {
this.parent[parentA] = parentB;
this.size[parentB] += this.size[parentA];
maxSize = Math.max(this.size[parentB], maxSize);
}
return true;
}
public int findParent(int a) {
if (parent[a] != a) {
parent[a] = findParent(parent[a]);
}
return parent[a];
}
public int getGroupSize(int a) {
return this.size[findParent(a)];
}
public int getTotalGroup() {
return totalGroup;
}
}
public static void main(String[] args) throws Exception {
int tc = io.nextInt();
for (int i = 0; i < tc; i++) {
solve();
}
io.close();
}
private static void solve() throws Exception {
int n = io.nextInt();
int a = io.nextInt();
int b = io.nextInt();
if (Math.abs(a - b) > 1) {
io.println(-1);
return;
}
if (a + b > n - 2) {
io.println(-1);
return;
}
int[] data = new int[n];
for (int i = 0; i < n; i++) {
data[i] = i + 1;
}
if (b == a) {
for (int i = 1; i < n; i += 2) {
if (a > 0) {
int t = data[i];
data[i] = data[i + 1];
data[i + 1] = t;
a--;
}
}
} else {
if (a > b) {
for (int i = 0; i < n; i++) {
data[i] = n - i;
}
} else {
a = b;
}
for (int i = 0; i < n; i += 2) {
if (a > 0) {
int t = data[i];
data[i] = data[i + 1];
data[i + 1] = t;
a--;
}
}
}
for (int i = 0; i < n; i++) {
io.print(data[i]);
io.print(" ");
}
io.println();
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>(a.length);
for (int i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
//-----------PrintWriter for faster output---------------------------------
public static FastIO io = new FastIO();
//-----------MyScanner class for faster input----------
static class FastIO extends PrintWriter {
private InputStream stream;
private byte[] buf = new byte[1 << 16];
private int curChar, numChars;
// standard input
public FastIO() {
this(System.in, System.out);
}
public FastIO(InputStream i, OutputStream o) {
super(o);
stream = i;
}
// file input
public FastIO(String i, String o) throws IOException {
super(new FileWriter(o));
stream = new FileInputStream(i);
}
// throws InputMismatchException() if previously detected end of file
private int nextByte() {
if (numChars == -1) throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars == -1) return -1; // end of file
}
return buf[curChar++];
}
// to read in entire lines, replace c <= ' '
// with a function that checks whether c is a line break
public String next() {
int c;
do {
c = nextByte();
} while (c <= ' ');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > ' ');
return res.toString();
}
public String nextLine() {
int c;
do {
c = nextByte();
} while (c < '\n');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > '\n');
return res.toString();
}
public int nextInt() {
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public long nextLong() {
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
int[] nextInts(int n) {
int[] data = new int[n];
for (int i = 0; i < n; i++) {
data[i] = io.nextInt();
}
return data;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
//--------------------------------------------------------
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 58b053dd6ed7f8e9502575b00424ae7d | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.awt.Container;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
FastScanner input = new FastScanner();
int tc = input.nextInt();
StringBuilder result = new StringBuilder();
work:
while (tc-- > 0) {
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
int ans[] = new int[n];
if(a+b+2>n)
{
result.append("-1\n");
}
else if(Math.abs(a-b)>1)
{
result.append("-1\n");
}
else
{
if(a<b)
{
int i =1;
int serial = 1;
while(b-->0)
{
ans[i] = serial;
serial++;
i+=2;
}
i=0;
while(i<n)
{
if(ans[i]==0)
{
ans[i] = serial++;
}
i++;
}
}
else if(a>b)
{
int i =1;
int serial = n;
while(a-->0)
{
ans[i] = serial--;
i+=2;
}
i=0;
while(i<n)
{
if(ans[i]==0)
{
ans[i] = serial--;
}
i++;
}
}
else
{
int i = 1;
int serial = n;
while(a-->0)
{
ans[i] = serial--;
i+=2;
}
i=0;
serial=1;
while(i<n)
{
if(ans[i]==0)
{
ans[i] = serial++;
}
i++;
}
}
for (int i = 0; i <n; i++) {
result.append(ans[i]+" ");
}
result.append("\n");
}
}
System.out.println(result);
}
static class FastScanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next()
{
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() throws IOException
{
return br.readLine();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 963b34df47e496b132f94323236f19e7 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.awt.Container;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
FastScanner input = new FastScanner();
int tc = input.nextInt();
work:
while (tc-- > 0) {
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
int ans[] = new int[n];
if(a+b+2>n)
{
System.out.println("-1");
}
else if(Math.abs(a-b)>1)
{
System.out.println("-1");
}
else
{
if(a<b)
{
int i =1;
int serial = 1;
while(b-->0)
{
ans[i] = serial;
serial++;
i+=2;
}
i=0;
while(i<n)
{
if(ans[i]==0)
{
ans[i] = serial++;
}
i++;
}
}
else if(a>b)
{
int i =1;
int serial = n;
while(a-->0)
{
ans[i] = serial--;
i+=2;
}
i=0;
while(i<n)
{
if(ans[i]==0)
{
ans[i] = serial--;
}
i++;
}
}
else
{
int i = 1;
int serial = n;
while(a-->0)
{
ans[i] = serial--;
i+=2;
}
i=0;
serial=1;
while(i<n)
{
if(ans[i]==0)
{
ans[i] = serial++;
}
i++;
}
}
for (int i = 0; i <n; i++) {
System.out.print(ans[i]+" ");
}
System.out.println("");
}
}
}
static class FastScanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next()
{
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() throws IOException
{
return br.readLine();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 2934e5019b3da37d73ab7e271d791dd6 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
static long fans[] = new long[200001];
static long inv[] = new long[200001];
static long mod = 1000000007;
static void init() {
fans[0] = 1;
inv[0] = 1;
fans[1] = 1;
inv[1] = 1;
for (int i = 2; i < 200001; i++) {
fans[i] = ((long) i * fans[i - 1]) % mod;
inv[i] = power(fans[i], mod - 2);
}
}
static long ncr(int n, int r) {
return (((fans[n] * inv[n - r]) % mod) * (inv[r])) % mod;
}
public static void main(String[] args) throws java.lang.Exception {
FastReader in = new FastReader(System.in);
StringBuilder sb = new StringBuilder();
int t = 1;
t = in.nextInt();
while (t > 0) {
--t;
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int arr[] = new int[n];
int s = 1;
int e = n;
if(Math.abs(a-b)>1) {
sb.append("-1\n");
continue;
}
else if(a+b>n-2) {
sb.append("-1\n");
continue;
}
else if(a>b) {
for(int i = 1;i<n && a>0;i+=2,a--)
{
arr[i] = e;
--e;
}
for(int i = 2;i<n && b>0;i+=2,b--)
{
arr[i] = s;
++s;
}
for(int i = 0;i<n;i++)
{
if(arr[i] == 0)
{
arr[i] = e;
--e;
}
}
}
else if(a<b)
{
for(int i = 1;i<n && b>0;i+=2,b--)
{
arr[i] = s;
++s;
}
for(int i = 2;i<n && a>0;i+=2,a--)
{
arr[i] = e;
--e;
}
for(int i = 0;i<n;i++)
{
if(arr[i] == 0)
{
arr[i] = s;
++s;
}
}
}
else {
for(int i = 1;i<n && b>0;i+=2,b--)
{
arr[i] = s;
++s;
}
for(int i = 2;i<n && a>0;i+=2,a--)
{
arr[i] = e;
--e;
}
for(int i = 0;i<n;i++)
{
if(arr[i] == 0)
{
arr[i] = e;
--e;
}
}
}
for(int i = 0;i<n;i++)
sb.append(arr[i]+" ");
sb.append("\n");
}
System.out.print(sb);
}
static long power(long x, long y) {
long res = 1; // Initialize result
while (y > 0) {
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = ((res % mod) * (x % mod)) % mod;
// y must be even now
y = y >> 1; // y = y/2
x = ((x % mod) * (x % mod)) % mod; // Change x to x^2
}
return res;
}
static long[] generateArray(FastReader in, int n) throws IOException {
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = in.nextLong();
return arr;
}
static long[][] generatematrix(FastReader in, int n, int m) throws IOException {
long arr[][] = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = in.nextLong();
}
}
return arr;
}
static long gcd(long a, long b) {
if (a == 0)
return b;
else
return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
}
class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan())
;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
String nextLine() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan())
;
StringBuilder sb = new StringBuilder();
for (; c != 10 && c != 13; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
char nextChar() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan())
;
return (char) c;
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan())
;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan())
;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | faac6ce9afdcbbbcfde4f4138877528b | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class rough {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tt = 0; tt < t; tt++){
int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
int[] ans = new int[n];
if(a+b > n-2){
System.out.println("-1");
continue;
} else if(Math.abs(a - b ) > 1){
System.out.println("-1");
continue;
}
if(a > b){
int curr = n;
for(int i = 1, cnt = 0; cnt < a; cnt++,i+=2){
ans[i] = curr; curr--;
}
int right = curr;
curr = 1;
for(int i = 2,cnt = 0; cnt < b; cnt++,i+=2){
ans[i] = curr; curr++;
}
ans[0] = right--;
for(int i = a+b+1; i < n; i++){
ans[i] = right--;
}
}
if(b > a){
int curr = 1;
for(int i = 1,cnt = 0; cnt < b; i+=2, cnt++){
ans[i] = curr; curr++;
}
int right = curr;
curr = n;
for(int i = 2,cnt = 0; cnt < a; i+=2,cnt++){
ans[i] = curr; curr--;
}
ans[0] = right++;
for(int i = a+b+1; i < n; i++){
ans[i] = right++;
}
}
if(a == b){
int curr = n;
for(int i = 1, cnt = 0; cnt < a; cnt++,i+=2){
ans[i] = curr; curr--;
}
curr = 1;
for(int i = 2,cnt = 0; cnt < b; cnt++,i+=2){
ans[i] = curr; curr++;
}
int left = curr;
ans[0] = left++;
for(int i = a+b+1; i < n; i++){
ans[i] = left++;
}
}
for(int i = 0; i < n; i++){
System.out.println(ans[i]);
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 8ebd1fef087cbb44691f6f368aefb679 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.io.*;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.Socket;
import java.util.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner cin=new Scanner(System.in);
int t =cin.nextInt();
while(t-->0)
{
int n=cin.nextInt();
int x=cin.nextInt();
int y=cin.nextInt();
int []a=new int[n+1];
if(Math.abs(x-y)>=2||x+y>n-2)
{
System.out.println("-1");
}
else
{
for(int i=1;i<=n;i++)
{
a[i]=i;
}
int num=Math.min(x,y);
if(x>y)
{
for (int i = 2; i < n; i += 2) {
if (num > 0) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
num--;
}
}
int temp = a[n];
a[n] = a[n-1];
a[n-1] = temp;
}
else if(x==y)
{
for (int i = 2; i < n; i += 2) {
if (num > 0) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
num--;
}
}
}
else
{
for (int i = 3; i < n; i += 2) {
if (num > 0) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
num--;
}
}
int temp = a[1];
a[1] = a[2];
a[2] = temp;
}
for(int i=1;i<=n;i++)
{
System.out.print(a[i]+" ");
}
System.out.println();
}
}
}
public class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 39296a7a4be19340b164f9e4279d67c3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class s{
static boolean flag;
public static void max(int n, int a, int b, int ans[]){
boolean ar[]= new boolean[n+1];
int l = n;
int c=0;
for (int i =2;i<=n-1;i+=2){
ans[i]= l;
ar[l]= true;
l--;
c++;
if (c==a) break;
}
if (c!=a) {
flag = false;
return;
}
l = n;
int nn = c-1;
if (b>c && b<(c-1)){
flag = false;
return;
}
if (b==c){
if (ans[n-1]==0){
ans[n-1]=1;
ar[1]= true;
}
else{
flag = false;
return;
}
}
Stack<Integer> st = new Stack<>();
for (int i =1;i<=n;i++){
if (!ar[i]) st.push(i);
}
for (int i=1;i<=n;i++){
if (ans[i]==0) ans[i]=st.pop();
}
}
public static void mn(int n, int a, int b, int ans[]){
boolean ar[]= new boolean[n+1];
int l = 1;
int c=0;
for (int i =2;i<=n-1;i+=2){
ans[i]= l;
ar[l]= true;
l++;
c++;
if (c==a) break;
}
if (c!=a) {
flag = false;
return;
}
l = n;
int nn = c-1;
if (b>c && b<(c-1)){
flag = false;
return;
}
if (b==c){
if (ans[n-1]==0){
ans[n-1]=n;
ar[n]= true;
}
else{
flag = false;
return;
}
}
Stack<Integer> st = new Stack<>();
for (int i =n;i>=1;i--){
if (!ar[i]) st.push(i);
}
for (int i=1;i<=n;i++){
if (ans[i]==0) ans[i]=st.pop();
}
}
public static void main (String [] args) throws IOException{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int t = Integer.parseInt(br.readLine());
while (t-->0){
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
flag = true;
if ((int)Math.abs(a-b)>1) {
System.out.println (-1);
continue;
}
int ans[]= new int[n+1];
if (a==0 && b==0){
for (int i=1;i<=n;i++){
System.out.print (i+" ");
}
System.out.println ();
continue;
}
else if (a>=b){
max (n,a,b,ans);
}
else{
mn (n,b,a,ans);
}
if (flag == false) {
System.out.println (-1);
continue;
}
for (int i=1;i<=n;i++){
System.out.print (ans[i]+" ");
}
System.out.println ();
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 5aa8a6b2883eb2bbde84d8ae9bfc5c5d | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class B_758
{
public static final long[] POWER2 = generatePOWER2();
public static final IteratorBuffer<Long> ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator());
public static long BIG = 1000000000 + 7;
private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer stringTokenizer = null;
private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static class Array<Type>
implements Iterable<Type>
{
private final Object[] array;
public Array(int size)
{
this.array = new Object[size];
}
public Array(int size, Type element)
{
this(size);
Arrays.fill(this.array, element);
}
public Array(Array<Type> array, Type element)
{
this(array.size() + 1);
for (int index = 0; index < array.size(); index++)
{
set(index, array.get(index));
}
set(size() - 1, element);
}
public Array(List<Type> list)
{
this(list.size());
int index = 0;
for (Type element: list)
{
set(index, element);
index += 1;
}
}
public Type get(int index)
{
return (Type) this.array[index];
}
@Override
public Iterator<Type> iterator()
{
return new Iterator<Type>()
{
int index = 0;
@Override
public boolean hasNext()
{
return this.index < size();
}
@Override
public Type next()
{
Type result = Array.this.get(index);
index += 1;
return result;
}
};
}
public Array set(int index, Type value)
{
this.array[index] = value;
return this;
}
public int size()
{
return this.array.length;
}
public List<Type> toList()
{
List<Type> result = new ArrayList<>();
for (Type element: this)
{
result.add(element);
}
return result;
}
@Override
public String toString()
{
return "[" + B_758.toString(this, ", ") + "]";
}
}
static class BIT
{
private static int lastBit(int index)
{
return index & -index;
}
private final long[] tree;
public BIT(int size)
{
this.tree = new long[size];
}
public void add(int index, long delta)
{
index += 1;
while (index <= this.tree.length)
{
tree[index - 1] += delta;
index += lastBit(index);
}
}
public long prefix(int end)
{
long result = 0;
while (end > 0)
{
result += this.tree[end - 1];
end -= lastBit(end);
}
return result;
}
public int size()
{
return this.tree.length;
}
public long sum(int start, int end)
{
return prefix(end) - prefix(start);
}
}
static abstract class Edge<TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>>
{
public final TypeVertex vertex0;
public final TypeVertex vertex1;
public final boolean bidirectional;
public Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)
{
this.vertex0 = vertex0;
this.vertex1 = vertex1;
this.bidirectional = bidirectional;
this.vertex0.edges.add(getThis());
if (this.bidirectional)
{
this.vertex1.edges.add(getThis());
}
}
public abstract TypeEdge getThis();
public TypeVertex other(Vertex<TypeVertex, TypeEdge> vertex)
{
TypeVertex result;
if (vertex0 == vertex)
{
result = vertex1;
}
else
{
result = vertex0;
}
return result;
}
public void remove()
{
this.vertex0.edges.remove(getThis());
if (this.bidirectional)
{
this.vertex1.edges.remove(getThis());
}
}
@Override
public String toString()
{
return this.vertex0 + "->" + this.vertex1;
}
}
public static class EdgeDefault<TypeVertex extends Vertex<TypeVertex, EdgeDefault<TypeVertex>>>
extends Edge<TypeVertex, EdgeDefault<TypeVertex>>
{
public EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)
{
super(vertex0, vertex1, bidirectional);
}
@Override
public EdgeDefault<TypeVertex> getThis()
{
return this;
}
}
public static class EdgeDefaultDefault
extends Edge<VertexDefaultDefault, EdgeDefaultDefault>
{
public EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)
{
super(vertex0, vertex1, bidirectional);
}
@Override
public EdgeDefaultDefault getThis()
{
return this;
}
}
public static class FIFO<Type>
{
public SingleLinkedList<Type> start;
public SingleLinkedList<Type> end;
public FIFO()
{
this.start = null;
this.end = null;
}
public boolean isEmpty()
{
return this.start == null;
}
public Type peek()
{
return this.start.element;
}
public Type pop()
{
Type result = this.start.element;
this.start = this.start.next;
return result;
}
public void push(Type element)
{
SingleLinkedList<Type> list = new SingleLinkedList<>(element, null);
if (this.start == null)
{
this.start = list;
this.end = list;
}
else
{
this.end.next = list;
this.end = list;
}
}
}
static class Fraction
implements Comparable<Fraction>
{
public static final Fraction ZERO = new Fraction(0, 1);
public static Fraction fraction(long whole)
{
return fraction(whole, 1);
}
public static Fraction fraction(long numerator, long denominator)
{
Fraction result;
if (denominator == 0)
{
throw new ArithmeticException();
}
if (numerator == 0)
{
result = Fraction.ZERO;
}
else
{
int sign;
if (numerator < 0 ^ denominator < 0)
{
sign = -1;
numerator = Math.abs(numerator);
denominator = Math.abs(denominator);
}
else
{
sign = 1;
}
long gcd = gcd(numerator, denominator);
result = new Fraction(sign * numerator / gcd, denominator / gcd);
}
return result;
}
public final long numerator;
public final long denominator;
private Fraction(long numerator, long denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}
public Fraction add(Fraction fraction)
{
return fraction(this.numerator * fraction.denominator + fraction.numerator * this.denominator, this.denominator * fraction.denominator);
}
@Override
public int compareTo(Fraction that)
{
return Long.compare(this.numerator * that.denominator, that.numerator * this.denominator);
}
public Fraction divide(Fraction fraction)
{
return multiply(fraction.inverse());
}
public boolean equals(Fraction that)
{
return this.compareTo(that) == 0;
}
public boolean equals(Object that)
{
return this.compareTo((Fraction) that) == 0;
}
public Fraction getRemainder()
{
return fraction(this.numerator - getWholePart() * denominator, denominator);
}
public long getWholePart()
{
return this.numerator / this.denominator;
}
public Fraction inverse()
{
return fraction(this.denominator, this.numerator);
}
public Fraction multiply(Fraction fraction)
{
return fraction(this.numerator * fraction.numerator, this.denominator * fraction.denominator);
}
public Fraction neg()
{
return fraction(-this.numerator, this.denominator);
}
public Fraction sub(Fraction fraction)
{
return add(fraction.neg());
}
@Override
public String toString()
{
String result;
if (getRemainder().equals(Fraction.ZERO))
{
result = "" + this.numerator;
}
else
{
result = this.numerator + "/" + this.denominator;
}
return result;
}
}
static class IteratorBuffer<Type>
{
private Iterator<Type> iterator;
private List<Type> list;
public IteratorBuffer(Iterator<Type> iterator)
{
this.iterator = iterator;
this.list = new ArrayList<Type>();
}
public Iterator<Type> iterator()
{
return new Iterator<Type>()
{
int index = 0;
@Override
public boolean hasNext()
{
return this.index < list.size() || IteratorBuffer.this.iterator.hasNext();
}
@Override
public Type next()
{
if (list.size() <= this.index)
{
list.add(iterator.next());
}
Type result = list.get(index);
index += 1;
return result;
}
};
}
}
public static class MapCount<Type>
extends SortedMapAVL<Type, Long>
{
private int count;
public MapCount(Comparator<? super Type> comparator)
{
super(comparator);
this.count = 0;
}
public long add(Type key, Long delta)
{
long result;
if (delta > 0)
{
Long value = get(key);
if (value == null)
{
value = delta;
}
else
{
value += delta;
}
put(key, value);
result = delta;
}
else
{
result = 0;
}
this.count += result;
return result;
}
public int count()
{
return this.count;
}
public List<Type> flatten()
{
List<Type> result = new ArrayList<>();
for (Entry<Type, Long> entry: entrySet())
{
for (long index = 0; index < entry.getValue(); index++)
{
result.add(entry.getKey());
}
}
return result;
}
@Override
public SortedMapAVL<Type, Long> headMap(Type keyEnd)
{
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map<? extends Type, ? extends Long> map)
{
throw new UnsupportedOperationException();
}
public long remove(Type key, Long delta)
{
long result;
if (delta > 0)
{
Long value = get(key) - delta;
if (value <= 0)
{
result = delta + value;
remove(key);
}
else
{
result = delta;
put(key, value);
}
}
else
{
result = 0;
}
this.count -= result;
return result;
}
@Override
public Long remove(Object key)
{
Long result = super.remove(key);
this.count -= result;
return result;
}
@Override
public SortedMapAVL<Type, Long> subMap(Type keyStart, Type keyEnd)
{
throw new UnsupportedOperationException();
}
@Override
public SortedMapAVL<Type, Long> tailMap(Type keyStart)
{
throw new UnsupportedOperationException();
}
}
public static class MapSet<TypeKey, TypeValue>
extends SortedMapAVL<TypeKey, SortedSetAVL<TypeValue>>
implements Iterable<TypeValue>
{
private Comparator<? super TypeValue> comparatorValue;
public MapSet(Comparator<? super TypeKey> comparatorKey, Comparator<? super TypeValue> comparatorValue)
{
super(comparatorKey);
this.comparatorValue = comparatorValue;
}
public MapSet(Comparator<? super TypeKey> comparatorKey, SortedSetAVL<Entry<TypeKey, SortedSetAVL<TypeValue>>> entrySet, Comparator<? super TypeValue> comparatorValue)
{
super(comparatorKey, entrySet);
this.comparatorValue = comparatorValue;
}
public boolean add(TypeKey key, TypeValue value)
{
SortedSetAVL<TypeValue> set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));
return set.add(value);
}
public TypeValue firstValue()
{
TypeValue result;
Entry<TypeKey, SortedSetAVL<TypeValue>> firstEntry = firstEntry();
if (firstEntry == null)
{
result = null;
}
else
{
result = firstEntry.getValue().first();
}
return result;
}
@Override
public MapSet<TypeKey, TypeValue> headMap(TypeKey keyEnd)
{
return new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);
}
public Iterator<TypeValue> iterator()
{
return new Iterator<TypeValue>()
{
Iterator<SortedSetAVL<TypeValue>> iteratorValues = values().iterator();
Iterator<TypeValue> iteratorValue = null;
@Override
public boolean hasNext()
{
return iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());
}
@Override
public TypeValue next()
{
if (iteratorValue == null || !iteratorValue.hasNext())
{
iteratorValue = iteratorValues.next().iterator();
}
return iteratorValue.next();
}
};
}
public TypeValue lastValue()
{
TypeValue result;
Entry<TypeKey, SortedSetAVL<TypeValue>> lastEntry = lastEntry();
if (lastEntry == null)
{
result = null;
}
else
{
result = lastEntry.getValue().last();
}
return result;
}
public boolean removeSet(TypeKey key, TypeValue value)
{
boolean result;
SortedSetAVL<TypeValue> set = get(key);
if (set == null)
{
result = false;
}
else
{
result = set.remove(value);
if (set.size() == 0)
{
remove(key);
}
}
return result;
}
@Override
public MapSet<TypeKey, TypeValue> tailMap(TypeKey keyStart)
{
return new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);
}
}
public static class Matrix
{
public final int rows;
public final int columns;
public final Fraction[][] cells;
public Matrix(int rows, int columns)
{
this.rows = rows;
this.columns = columns;
this.cells = new Fraction[rows][columns];
for (int row = 0; row < rows; row++)
{
for (int column = 0; column < columns; column++)
{
set(row, column, Fraction.ZERO);
}
}
}
public void add(int rowSource, int rowTarget, Fraction fraction)
{
for (int column = 0; column < columns; column++)
{
this.cells[rowTarget][column] = this.cells[rowTarget][column].add(this.cells[rowSource][column].multiply(fraction));
}
}
private int columnPivot(int row)
{
int result = this.columns;
for (int column = this.columns - 1; 0 <= column; column--)
{
if (this.cells[row][column].compareTo(Fraction.ZERO) != 0)
{
result = column;
}
}
return result;
}
public void reduce()
{
for (int rowMinimum = 0; rowMinimum < this.rows; rowMinimum++)
{
int rowPivot = rowPivot(rowMinimum);
if (rowPivot != -1)
{
int columnPivot = columnPivot(rowPivot);
Fraction current = this.cells[rowMinimum][columnPivot];
Fraction pivot = this.cells[rowPivot][columnPivot];
Fraction fraction = pivot.inverse().sub(current.divide(pivot));
add(rowPivot, rowMinimum, fraction);
for (int row = rowMinimum + 1; row < this.rows; row++)
{
if (columnPivot(row) == columnPivot)
{
add(rowMinimum, row, this.cells[row][columnPivot(row)].neg());
}
}
}
}
}
private int rowPivot(int rowMinimum)
{
int result = -1;
int pivotColumnMinimum = this.columns;
for (int row = rowMinimum; row < this.rows; row++)
{
int pivotColumn = columnPivot(row);
if (pivotColumn < pivotColumnMinimum)
{
result = row;
pivotColumnMinimum = pivotColumn;
}
}
return result;
}
public void set(int row, int column, Fraction value)
{
this.cells[row][column] = value;
}
public String toString()
{
String result = "";
for (int row = 0; row < rows; row++)
{
for (int column = 0; column < columns; column++)
{
result += this.cells[row][column] + "\t";
}
result += "\n";
}
return result;
}
}
public static class Node<Type>
{
public static <Type> Node<Type> balance(Node<Type> result)
{
while (result != null && 1 < Math.abs(height(result.left) - height(result.right)))
{
if (height(result.left) < height(result.right))
{
Node<Type> right = result.right;
if (height(right.right) < height(right.left))
{
result = new Node<>(result.value, result.left, right.rotateRight());
}
result = result.rotateLeft();
}
else
{
Node<Type> left = result.left;
if (height(left.left) < height(left.right))
{
result = new Node<>(result.value, left.rotateLeft(), result.right);
}
result = result.rotateRight();
}
}
return result;
}
public static <Type> Node<Type> clone(Node<Type> result)
{
if (result != null)
{
result = new Node<>(result.value, clone(result.left), clone(result.right));
}
return result;
}
public static <Type> Node<Type> delete(Node<Type> node, Type value, Comparator<? super Type> comparator)
{
Node<Type> result;
if (node == null)
{
result = null;
}
else
{
int compare = comparator.compare(value, node.value);
if (compare == 0)
{
if (node.left == null)
{
result = node.right;
}
else
{
if (node.right == null)
{
result = node.left;
}
else
{
Node<Type> first = first(node.right);
result = new Node<>(first.value, node.left, delete(node.right, first.value, comparator));
}
}
}
else
{
if (compare < 0)
{
result = new Node<>(node.value, delete(node.left, value, comparator), node.right);
}
else
{
result = new Node<>(node.value, node.left, delete(node.right, value, comparator));
}
}
result = balance(result);
}
return result;
}
public static <Type> Node<Type> first(Node<Type> result)
{
while (result.left != null)
{
result = result.left;
}
return result;
}
public static <Type> Node<Type> get(Node<Type> node, Type value, Comparator<? super Type> comparator)
{
Node<Type> result;
if (node == null)
{
result = null;
}
else
{
int compare = comparator.compare(value, node.value);
if (compare == 0)
{
result = node;
}
else
{
if (compare < 0)
{
result = get(node.left, value, comparator);
}
else
{
result = get(node.right, value, comparator);
}
}
}
return result;
}
public static <Type> Node<Type> head(Node<Type> node, Type value, Comparator<? super Type> comparator)
{
Node<Type> result;
if (node == null)
{
result = null;
}
else
{
int compare = comparator.compare(value, node.value);
if (compare == 0)
{
result = node.left;
}
else
{
if (compare < 0)
{
result = head(node.left, value, comparator);
}
else
{
result = new Node<>(node.value, node.left, head(node.right, value, comparator));
}
}
result = balance(result);
}
return result;
}
public static int height(Node node)
{
return node == null ? 0 : node.height;
}
public static <Type> Node<Type> insert(Node<Type> node, Type value, Comparator<? super Type> comparator)
{
Node<Type> result;
if (node == null)
{
result = new Node<>(value, null, null);
}
else
{
int compare = comparator.compare(value, node.value);
if (compare == 0)
{
result = new Node<>(value, node.left, node.right);
;
}
else
{
if (compare < 0)
{
result = new Node<>(node.value, insert(node.left, value, comparator), node.right);
}
else
{
result = new Node<>(node.value, node.left, insert(node.right, value, comparator));
}
}
result = balance(result);
}
return result;
}
public static <Type> Node<Type> last(Node<Type> result)
{
while (result.right != null)
{
result = result.right;
}
return result;
}
public static int size(Node node)
{
return node == null ? 0 : node.size;
}
public static <Type> Node<Type> tail(Node<Type> node, Type value, Comparator<? super Type> comparator)
{
Node<Type> result;
if (node == null)
{
result = null;
}
else
{
int compare = comparator.compare(value, node.value);
if (compare == 0)
{
result = new Node<>(node.value, null, node.right);
}
else
{
if (compare < 0)
{
result = new Node<>(node.value, tail(node.left, value, comparator), node.right);
}
else
{
result = tail(node.right, value, comparator);
}
}
result = balance(result);
}
return result;
}
public static <Type> void traverseOrderIn(Node<Type> node, Consumer<Type> consumer)
{
if (node != null)
{
traverseOrderIn(node.left, consumer);
consumer.accept(node.value);
traverseOrderIn(node.right, consumer);
}
}
public final Type value;
public final Node<Type> left;
public final Node<Type> right;
public final int size;
private final int height;
public Node(Type value, Node<Type> left, Node<Type> right)
{
this.value = value;
this.left = left;
this.right = right;
this.size = 1 + size(left) + size(right);
this.height = 1 + Math.max(height(left), height(right));
}
public Node<Type> rotateLeft()
{
Node<Type> left = new Node<>(this.value, this.left, this.right.left);
return new Node<>(this.right.value, left, this.right.right);
}
public Node<Type> rotateRight()
{
Node<Type> right = new Node<>(this.value, this.left.right, this.right);
return new Node<>(this.left.value, this.left.left, right);
}
}
public static class SingleLinkedList<Type>
{
public final Type element;
public SingleLinkedList<Type> next;
public SingleLinkedList(Type element, SingleLinkedList<Type> next)
{
this.element = element;
this.next = next;
}
public void toCollection(Collection<Type> collection)
{
if (this.next != null)
{
this.next.toCollection(collection);
}
collection.add(this.element);
}
}
public static class SmallSetIntegers
{
public static final int SIZE = 20;
public static final int[] SET = generateSet();
public static final int[] COUNT = generateCount();
public static final int[] INTEGER = generateInteger();
private static int count(int set)
{
int result = 0;
for (int integer = 0; integer < SIZE; integer++)
{
if (0 < (set & set(integer)))
{
result += 1;
}
}
return result;
}
private static final int[] generateCount()
{
int[] result = new int[1 << SIZE];
for (int set = 0; set < result.length; set++)
{
result[set] = count(set);
}
return result;
}
private static final int[] generateInteger()
{
int[] result = new int[1 << SIZE];
Arrays.fill(result, -1);
for (int integer = 0; integer < SIZE; integer++)
{
result[SET[integer]] = integer;
}
return result;
}
private static final int[] generateSet()
{
int[] result = new int[SIZE];
for (int integer = 0; integer < result.length; integer++)
{
result[integer] = set(integer);
}
return result;
}
private static int set(int integer)
{
return 1 << integer;
}
}
public static class SortedMapAVL<TypeKey, TypeValue>
implements SortedMap<TypeKey, TypeValue>
{
public final Comparator<? super TypeKey> comparator;
public final SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet;
public SortedMapAVL(Comparator<? super TypeKey> comparator)
{
this(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));
}
private SortedMapAVL(Comparator<? super TypeKey> comparator, SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet)
{
this.comparator = comparator;
this.entrySet = entrySet;
}
@Override
public void clear()
{
this.entrySet.clear();
}
@Override
public Comparator<? super TypeKey> comparator()
{
return this.comparator;
}
@Override
public boolean containsKey(Object key)
{
return this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null));
}
@Override
public boolean containsValue(Object value)
{
throw new UnsupportedOperationException();
}
@Override
public SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet()
{
return this.entrySet;
}
public Entry<TypeKey, TypeValue> firstEntry()
{
return this.entrySet.first();
}
@Override
public TypeKey firstKey()
{
return firstEntry().getKey();
}
@Override
public TypeValue get(Object key)
{
Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);
entry = this.entrySet.get(entry);
return entry == null ? null : entry.getValue();
}
@Override
public SortedMapAVL<TypeKey, TypeValue> headMap(TypeKey keyEnd)
{
return new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));
}
@Override
public boolean isEmpty()
{
return this.entrySet.isEmpty();
}
@Override
public Set<TypeKey> keySet()
{
return new SortedSet<TypeKey>()
{
@Override
public boolean add(TypeKey typeKey)
{
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends TypeKey> collection)
{
throw new UnsupportedOperationException();
}
@Override
public void clear()
{
throw new UnsupportedOperationException();
}
@Override
public Comparator<? super TypeKey> comparator()
{
throw new UnsupportedOperationException();
}
@Override
public boolean contains(Object o)
{
throw new UnsupportedOperationException();
}
@Override
public boolean containsAll(Collection<?> collection)
{
throw new UnsupportedOperationException();
}
@Override
public TypeKey first()
{
throw new UnsupportedOperationException();
}
@Override
public SortedSet<TypeKey> headSet(TypeKey typeKey)
{
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty()
{
return size() == 0;
}
@Override
public Iterator<TypeKey> iterator()
{
final Iterator<Entry<TypeKey, TypeValue>> iterator = SortedMapAVL.this.entrySet.iterator();
return new Iterator<TypeKey>()
{
@Override
public boolean hasNext()
{
return iterator.hasNext();
}
@Override
public TypeKey next()
{
return iterator.next().getKey();
}
};
}
@Override
public TypeKey last()
{
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object o)
{
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> collection)
{
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> collection)
{
throw new UnsupportedOperationException();
}
@Override
public int size()
{
return SortedMapAVL.this.entrySet.size();
}
@Override
public SortedSet<TypeKey> subSet(TypeKey typeKey, TypeKey e1)
{
throw new UnsupportedOperationException();
}
@Override
public SortedSet<TypeKey> tailSet(TypeKey typeKey)
{
throw new UnsupportedOperationException();
}
@Override
public Object[] toArray()
{
throw new UnsupportedOperationException();
}
@Override
public <T> T[] toArray(T[] ts)
{
throw new UnsupportedOperationException();
}
};
}
public Entry<TypeKey, TypeValue> lastEntry()
{
return this.entrySet.last();
}
@Override
public TypeKey lastKey()
{
return lastEntry().getKey();
}
@Override
public TypeValue put(TypeKey key, TypeValue value)
{
TypeValue result = get(key);
Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>(key, value);
this.entrySet().add(entry);
return result;
}
@Override
public void putAll(Map<? extends TypeKey, ? extends TypeValue> map)
{
map.entrySet()
.forEach(entry -> put(entry.getKey(), entry.getValue()));
}
@Override
public TypeValue remove(Object key)
{
TypeValue result = get(key);
Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);
this.entrySet.remove(entry);
return result;
}
@Override
public int size()
{
return this.entrySet().size();
}
@Override
public SortedMapAVL<TypeKey, TypeValue> subMap(TypeKey keyStart, TypeKey keyEnd)
{
return new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));
}
@Override
public SortedMapAVL<TypeKey, TypeValue> tailMap(TypeKey keyStart)
{
return new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));
}
@Override
public String toString()
{
return this.entrySet().toString();
}
@Override
public Collection<TypeValue> values()
{
return new Collection<TypeValue>()
{
@Override
public boolean add(TypeValue typeValue)
{
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends TypeValue> collection)
{
throw new UnsupportedOperationException();
}
@Override
public void clear()
{
throw new UnsupportedOperationException();
}
@Override
public boolean contains(Object value)
{
throw new UnsupportedOperationException();
}
@Override
public boolean containsAll(Collection<?> collection)
{
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty()
{
return SortedMapAVL.this.entrySet.isEmpty();
}
@Override
public Iterator<TypeValue> iterator()
{
return new Iterator<TypeValue>()
{
Iterator<Entry<TypeKey, TypeValue>> iterator = SortedMapAVL.this.entrySet.iterator();
@Override
public boolean hasNext()
{
return this.iterator.hasNext();
}
@Override
public TypeValue next()
{
return this.iterator.next().getValue();
}
};
}
@Override
public boolean remove(Object o)
{
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> collection)
{
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> collection)
{
throw new UnsupportedOperationException();
}
@Override
public int size()
{
return SortedMapAVL.this.entrySet.size();
}
@Override
public Object[] toArray()
{
throw new UnsupportedOperationException();
}
@Override
public <T> T[] toArray(T[] ts)
{
throw new UnsupportedOperationException();
}
};
}
}
public static class SortedSetAVL<Type>
implements SortedSet<Type>
{
public Comparator<? super Type> comparator;
public Node<Type> root;
private SortedSetAVL(Comparator<? super Type> comparator, Node<Type> root)
{
this.comparator = comparator;
this.root = root;
}
public SortedSetAVL(Comparator<? super Type> comparator)
{
this(comparator, null);
}
public SortedSetAVL(Collection<? extends Type> collection, Comparator<? super Type> comparator)
{
this(comparator, null);
this.addAll(collection);
}
public SortedSetAVL(SortedSetAVL<Type> sortedSetAVL)
{
this(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));
}
@Override
public boolean add(Type value)
{
int sizeBefore = size();
this.root = Node.insert(this.root, value, this.comparator);
return sizeBefore != size();
}
@Override
public boolean addAll(Collection<? extends Type> collection)
{
return collection.stream()
.map(this::add)
.reduce(true, (x, y) -> x | y);
}
@Override
public void clear()
{
this.root = null;
}
@Override
public Comparator<? super Type> comparator()
{
return this.comparator;
}
@Override
public boolean contains(Object value)
{
return Node.get(this.root, (Type) value, this.comparator) != null;
}
@Override
public boolean containsAll(Collection<?> collection)
{
return collection.stream()
.allMatch(this::contains);
}
@Override
public Type first()
{
return Node.first(this.root).value;
}
public Type get(Type value)
{
Node<Type> node = Node.get(this.root, value, this.comparator);
return node == null ? null : node.value;
}
@Override
public SortedSetAVL<Type> headSet(Type valueEnd)
{
return new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));
}
@Override
public boolean isEmpty()
{
return this.root == null;
}
@Override
public Iterator<Type> iterator()
{
Stack<Node<Type>> path = new Stack<>();
return new Iterator<Type>()
{
{
push(SortedSetAVL.this.root);
}
@Override
public boolean hasNext()
{
return !path.isEmpty();
}
@Override
public Type next()
{
if (path.isEmpty())
{
throw new NoSuchElementException();
}
else
{
Node<Type> node = path.peek();
Type result = node.value;
if (node.right != null)
{
push(node.right);
}
else
{
do
{
node = path.pop();
}
while (!path.isEmpty() && path.peek().right == node);
}
return result;
}
}
public void push(Node<Type> node)
{
while (node != null)
{
path.push(node);
node = node.left;
}
}
};
}
@Override
public Type last()
{
return Node.last(this.root).value;
}
@Override
public boolean remove(Object value)
{
int sizeBefore = size();
this.root = Node.delete(this.root, (Type) value, this.comparator);
return sizeBefore != size();
}
@Override
public boolean removeAll(Collection<?> collection)
{
return collection.stream()
.map(this::remove)
.reduce(true, (x, y) -> x | y);
}
@Override
public boolean retainAll(Collection<?> collection)
{
SortedSetAVL<Type> set = new SortedSetAVL<>(this.comparator);
collection.stream()
.map(element -> (Type) element)
.filter(this::contains)
.forEach(set::add);
boolean result = size() != set.size();
this.root = set.root;
return result;
}
@Override
public int size()
{
return this.root == null ? 0 : this.root.size;
}
@Override
public SortedSetAVL<Type> subSet(Type valueStart, Type valueEnd)
{
return tailSet(valueStart).headSet(valueEnd);
}
@Override
public SortedSetAVL<Type> tailSet(Type valueStart)
{
return new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));
}
@Override
public Object[] toArray()
{
return toArray(new Object[0]);
}
@Override
public <T> T[] toArray(T[] ts)
{
List<Object> list = new ArrayList<>();
Node.traverseOrderIn(this.root, list::add);
return list.toArray(ts);
}
@Override
public String toString()
{
return "{" + B_758.toString(this, ", ") + "}";
}
}
public static class Tree2D
{
public static final int SIZE = 1 << 30;
public static final Tree2D[] TREES_NULL = new Tree2D[]{null, null, null, null};
public static boolean contains(int x, int y, int left, int bottom, int size)
{
return left <= x && x < left + size && bottom <= y && y < bottom + size;
}
public static int count(Tree2D[] trees)
{
int result = 0;
for (int index = 0; index < 4; index++)
{
if (trees[index] != null)
{
result += trees[index].count;
}
}
return result;
}
public static int count
(
int rectangleLeft,
int rectangleBottom,
int rectangleRight,
int rectangleTop,
Tree2D tree,
int left,
int bottom,
int size
)
{
int result;
if (tree == null)
{
result = 0;
}
else
{
int right = left + size;
int top = bottom + size;
int intersectionLeft = Math.max(rectangleLeft, left);
int intersectionBottom = Math.max(rectangleBottom, bottom);
int intersectionRight = Math.min(rectangleRight, right);
int intersectionTop = Math.min(rectangleTop, top);
if (intersectionRight <= intersectionLeft || intersectionTop <= intersectionBottom)
{
result = 0;
}
else
{
if (intersectionLeft == left && intersectionBottom == bottom && intersectionRight == right && intersectionTop == top)
{
result = tree.count;
}
else
{
size = size >> 1;
result = 0;
for (int index = 0; index < 4; index++)
{
result += count
(
rectangleLeft,
rectangleBottom,
rectangleRight,
rectangleTop,
tree.trees[index],
quadrantLeft(left, size, index),
quadrantBottom(bottom, size, index),
size
);
}
}
}
}
return result;
}
public static int quadrantBottom(int bottom, int size, int index)
{
return bottom + (index >> 1) * size;
}
public static int quadrantLeft(int left, int size, int index)
{
return left + (index & 1) * size;
}
public final Tree2D[] trees;
public final int count;
private Tree2D(Tree2D[] trees, int count)
{
this.trees = trees;
this.count = count;
}
public Tree2D(Tree2D[] trees)
{
this(trees, count(trees));
}
public Tree2D()
{
this(TREES_NULL);
}
public int count(int rectangleLeft, int rectangleBottom, int rectangleRight, int rectangleTop)
{
return count
(
rectangleLeft,
rectangleBottom,
rectangleRight,
rectangleTop,
this,
0,
0,
SIZE
);
}
public Tree2D setPoint
(
int x,
int y,
Tree2D tree,
int left,
int bottom,
int size
)
{
Tree2D result;
if (contains(x, y, left, bottom, size))
{
if (size == 1)
{
result = new Tree2D(TREES_NULL, 1);
}
else
{
size = size >> 1;
Tree2D[] trees = new Tree2D[4];
for (int index = 0; index < 4; index++)
{
trees[index] = setPoint
(
x,
y,
tree == null ? null : tree.trees[index],
quadrantLeft(left, size, index),
quadrantBottom(bottom, size, index),
size
);
}
result = new Tree2D(trees);
}
}
else
{
result = tree;
}
return result;
}
public Tree2D setPoint(int x, int y)
{
return setPoint
(
x,
y,
this,
0,
0,
SIZE
);
}
}
public static class Tuple2<Type0, Type1>
{
public final Type0 v0;
public final Type1 v1;
public Tuple2(Type0 v0, Type1 v1)
{
this.v0 = v0;
this.v1 = v1;
}
@Override
public String toString()
{
return "(" + this.v0 + ", " + this.v1 + ")";
}
}
public static class Tuple2Comparable<Type0 extends Comparable<? super Type0>, Type1 extends Comparable<? super Type1>>
extends Tuple2<Type0, Type1>
implements Comparable<Tuple2Comparable<Type0, Type1>>
{
public Tuple2Comparable(Type0 v0, Type1 v1)
{
super(v0, v1);
}
@Override
public int compareTo(Tuple2Comparable<Type0, Type1> that)
{
int result = this.v0.compareTo(that.v0);
if (result == 0)
{
result = this.v1.compareTo(that.v1);
}
return result;
}
}
public static class Tuple3<Type0, Type1, Type2>
{
public final Type0 v0;
public final Type1 v1;
public final Type2 v2;
public Tuple3(Type0 v0, Type1 v1, Type2 v2)
{
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
}
@Override
public String toString()
{
return "(" + this.v0 + ", " + this.v1 + ", " + this.v2 + ")";
}
}
public static class Vertex
<
TypeVertex extends Vertex<TypeVertex, TypeEdge>,
TypeEdge extends Edge<TypeVertex, TypeEdge>
>
implements Comparable<Vertex<? super TypeVertex, ? super TypeEdge>>
{
public static <
TypeVertex extends Vertex<TypeVertex, TypeEdge>,
TypeEdge extends Edge<TypeVertex, TypeEdge>,
TypeResult
> TypeResult breadthFirstSearch
(
TypeVertex vertex,
TypeEdge edge,
BiFunctionResult<TypeVertex, TypeEdge, TypeResult> function,
Array<Boolean> visited,
FIFO<TypeVertex> verticesNext,
FIFO<TypeEdge> edgesNext,
TypeResult result
)
{
if (!visited.get(vertex.index))
{
visited.set(vertex.index, true);
result = function.apply(vertex, edge, result);
for (TypeEdge edgeNext: vertex.edges)
{
TypeVertex vertexNext = edgeNext.other(vertex);
if (!visited.get(vertexNext.index))
{
verticesNext.push(vertexNext);
edgesNext.push(edgeNext);
}
}
}
return result;
}
public static <
TypeVertex extends Vertex<TypeVertex, TypeEdge>,
TypeEdge extends Edge<TypeVertex, TypeEdge>,
TypeResult
>
TypeResult breadthFirstSearch
(
Array<TypeVertex> vertices,
int indexVertexStart,
BiFunctionResult<TypeVertex, TypeEdge, TypeResult> function,
TypeResult result
)
{
Array<Boolean> visited = new Array<>(vertices.size(), false);
FIFO<TypeVertex> verticesNext = new FIFO<>();
verticesNext.push(vertices.get(indexVertexStart));
FIFO<TypeEdge> edgesNext = new FIFO<>();
edgesNext.push(null);
while (!verticesNext.isEmpty())
{
result = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);
}
return result;
}
public static <
TypeVertex extends Vertex<TypeVertex, TypeEdge>,
TypeEdge extends Edge<TypeVertex, TypeEdge>
>
boolean
cycle
(
TypeVertex start,
SortedSet<TypeVertex> result
)
{
boolean cycle = false;
Stack<TypeVertex> stackVertex = new Stack<>();
Stack<TypeEdge> stackEdge = new Stack<>();
stackVertex.push(start);
stackEdge.push(null);
while (!stackVertex.isEmpty())
{
TypeVertex vertex = stackVertex.pop();
TypeEdge edge = stackEdge.pop();
if (!result.contains(vertex))
{
result.add(vertex);
for (TypeEdge otherEdge: vertex.edges)
{
if (otherEdge != edge)
{
TypeVertex otherVertex = otherEdge.other(vertex);
if (result.contains(otherVertex))
{
cycle = true;
}
else
{
stackVertex.push(otherVertex);
stackEdge.push(otherEdge);
}
}
}
}
}
return cycle;
}
public static <
TypeVertex extends Vertex<TypeVertex, TypeEdge>,
TypeEdge extends Edge<TypeVertex, TypeEdge>
>
SortedSet<TypeVertex>
depthFirstSearch
(
TypeVertex start,
BiConsumer<TypeVertex, TypeEdge> functionVisitPre,
BiConsumer<TypeVertex, TypeEdge> functionVisitPost
)
{
SortedSet<TypeVertex> result = new SortedSetAVL<>(Comparator.naturalOrder());
Stack<TypeVertex> stackVertex = new Stack<>();
Stack<TypeEdge> stackEdge = new Stack<>();
stackVertex.push(start);
stackEdge.push(null);
while (!stackVertex.isEmpty())
{
TypeVertex vertex = stackVertex.pop();
TypeEdge edge = stackEdge.pop();
if (result.contains(vertex))
{
functionVisitPost.accept(vertex, edge);
}
else
{
result.add(vertex);
stackVertex.push(vertex);
stackEdge.push(edge);
functionVisitPre.accept(vertex, edge);
for (TypeEdge otherEdge: vertex.edges)
{
TypeVertex otherVertex = otherEdge.other(vertex);
if (!result.contains(otherVertex))
{
stackVertex.push(otherVertex);
stackEdge.push(otherEdge);
}
}
}
}
return result;
}
public static <
TypeVertex extends Vertex<TypeVertex, TypeEdge>,
TypeEdge extends Edge<TypeVertex, TypeEdge>
>
SortedSet<TypeVertex>
depthFirstSearch
(
TypeVertex start,
Consumer<TypeVertex> functionVisitPreVertex,
Consumer<TypeVertex> functionVisitPostVertex
)
{
BiConsumer<TypeVertex, TypeEdge> functionVisitPreVertexEdge = (vertex, edge) ->
{
functionVisitPreVertex.accept(vertex);
};
BiConsumer<TypeVertex, TypeEdge> functionVisitPostVertexEdge = (vertex, edge) ->
{
functionVisitPostVertex.accept(vertex);
};
return depthFirstSearch(start, functionVisitPreVertexEdge, functionVisitPostVertexEdge);
}
public final int index;
public final List<TypeEdge> edges;
public Vertex(int index)
{
this.index = index;
this.edges = new ArrayList<>();
}
@Override
public int compareTo(Vertex<? super TypeVertex, ? super TypeEdge> that)
{
return Integer.compare(this.index, that.index);
}
@Override
public String toString()
{
return "" + this.index;
}
}
public static class VertexDefault<TypeEdge extends Edge<VertexDefault<TypeEdge>, TypeEdge>>
extends Vertex<VertexDefault<TypeEdge>, TypeEdge>
{
public VertexDefault(int index)
{
super(index);
}
}
public static class VertexDefaultDefault
extends Vertex<VertexDefaultDefault, EdgeDefaultDefault>
{
public static Array<VertexDefaultDefault> vertices(int n)
{
Array<VertexDefaultDefault> result = new Array<>(n);
for (int index = 0; index < n; index++)
{
result.set(index, new VertexDefaultDefault(index));
}
return result;
}
public VertexDefaultDefault(int index)
{
super(index);
}
}
public static class Wrapper<Type>
{
public Type value;
public Wrapper(Type value)
{
this.value = value;
}
public Type get()
{
return this.value;
}
public void set(Type value)
{
this.value = value;
}
@Override
public String toString()
{
return this.value.toString();
}
}
public static void add(int delta, int[] result)
{
for (int index = 0; index < result.length; index++)
{
result[index] += delta;
}
}
public static void add(int delta, int[]... result)
{
for (int index = 0; index < result.length; index++)
{
add(delta, result[index]);
}
}
public static long add(long x, long y)
{
return (x + y) % BIG;
}
public static int binarySearchMaximum(Function<Integer, Boolean> filter, int start, int end)
{
return -binarySearchMinimum(x -> filter.apply(-x), -end, -start);
}
public static int binarySearchMinimum(Function<Integer, Boolean> filter, int start, int end)
{
int result;
if (start == end)
{
result = end;
}
else
{
int middle = start + (end - start) / 2;
if (filter.apply(middle))
{
result = binarySearchMinimum(filter, start, middle);
}
else
{
result = binarySearchMinimum(filter, middle + 1, end);
}
}
return result;
}
public static void close()
{
out.close();
}
private static void combinations(int n, int k, int start, SortedSet<Integer> combination, List<SortedSet<Integer>> result)
{
if (k == 0)
{
result.add(new SortedSetAVL<>(combination, Comparator.naturalOrder()));
}
else
{
for (int index = start; index < n; index++)
{
if (!combination.contains(index))
{
combination.add(index);
combinations(n, k - 1, index + 1, combination, result);
combination.remove(index);
}
}
}
}
public static List<SortedSet<Integer>> combinations(int n, int k)
{
List<SortedSet<Integer>> result = new ArrayList<>();
combinations(n, k, 0, new SortedSetAVL<>(Comparator.naturalOrder()), result);
return result;
}
public static <Type> int compare(Iterator<Type> iterator0, Iterator<Type> iterator1, Comparator<Type> comparator)
{
int result = 0;
while (result == 0 && iterator0.hasNext() && iterator1.hasNext())
{
result = comparator.compare(iterator0.next(), iterator1.next());
}
if (result == 0)
{
if (iterator1.hasNext())
{
result = -1;
}
else
{
if (iterator0.hasNext())
{
result = 1;
}
}
}
return result;
}
public static <Type> int compare(Iterable<Type> iterable0, Iterable<Type> iterable1, Comparator<Type> comparator)
{
return compare(iterable0.iterator(), iterable1.iterator(), comparator);
}
public static long divideCeil(long x, long y)
{
return (x + y - 1) / y;
}
public static Set<Long> divisors(long n)
{
SortedSetAVL<Long> result = new SortedSetAVL<>(Comparator.naturalOrder());
result.add(1L);
for (Long factor: factors(n))
{
SortedSetAVL<Long> divisors = new SortedSetAVL<>(result);
for (Long divisor: result)
{
divisors.add(divisor * factor);
}
result = divisors;
}
return result;
}
public static LinkedList<Long> factors(long n)
{
LinkedList<Long> result = new LinkedList<>();
Iterator<Long> primes = ITERATOR_BUFFER_PRIME.iterator();
Long prime;
while (n > 1 && (prime = primes.next()) * prime <= n)
{
while (n % prime == 0)
{
result.add(prime);
n /= prime;
}
}
if (n > 1)
{
result.add(n);
}
return result;
}
public static long faculty(int n)
{
long result = 1;
for (int index = 2; index <= n; index++)
{
result *= index;
}
return result;
}
static long gcd(long a, long b)
{
return b == 0 ? a : gcd(b, a % b);
}
public static long[] generatePOWER2()
{
long[] result = new long[63];
for (int x = 0; x < result.length; x++)
{
result[x] = 1L << x;
}
return result;
}
public static boolean isPrime(long x)
{
boolean result = x > 1;
Iterator<Long> iterator = ITERATOR_BUFFER_PRIME.iterator();
Long prime;
while ((prime = iterator.next()) * prime <= x)
{
result &= x % prime > 0;
}
return result;
}
public static long knapsack(List<Tuple3<Long, Integer, Integer>> itemsValueWeightCount, int weightMaximum)
{
long[] valuesMaximum = new long[weightMaximum + 1];
for (Tuple3<Long, Integer, Integer> itemValueWeightCount: itemsValueWeightCount)
{
long itemValue = itemValueWeightCount.v0;
int itemWeight = itemValueWeightCount.v1;
int itemCount = itemValueWeightCount.v2;
for (int weight = weightMaximum; 0 <= weight; weight--)
{
for (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)
{
valuesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);
}
}
}
long result = 0;
for (long valueMaximum: valuesMaximum)
{
result = Math.max(result, valueMaximum);
}
return result;
}
public static boolean knapsackPossible(List<Tuple2<Integer, Integer>> itemsWeightCount, int weightMaximum)
{
boolean[] weightPossible = new boolean[weightMaximum + 1];
weightPossible[0] = true;
int weightLargest = 0;
for (Tuple2<Integer, Integer> itemWeightCount: itemsWeightCount)
{
int itemWeight = itemWeightCount.v0;
int itemCount = itemWeightCount.v1;
for (int weightStart = 0; weightStart < itemWeight; weightStart++)
{
int count = 0;
for (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)
{
if (weightPossible[weight])
{
count = itemCount;
}
else
{
if (0 < count)
{
weightPossible[weight] = true;
weightLargest = weight;
count -= 1;
}
}
}
}
}
return weightPossible[weightMaximum];
}
public static long lcm(int a, int b)
{
return a * b / gcd(a, b);
}
public static void main(String[] args)
{
try
{
solve();
}
catch (IOException exception)
{
exception.printStackTrace();
}
close();
}
public static long mul(long x, long y)
{
return (x * y) % BIG;
}
public static double nextDouble()
throws IOException
{
return Double.parseDouble(nextString());
}
public static int nextInt()
throws IOException
{
return Integer.parseInt(nextString());
}
public static void nextInts(int n, int[]... result)
throws IOException
{
for (int index = 0; index < n; index++)
{
for (int value = 0; value < result.length; value++)
{
result[value][index] = nextInt();
}
}
}
public static int[] nextInts(int n)
throws IOException
{
int[] result = new int[n];
nextInts(n, result);
return result;
}
public static String nextLine()
throws IOException
{
return bufferedReader.readLine();
}
public static long nextLong()
throws IOException
{
return Long.parseLong(nextString());
}
public static void nextLongs(int n, long[]... result)
throws IOException
{
for (int index = 0; index < n; index++)
{
for (int value = 0; value < result.length; value++)
{
result[value][index] = nextLong();
}
}
}
public static long[] nextLongs(int n)
throws IOException
{
long[] result = new long[n];
nextLongs(n, result);
return result;
}
public static String nextString()
throws IOException
{
while ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))
{
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
}
return stringTokenizer.nextToken();
}
public static String[] nextStrings(int n)
throws IOException
{
String[] result = new String[n];
{
for (int index = 0; index < n; index++)
{
result[index] = nextString();
}
}
return result;
}
public static <T> List<T> permutation(long p, List<T> x)
{
List<T> copy = new ArrayList<>();
for (int index = 0; index < x.size(); index++)
{
copy.add(x.get(index));
}
List<T> result = new ArrayList<>();
for (int indexTo = 0; indexTo < x.size(); indexTo++)
{
int indexFrom = (int) p % copy.size();
p = p / copy.size();
result.add(copy.remove(indexFrom));
}
return result;
}
public static <Type> List<List<Type>> permutations(List<Type> list)
{
List<List<Type>> result = new ArrayList<>();
result.add(new ArrayList<>());
for (Type element: list)
{
List<List<Type>> permutations = result;
result = new ArrayList<>();
for (List<Type> permutation: permutations)
{
for (int index = 0; index <= permutation.size(); index++)
{
List<Type> permutationNew = new ArrayList<>(permutation);
permutationNew.add(index, element);
result.add(permutationNew);
}
}
}
return result;
}
public static long[][] sizeGroup2CombinationsCount(int maximum)
{
long[][] result = new long[maximum + 1][maximum + 1];
for (int length = 0; length <= maximum; length++)
{
result[length][0] = 1;
for (int group = 1; group <= length; group++)
{
result[length][group] = add(result[length - 1][group - 1], result[length - 1][group]);
}
}
return result;
}
public static Stream<BigInteger> streamFibonacci()
{
return Stream.generate(new Supplier<BigInteger>()
{
private BigInteger n0 = BigInteger.ZERO;
private BigInteger n1 = BigInteger.ONE;
@Override
public BigInteger get()
{
BigInteger result = n0;
n0 = n1;
n1 = result.add(n0);
return result;
}
});
}
public static Stream<Long> streamPrime(int sieveSize)
{
return Stream.generate(new Supplier<Long>()
{
private boolean[] isPrime = new boolean[sieveSize];
private long sieveOffset = 2;
private List<Long> primes = new ArrayList<>();
private int index = 0;
public void filter(long prime, boolean[] result)
{
if (prime * prime < this.sieveOffset + sieveSize)
{
long remainingStart = this.sieveOffset % prime;
long start = remainingStart == 0 ? 0 : prime - remainingStart;
for (long index = start; index < sieveSize; index += prime)
{
result[(int) index] = false;
}
}
}
public void generatePrimes()
{
Arrays.fill(this.isPrime, true);
this.primes.forEach(prime -> filter(prime, isPrime));
for (int index = 0; index < sieveSize; index++)
{
if (isPrime[index])
{
this.primes.add(this.sieveOffset + index);
filter(this.sieveOffset + index, isPrime);
}
}
this.sieveOffset += sieveSize;
}
@Override
public Long get()
{
while (this.primes.size() <= this.index)
{
generatePrimes();
}
Long result = this.primes.get(this.index);
this.index += 1;
return result;
}
});
}
public static <Type> String toString(Iterator<Type> iterator, String separator)
{
StringBuilder stringBuilder = new StringBuilder();
if (iterator.hasNext())
{
stringBuilder.append(iterator.next());
}
while (iterator.hasNext())
{
stringBuilder.append(separator);
stringBuilder.append(iterator.next());
}
return stringBuilder.toString();
}
public static <Type> String toString(Iterator<Type> iterator)
{
return toString(iterator, " ");
}
public static <Type> String toString(Iterable<Type> iterable, String separator)
{
return toString(iterable.iterator(), separator);
}
public static <Type> String toString(Iterable<Type> iterable)
{
return toString(iterable, " ");
}
public static long totient(long n)
{
Set<Long> factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());
long result = n;
for (long p: factors)
{
result -= result / p;
}
return result;
}
interface BiFunctionResult<Type0, Type1, TypeResult>
{
TypeResult apply(Type0 x0, Type1 x1, TypeResult x2);
}
public static int[] solve(int n, int a, int b)
{
int[] result;
if (a + b <= n - 2 && Math.abs(a - b) <= 1)
{
result = new int[n];
int monotoneUntil = n - 1 - a - b;
for (int i = 0; i < monotoneUntil; i++)
{
result[i] = i;
}
boolean max = true;
int low = monotoneUntil;
int high = n - 1;
for (int i = monotoneUntil; i < n; i++)
{
if (max)
{
result[i] = high;
high -= 1;
}
else
{
result[i] = low;
low += 1;
}
max = !max;
}
if (a < b)
{
for (int i = 0; i < n; i++)
{
result[i] = n - 1 - result[i];
}
}
}
else
{
result = null;
}
return result;
}
public static void solve()
throws IOException
{
int t = nextInt();
for (int test = 0; test < t; test++)
{
int n = nextInt();
int a = nextInt();
int b = nextInt();
int[] s = solve(n, a, b);
if (s == null)
{
out.println(-1);
}
else
{
for (int i = 0; i < n; i++)
{
out.print(s[i] + 1 + " ");
}
out.println();
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f7b38bb1a3893002427bfd62bbc48fc0 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class MyCpClass{
public static void main(String []args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine().trim());
while(T-- > 0){
String []str = br.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int a = Integer.parseInt(str[1]);
int b = Integer.parseInt(str[2]);
int []res = new int[n];
if(n % 2 == 0 && Math.max(a, b) > (n+1)/2-1){
sb.append("-1\n");
continue;
}
if(n % 2 != 0 && Math.max(a, b) > (n+1)/2-1){
sb.append("-1\n");
continue;
}
if(n % 2 != 0 && a == (n+1)/2-1 && b == (n+1)/2-1){
sb.append("-1\n");
continue;
}
if(Math.abs(a-b) > 1){
sb.append("-1\n");
continue;
}
if(a > b){
int x = 1;
for(int i=0; i<2*a; i+=2)
res[i] = x++;
for(int i=n-1; i>=2*a; i--)
res[i] = x++;
for(int i=1; i<2*a; i+=2)
res[i] = x++;
}
else if(a < b){
int x = 1;
for(int i=1; i<2*b; i+=2)
res[i] = x++;
for(int i=2*b; i<n; i++)
res[i] = x++;
for(int i=0; i<2*b; i+=2)
res[i] = x++;
}
else{
int x = 1;
for(int i=0; i<=2*a; i+=2)
res[i] = x++;
for(int i=1; i<=2*a; i+=2)
res[i] = x++;
for(int i=2*a+1; i<n; i++)
res[i] = x++;
}
for(int i=0; i<n; i++)
sb.append(res[i] + " ");
sb.append("\n");
}
System.out.println(sb);
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 211f0dea0696be18f7bb451cf9bc940c | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | //package Div2.B;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BuildThePermutation {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0){
String []nab=br.readLine().split(" ");
int n=Integer.parseInt(nab[0]);
int a=Integer.parseInt(nab[1]);
int b=Integer.parseInt(nab[2]);
if(a+b>n-2 || abs(a-b)>1)
System.out.println(-1);
else{
StringBuilder ans=new StringBuilder();
int min=1;
int max=n;
if(a>=b){
ans.append(min).append(" ");
min++;
for(int i=1;i<=a+b;i++){
if(i%2!=0) {
ans.append(max).append(" ");
max--;
}else{
ans.append(min).append(" ");
min++;
}
}
}else{
ans.append(max).append(" ");
max--;
for(int i=1;i<=a+b;i++){
if(i%2!=0) {
ans.append(min).append(" ");
min++;
}
else {
ans.append(max).append(" ");
max--;
}
}
}
if(a>b){
while(max>=min){
ans.append(max).append(" ");
max--;
}
}else{
while(min<=max){
ans.append(min).append(" ");
min++;
}
}
System.out.println(ans);
}
t--;
}
}
private static int abs(int x){
return x<0?-x:x;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f155ddb50a258d6fb09ba4fad681df0b | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws
IOException {
int t = nextInt();
while (t-- != 0) {
int n = nextInt();
int a = nextInt();
int b = nextInt();
int[] ans = new int[n];
if (Math.abs(a - b) >= 2 || a + b > n - 2) out.println(-1);
else {
int x = n;
int y = 1;
if (a > b) {
for (int i = 0; i < Math.min(a * 2, n); i++) {
if (i % 2 == 1) {
ans[i] = x;
x--;
} else {
ans[i] = y;
y++;
}
}
for (int i = a * 2; i < n; i++) {
ans[i] = x;
x--;
}
} else if (a < b) {
for (int i = 0; i < Math.min(b * 2, n); i++) {
if (i % 2 == 1) {
ans[i] = y;
y++;
} else {
ans[i] = x;
x--;
}
}
for (int i = b * 2; i < n; i++) {
ans[i] = y;
y++;
}
} else {
for (int i = 0; i < Math.min(b * 2 + 1, n); i++) {
if (i % 2 == 0) {
ans[i] = y;
y++;
} else {
ans[i] = x;
x--;
}
}
for (int i = a * 2 + 1; i < n; i++) {
ans[i] = y;
y++;
}
}
int cnt1 = 0;
int cnt2 = 0;
for (int i = 1; i < n-1; i++) {
if(ans[i-1]<ans[i]&&ans[i]>ans[i+1])cnt1++;
else if(ans[i-1]>ans[i]&&ans[i]<ans[i+1])cnt2++;
}
if(cnt1==a&&cnt2==b){
for (int i = 0; i < n; i++) {
out.print(ans[i]+" ");
}
out.println();
}
else out.println(-1);
}
}
out.close();
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer in = new StringTokenizer("");
public static boolean hasNext() throws IOException {
if (in.hasMoreTokens()) return true;
String s;
while ((s = br.readLine()) != null) {
in = new StringTokenizer(s);
if (in.hasMoreTokens()) return true;
}
return false;
}
public static String nextToken() throws IOException {
while (!in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 72167586cfae038d31e9058ae4b2d64c | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
static FastReader in;
static PrintWriter out;
static int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
static void p(Object o) {
out.print(o);
}
static void pn(Object o) {
out.println(o);
}
static void pni(Object o) {
out.println(o);
out.flush();
}
static String n() throws Exception {
return in.next();
}
static String nln() throws Exception {
return in.nextLine();
}
static int ni() throws Exception {
return Integer.parseInt(in.next());
}
static long nl() throws Exception {
return Long.parseLong(in.next());
}
static double nd() throws Exception {
return Double.parseDouble(in.next());
}
static class FastReader {
static BufferedReader br;
static StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
static long power(long a, long b) {
if (b == 0)
return 1;
long val = power(a, b / 2);
val = val * val;
if ((b % 2) != 0)
val = val * a;
return val;
}
static long power(long a, long b, long mod) {
if (b == 0)
return 1L;
long val = power(a, b / 2) % mod;
val = (val * val) % mod;
if ((b % 2) != 0)
val = (val * a) % mod;
return val % mod;
}
static ArrayList<Long> prime_factors(long n) {
ArrayList<Long> ans = new ArrayList<Long>();
while (n % 2 == 0) {
ans.add(2L);
n /= 2L;
}
for (long i = 3; i <= Math.sqrt(n); i++) {
while (n % i == 0) {
ans.add(i);
n /= i;
}
}
if (n > 2) {
ans.add(n);
}
return ans;
}
static void sort(ArrayList<Long> a) {
Collections.sort(a);
}
static void reverse_sort(ArrayList<Long> a) {
Collections.sort(a, Collections.reverseOrder());
}
static void swap(long[] a, int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static void swap(List<Long> a, int i, int j) {
long temp = a.get(i);
a.set(j, a.get(i));
a.set(j, temp);
}
static void sieve(boolean[] prime) {
int n = prime.length - 1;
Arrays.fill(prime, true);
for (int i = 2; i * i <= n; i++) {
if (prime[i]) {
for (int j = 2 * i; j <= n; j += i) {
prime[j] = false;
}
}
}
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long mod = 1000000007;
public static void sort(long[] arr, int l, int r) {
if (l >= r)
return;
int mid = (l + r) / 2;
sort(arr, l, mid);
sort(arr, mid + 1, r);
merge(arr, l, mid, r);
}
public static void sort(int[] arr, int l, int r) {
if (l >= r)
return;
int mid = (l + r) / 2;
sort(arr, l, mid);
sort(arr, mid + 1, r);
merge(arr, l, mid, r);
}
static void merge(int[] arr, int l, int mid, int r) {
int[] left = new int[mid - l + 1];
int[] right = new int[r - mid];
for (int i = l; i <= mid; i++) {
left[i - l] = arr[i];
}
for (int i = mid + 1; i <= r; i++) {
right[i - (mid + 1)] = arr[i];
}
int left_start = 0;
int right_start = 0;
int left_length = mid - l + 1;
int right_length = r - mid;
int temp = l;
while (left_start < left_length && right_start < right_length) {
if (left[left_start] < right[right_start]) {
arr[temp] = left[left_start++];
} else {
arr[temp] = right[right_start++];
}
temp++;
}
while (left_start < left_length) {
arr[temp++] = left[left_start++];
}
while (right_start < right_length) {
arr[temp++] = right[right_start++];
}
}
static void merge(long[] arr, int l, int mid, int r) {
long[] left = new long[mid - l + 1];
long[] right = new long[r - mid];
for (int i = l; i <= mid; i++) {
left[i - l] = arr[i];
}
for (int i = mid + 1; i <= r; i++) {
right[i - (mid + 1)] = arr[i];
}
int left_start = 0;
int right_start = 0;
int left_length = mid - l + 1;
int right_length = r - mid;
int temp = l;
while (left_start < left_length && right_start < right_length) {
if (left[left_start] < right[right_start]) {
arr[temp] = left[left_start++];
} else {
arr[temp] = right[right_start++];
}
temp++;
}
while (left_start < left_length) {
arr[temp++] = left[left_start++];
}
while (right_start < right_length) {
arr[temp++] = right[right_start++];
}
}
static class pair implements Comparable<pair> {
int a, b, c;
public pair(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int compareTo(pair p) {
return this.a - p.a;
}
}
static int count = 1;
static int[] p = new int[100002];
static long[] flat_tree = new long[300002];
static int[] in_time = new int[1000002];
static int[] out_time = new int[1000002];
static long[] subtree_gcd = new long[100002];
static int w = 0;
static boolean poss = true;
public static void main(String[] args) throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int t = ni();
while (t-- > 0) {
int n=ni();
int a=ni();
int b=ni();
int[] ans=new int[n];
for(int i=0;i<n;i++){
ans[i]=i+1;
}
if(n==2){
if(a==0 && b==0){
pn("1 2");
continue;
}else pn("-1");
continue;
}
if(Math.abs(a-b)>1){
pn("-1");
continue;
}
if(a>b){
if(1+(n-3)/2<a){
pn("-1");
continue;
}
int count=0;
int k=n-2;
while(count<a){
swap(ans,k,k+1);
k-=2;
count++;
}
print(ans);
}else if(b>a){
if(1+(n-3)/2<b){
pn("-1");
continue;
}
int count=0;
int k=0;
while(count<b){
swap(ans,k,k+1);
k+=2;
count++;
}
print(ans);
}else{
if(n==3 && a!=0 && b!=0){
pn("-1");
continue;
}
if(a>(1+(n-4)/2)){
pn("-1");
continue;
}
int count=0;
int k=n-3;
while(count<a){
swap(ans,k,k+1);
k-=2;
count++;
}
print(ans);
}
}
out.flush();
out.close();
}
static void print(int[] a){
for(int i=0;i<a.length;i++)p(a[i]+" ");
pn("");
}
static long count(long n) {
long count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
static void swap(long a, long b) {
long temp = a;
a = b;
b = temp;
}
static void swap(int[] a, int i,int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static int LcsOfPrefix(String a, String b) {
int i = 0;
int j = 0;
int count = 0;
while (i < a.length() && j < b.length()) {
if (a.charAt(i) == b.charAt(j)) {
j++;
count++;
}
i++;
}
return a.length() + b.length() - 2 * count;
}
static void reverse(int[] a, int n) {
for (int i = 0; i < n / 2; i++) {
int temp = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = temp;
}
}
static char get_char(int a) {
return (char) (a + 'a');
}
static void dfs(int i, List<List<Integer>> arr, boolean[] visited, int parent) {
visited[i] = true;
for (int v : arr.get(i)) {
if (!visited[v]) {
dfs(v, arr, visited, i);
}
}
}
static int find1(List<Integer> a, int val) {
int ans = -1;
int l = 0;
int r = a.size() - 1;
while (l <= r) {
int mid = l + (r - l) / 2;
if (a.get(mid) >= val) {
r = mid - 1;
ans = mid;
} else
l = mid + 1;
}
return ans;
}
static int find2(List<Integer> a, int val) {
int l = 0;
int r = a.size() - 1;
int ans = -1;
while (l <= r) {
int mid = l + (r - l) / 2;
if (a.get(mid) <= val) {
ans = mid;
l = mid + 1;
} else
r = mid - 1;
}
return ans;
}
static void dfs(List<List<Integer>> arr, int node, int parent, long[] val) {
p[node] = parent;
in_time[node] = count;
flat_tree[count] = val[node];
subtree_gcd[node] = val[node];
count++;
for (int adj : arr.get(node)) {
if (adj == parent)
continue;
dfs(arr, adj, node, val);
subtree_gcd[node] = gcd(subtree_gcd[adj], subtree_gcd[node]);
}
out_time[node] = count;
flat_tree[count] = val[node];
count++;
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 648e0a95603c7d0d53396ead97ea62f1 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class a729 {
public static void main(String[] args) throws IOException {
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(System.out));
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
PrintWriter pt = new PrintWriter(System.out);
FastReader sc = new FastReader();
int t = sc.nextInt();
for(int o = 0 ; o<t;o++) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int val = 0;
if(Math.abs(a-b)>1) {
System.out.println(-1);
continue;
}
if(a==b) {
val = a + b + 2;
}else if(a>b) {
val = (2*b + 3);
}else {
val = (2*a + 3);
}
if(val>n) {
System.out.println(-1);
continue;
}
if(a == b) {
int x = n;
int y = 1;
int v = a + b + 1;
for(int i = 0 ; i<a + b + 1;i++) {
if(i%2 == 0) {
System.out.print(x + " ");
x--;
}else {
System.out.print(y + " ");
y++;
}
}
for(int i = 0 ; i<n-v;i++) {
System.out.print(x + " ");
x--;
}
}else if(a>b) {
int x = n;
int y = 1;
int v = 2*b + 2;
for(int i = 0 ; i<v;i++) {
if(i%2 == 0) {
System.out.print(y + " ");
y++;
}else {
System.out.print(x + " ");
x--;
}
}
for(int i = 0 ; i<n-v;i++) {
System.out.print(x + " ");
x--;
}
}else {
int x = n;
int y = 1;
int v = 2*a + 2;
for(int i = 0 ; i<v;i++) {
if(i%2 == 0) {
System.out.print(x + " ");
x--;
}else {
System.out.print(y + " ");
y++;
}
}
for(int i = 0 ; i<n-v;i++) {
System.out.print(y + " ");
y++;
}
}
// if(a==b) {
// int v = a + b + 2;
// int lo = 1;
// int hi = Integer.MAX_VALUE;
// for(int i = 0 ; i<v; i++){
// if(i%2==0) {
// System.out.print(lo + " ");
// lo++;
// }else{
// System.out.print(hi + " ");
// hi--;
// }
// }
// for(int i = 0 ; i<n-v;i++) {
// System.out.print(hi + " ");
// hi--;
// }
// }else if(a>b) {
// int lo =
// int x = 2*b + 3;
// int y = 3*(a-b-1);
//
//
// for(int i = 0 ; i<x;i++) {
// if(i%2==0) {
// System.out.print(1 + " ");
// }else {
// System.out.print(2 + " ");
// }
// }
// for(int i = 0 ; i<y;i++) {
// if(i%3==0) {
// System.out.print(1 + " ");
// }else if(i%3==1) {
// System.out.print(2 + " ");
// }else {
// System.out.print(1 + " ");
// }
// }
// for(int i = 0 ; i<n-x-y;i++) {
// System.out.print(1 + " ");
// }
//
// }else {
// int x = 2*a + 3;
// int y = 3*(b-a-1);
//
//
// for(int i = 0 ; i<x;i++) {
// if(i%2==0) {
// System.out.print(2 + " ");
// }else {
// System.out.print(1 + " ");
// }
// }
// for(int i = 0 ; i<y;i++) {
// if(i%3==0) {
// System.out.print(2 + " ");
// }else if(i%3==1) {
// System.out.print(1 + " ");
// }else {
// System.out.print(2 + " ");
// }
// }
// for(int i = 0 ; i<n-x-y;i++) {
// System.out.print(2 + " ");
// }
//
// }
// }
// System.out.println();
}
// String s = sc.next();
// char[] arr = new char[s.length()];
// for(int i = 0 ; i<s.length();i++) {
// arr[i] = s.charAt(i);
// }
// int n = s.length();
// int[] seg = new int[n+1];
// HashSet<Character> set = new HashSet<Character>();
// build(seg, arr, 0, 0, n-1, set);
// int m = sc.nextInt();
//
// for(int o = 0 ; o<m;o++) {
// int x = sc.nextInt();
// if(x == 1) {
// int id = sc.nextInt();
// char ch = sc.next().charAt(0);
//// arr[id] = ch;
// update(seg, 0, 0, n-1, id, ch, set, arr);
// continue;
// }
// int l = sc.nextInt();
// int r = sc.nextInt();
// System.out.println(query(seg, 0, 0, n-1, l, r));
//
// }
//
}
//------------------------------------------------------------------------------------------------------------------------------------------------
public static void build(int [] seg,char []arr,int idx, int lo , int hi,HashSet<Character>set) {
if(lo == hi) {
// seg[idx] = arr[lo];
if(set.contains(arr[lo])) {
seg[idx] = 0;
}else {
seg[idx] =1 ;
set.add(arr[lo]);
}
return;
}
int mid = (lo + hi)/2;
build(seg,arr,2*idx+1, lo, mid,set);
build(seg,arr,idx*2+2, mid +1, hi,set);
// seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]);
seg[idx] = seg[2*idx+1] + seg[2*idx+2];
}
//for finding minimum in range
public static int query(int[]seg,int idx , int lo , int hi , int l , int r) {
if(lo>=l && hi<=r) {
return seg[idx];
}
if(hi<l || lo>r) {
// return Integer.MAX_VALUE;
return 0;
}
int mid = (lo + hi)/2;
int left = query(seg,idx*2 +1, lo, mid, l, r);
int right = query(seg,idx*2 + 2, mid + 1, hi, l, r);
// return Math.min(left, right);
return left + right;
}
// for sum
public static void update(int[]seg,int idx, int lo , int hi , int node , char val,HashSet<Character>set,char[] arr) {
if(lo == hi) {
// seg[idx] += val;
set.remove(arr[node]);
arr[node] = val;
if(set.contains(val)) {
seg[idx] = 0;
}else {
seg[idx] = 1;
set.add(val);
}
}else {
int mid = (lo + hi )/2;
if(node<=mid && node>=lo) {
update(seg, idx * 2 +1, lo, mid, node, val,set,arr);
}else {
update(seg, idx*2 + 2, mid + 1, hi, node, val,set,arr);
}
seg[idx] = seg[idx*2 + 1] + seg[idx*2 + 2];
}
}
public static int lower_bound(int array[], int low, int high, int key){
// Base Case
if (low > high) {
return low;
}
// Find the middle index
int mid = low + (high - low) / 2;
// If key is lesser than or equal to
// array[mid] , then search
// in left subarray
if (key <= array[mid]) {
return lower_bound(array, low,
mid - 1, key);
}
// If key is greater than array[mid],
// then find in right subarray
return lower_bound(array, mid + 1, high,
key);
}
public static int upper_bound(int arr[], int low,
int high, int key){
// Base Case
if (low > high || low == arr.length)
return low;
// Find the value of middle index
int mid = low + (high - low) / 2;
// If key is greater than or equal
// to array[mid], then find in
// right subarray
if (key >= arr[mid]) {
return upper_bound(arr, mid + 1, high,
key);
}
// If key is less than array[mid],
// then find in left subarray
return upper_bound(arr, low, mid - 1,
key);
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
public static int gcd(int a, int b){
if (a == 0)
return b;
return gcd(b % a, a);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
public static long modInverse(long a, long m){
long m0 = m;
long y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
long q = a / m;
long t = m;
// m is remainder now, process
// same as Euclid's algo
m = a % m;
a = t;
t = y;
// Update x and y
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
//-----------------------------------------------------------------------------------------------------------------------------------
//segment tree
//for finding minimum in range
// public static void build(int [] seg,int []arr,int idx, int lo , int hi) {
// if(lo == hi) {
// seg[idx] = arr[lo];
// return;
// }
// int mid = (lo + hi)/2;
// build(seg,arr,2*idx+1, lo, mid);
// build(seg,arr,idx*2+2, mid +1, hi);
// seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]);
// }
////for finding minimum in range
//public static int query(int[]seg,int idx , int lo , int hi , int l , int r) {
// if(lo>=l && hi<=r) {
// return seg[idx];
// }
// if(hi<l || lo>r) {
// return Integer.MAX_VALUE;
// }
// int mid = (lo + hi)/2;
// int left = query(seg,idx*2 +1, lo, mid, l, r);
// int right = query(seg,idx*2 + 2, mid + 1, hi, l, r);
// return Math.min(left, right);
//}
// // for sum
//
//public static void update(int[]seg,int idx, int lo , int hi , int node , int val) {
// if(lo == hi) {
// seg[idx] += val;
// }else {
//int mid = (lo + hi )/2;
//if(node<=mid && node>=lo) {
// update(seg, idx * 2 +1, lo, mid, node, val);
//}else {
// update(seg, idx*2 + 2, mid + 1, hi, node, val);
//}
//seg[idx] = seg[idx*2 + 1] + seg[idx*2 + 2];
//
//}
//}
//---------------------------------------------------------------------------------------------------------------------------------------
static void shuffleArray(int[] ar)
{
// If running on Java 6 or older, use `new Random()` on RHS here
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------
class SegmentTree{
int n;
public SegmentTree(int[] arr,int n) {
this.arr = arr;
this.n = n;
}
int[] arr = new int[n];
// int n = arr.length;
int[] seg = new int[4*n];
void build(int idx, int lo , int hi) {
if(lo == hi) {
seg[idx] = arr[lo];
return;
}
int mid = (lo + hi)/2;
build(2*idx+1, lo, mid);
build(idx*2+2, mid +1, hi);
seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]);
}
int query(int idx , int lo , int hi , int l , int r) {
if(lo<=l && hi>=r) {
return seg[idx];
}
if(hi<l || lo>r) {
return Integer.MAX_VALUE;
}
int mid = (lo + hi)/2;
int left = query(idx*2 +1, lo, mid, l, r);
int right = query(idx*2 + 2, mid + 1, hi, l, r);
return Math.min(left, right);
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
class coup{
int a , b;
public coup(int a , int b) {
this.a = a;
this.b = b;
}
}
class trip{
int a , b, c;
public trip(int a , int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 38367b1e0e0f0d368591a167c951e780 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String args[]){
FScanner in = new FScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int n =in.nextInt();
int a=in.nextInt();
int b=in.nextInt();
if(a+b>(n-2)||(Math.abs(a-b)>1))
out.print(-1);
else if(a!=0||b!=0)
{
if(a>b)
{
int f=1;
int s=n;
int c=0,f2=0;
for(int i=1;i<=n;i++)
{
if(i%2==0)
{
out.print(s+" ");
s--;
c++;
}
else
{
out.print(f+" ");
f++;
}
if(c==a)
{
f2=1;
break;
}
}
if(f2==1)
{
for(int i=s;i>=f;i--)
out.print(i+" ");
}
}
else if(b>a)
{
int f=1;
int s=n;
int c1=0,f1=0;
for(int i=1;i<=n;i++)
{
if(i%2==0)
{
out.print(f+" ");
f++;
}
else
{
out.print(s+" ");
s--;
c1++;
}
if(c1==b)
{
f1=1;
break;
}
}
if(f1==1)
{
for(int i=f;i<=s;i++)
out.print(i+" ");
}
}
else
{
int f=1;
int s=n;
int c=0,c1=0,f1=0;
for(int i=1;i<n;i++)
{
if(i%2==0)
{
out.print(f+" ");
f++;
c++;
}
else
{
out.print(s+" ");
s--;
c1++;
}
if(c==a&&c1==b)
{
f1=1;
break;
}
}
if(f1==1)
{
for(int i=s;i>=f;i--)
out.print(i+" ");
}
}
}
else
{
for(int i=1;i<=n;i++)
out.print(i+" ");
}
out.println();
}
out.close();
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean checkprime(int n1)
{
if(n1%2==0||n1%3==0)
return false;
else
{
for(int i=5;i*i<=n1;i+=6)
{
if(n1%i==0||n1%(i+2)==0)
return false;
}
return true;
}
}
static class FScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer sb = new StringTokenizer("");
String next(){
while(!sb.hasMoreTokens()){
try{
sb = new StringTokenizer(br.readLine());
} catch(IOException e){ }
}
return sb.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
float nextFloat(){
return Float.parseFloat(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | e23aafe88a849f0ec91bab908cd80c51 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static FastScanner sc = new FastScanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder();
static long mod = (long) 1e9 + 7;
public static void main(String[] args) throws Exception {
int n = sc.nextInt();
for(int i = 0; i < n; i++) solve();
pw.flush();
}
public static void solve() {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int[] ans = new int[n];
for(int i = 1; i <= n; i++){
ans[i-1] = i;
}
if(a == 0 && b == 0){
//何もしない
}else if(a <= b){
int rem = b;
for(int i = 0; i < n-1; i+=2){
if(rem == 0){
break;
}
int tmp = ans[i+1];
ans[i+1] = ans[i];
ans[i] = tmp;
rem--;
}
if(a == b){
int tmp = ans[n-2];
ans[n-2] = ans[n-1];
ans[n-1] = tmp;
}
}else{
int rem = a;
for(int i = n-1; i > 1; i-=2){
if(rem == 0){
break;
}
int tmp = ans[i-1];
ans[i-1] = ans[i];
ans[i] = tmp;
rem--;
}
}
sb.append(ans[0]).append(" ");
for(int i = 1; i < n-1; i++){
if(ans[i-1] < ans[i] && ans[i] > ans[i+1]){
a--;
}else if(ans[i-1] > ans[i] && ans[i] < ans[i+1]){
b--;
}
sb.append(ans[i]).append(" ");
}
sb.append(ans[n-1]);
if(a == 0 && b == 0){
pw.println(sb.toString());
}else{
pw.println(-1);
}
//pw.println(a + " " + b);
sb.setLength(0);
}
static class GeekInteger {
public static void save_sort(int[] array) {
shuffle(array);
Arrays.sort(array);
}
public static int[] shuffle(int[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
int randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
public static void save_sort(long[] array) {
shuffle(array);
Arrays.sort(array);
}
public static long[] shuffle(long[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
long randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
}
}
class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public FastScanner(FileReader in) {
reader = new BufferedReader(in);
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String[] nextArray(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++)
a[i] = next();
return a;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | ba39fb8ab987c0a41f57cc7fcefe3a2e | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
/**
* Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
public static class Task {
private boolean[] notPrime;
private void init() {
notPrime = new boolean[1000002];
for(int i=2;i<=1000001;i++) {
for(int j=2;j*i<=1000001;j++) {
notPrime[i*j] = true;
}
}
}
private boolean isPrime(Integer num) {
return !notPrime[num];
}
public void solve(int cnt, InputReader in, PrintWriter out) {
cnt = in.nextInt();
for (int c = 0; c < cnt; c++) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
if(Math.abs(a-b)>1 || (a+b+2)>n) {
out.println(-1);
} else {
if(b>a) {
for(int i=n-a-1;i>=b+1;i--) {
out.print(i+" ");
}
int ta = a, tb=b;
while (ta>0 || tb>0) {
if(tb>0) {
out.print((b-tb+1)+" ");
tb--;
}
if(ta>0) {
out.print((n-(a-ta))+" ");
ta--;
}
}
out.print(n-a);
} else {
for(int i=b+1;i<=n-a-1;i++) {
out.print(i+" ");
}
int ta = a, tb=b;
while (ta>0 || tb>0) {
if(ta>0) {
out.print((n-(a-ta))+" ");
ta--;
}
if(tb>0) {
out.print((b-tb+1)+" ");
tb--;
}
}
out.print(n-a);
}
out.println();
}
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 228069aeb11ea0bba5d4e2fa16adb30a | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class code{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static int GCD(int a, int b)
{
if (b == 0)
return a;
return GCD(b, a % b);
}
public static ArrayList<ArrayList<Integer>> al;
//@SuppressWarnings("unchecked")
public static void main(String[] arg) throws IOException{
//Reader in=new Reader();
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner(System.in);
int t=in.nextInt();
while(t-- > 0){
int n=in.nextInt();
int a=in.nextInt();
int b=in.nextInt();
if(Math.abs(a-b)>1 || a>((n-1)/2) || b>((n-1)/2) || n-(a+b)<=1){
out.println(-1);
continue;
}
int[] arr=new int[n];
int res=1;
int l1=a,l2=b;
if(a==b){
for(int i=0;i<n && a>=0;i+=2){
arr[i]=res;
res++;
a--;
}
for(int i=1;i<n && b>0;i+=2){
arr[i]=res;
res++;
b--;
}
for(int i=0;i<n;i++){
if(arr[i]==0) arr[i]=i+1;
}
}
else if(a>b){
//a=b;
for(int i=0;i<n && l1>0;i+=2){
arr[i]=res;
res++;
l1--;
}
for(int i=1;i<n && l2>0;i+=2){
arr[i]=res++;
l2--;
}
res=n;
arr[a+b]=res--;
for(int i=a+b+1;i<n;i++){
arr[i]=res--;
}
}
else{
//b=a;
res=n;
//out.println(a+" "+b+" "+res);
for(int i=0;i<n && l2>0;i+=2){
arr[i]=res--;
l2--;
//out.println(i+" "+arr[i]);
}
for(int i=1;i<n && l1>0;i+=2){
arr[i]=res--;
l1--;
//out.println(i+" "+arr[i]);
}
res=1;
arr[a+b]=res++;
for(int i=a+b+1;i<n;i++){
arr[i]=res++;
//out.println(i+" "+arr[i]);
}
}
for(int i=0;i<n;i++){
out.print(arr[i]+" ");
}
out.println();
}
out.flush();
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 86259fdbb3d8e66dc8acd696f379a2e6 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.regex.MatchResult;
public class B {
public static boolean checker(ArrayList<Integer> a, int max, int min) {
for (int i = 1; i < a.size() - 1; i++) {
if (a.get(i) > a.get(i + 1) && a.get(i) > a.get(i - 1)) {
max--;
}
if (a.get(i) < a.get(i + 1) && a.get(i) < a.get(i - 1)) {
min--;
}
}
return max == 0 && min == 0;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int max = sc.nextInt();
int min = sc.nextInt();
if (max == min) {
LinkedList<Integer> big = new LinkedList<>();
LinkedList<Integer> small = new LinkedList<>();
for (int i = 1; i <= min + 1; i++) {
small.add(i);
}
for (int i = min + 2; i <= n; i++) {
big.add(i);
}
LinkedList<Integer> ans = new LinkedList<>();
// System.out.println(small+" "+big);
if (max + min + 2 <= n) {
for (int i = 0; i < max + min + 2; i++) {
if (i % 2 == 0) {
ans.addLast(small.pollLast());
} else {
ans.addLast(big.pollFirst());
}
}
while (!small.isEmpty()) {
ans.addLast(small.pollLast());
}
while (!big.isEmpty()) {
ans.addLast(big.pollFirst());
}
// System.out.println(ans);
for (int x : ans) {
pw.print(x + " ");
}
pw.println();
} else {
pw.println(-1);
}
} else if (max == min + 1) {
LinkedList<Integer> big = new LinkedList<>();
LinkedList<Integer> small = new LinkedList<>();
for (int i = 1; i <= n - max; i++) {
small.add(i);
}
for (int i = n - max + 1; i <= n; i++) {
big.add(i);
}
LinkedList<Integer> ans = new LinkedList<>();
// System.out.println(small+" "+big);
if (max + min + 2 <= n) {
for (int i = 0; i < max + min + 2; i++) {
if (i % 2 == 0) {
ans.addLast(small.pollLast());
} else {
ans.addLast(big.pollFirst());
}
}
while (!small.isEmpty()) {
ans.addLast(small.pollLast());
}
while (!big.isEmpty()) {
ans.addLast(big.pollFirst());
}
// System.out.println(ans);
for (int x : ans) {
pw.print(x + " ");
}
pw.println();
} else {
pw.println(-1);
}
} else if (max == min - 1) {
LinkedList<Integer> big = new LinkedList<>();
LinkedList<Integer> small = new LinkedList<>();
for (int i = 1; i <= min; i++) {
small.add(i);
}
for (int i = min + 1; i <= n; i++) {
big.add(i);
}
LinkedList<Integer> ans = new LinkedList<>();
if (max + min + 2 <= n) {
for (int i = 0; i < max + min + 2; i++) {
if (i % 2 == 0) {
ans.addLast(big.pollFirst());
} else {
ans.addLast(small.pollLast());
}
}
// System.out.println(ans);
while (!big.isEmpty()) {
ans.addLast(big.pollFirst());
}
for (int x : ans) {
pw.print(x + " ");
}
pw.println();
} else {
pw.println(-1);
}
} else {
pw.println(-1);
}
}
pw.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 6287c8b540d9a3197bd0ad781e01651a | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;import java.util.*;import java.math.*;import static java.lang.Math.*;import static java.
util.Map.*;import static java.util.Arrays.*;import static java.util.Collections.*;
import static java.lang.System.*;
public class Main
{
public void tq()throws Exception
{
st=new StringTokenizer(bq.readLine());
int tq=i();
sb=new StringBuilder(2000000);
o:
while(tq-->0)
{
int n=i();
int a=i();
int b=i();
int aa=a;
int bb=b;
int ar[]=new int[n];
if(!(abs(a-b)<2))
{
sl(-1);
continue;
}
if(a==0&&b==1)
{
ar[1]=1;
ar[0]=n;
for(int x=2;x<n;x++)ar[x]=x;
}
else if(b==0&&a==1)
{
ar[1]=n;
ar[0]=1;
int v=n-1;
for(int x=2;x<n;x++)ar[x]=v--;
}
else if(a==0&&b==0)
{
for(int x=0;x<n;x++)ar[x]=x+1;
}
else
{
if(a>=b)
{
int v=n;
for(int x=1;x<n;x+=2)
{
ar[x]=v--;
a--;
if(a==0)break;
}
v=1;
for(int x=2;x<n;x+=2)
{
ar[x]=v++;
b--;
if(b==0)break;
}
}
else
{
int v=1;
for(int x=1;x<n;x+=2)
{
ar[x]=v++;
b--;
if(b==0)break;
}
v=n;
for(int x=2;x<n;x+=2)
{
ar[x]=v--;
a--;
if(a==0)break;
}
}
int vv=0;
for(int x=1;x<n;x++)
{
if(ar[x]==0)
{
vv=ar[x-1];
break;
}
}
if(vv>n/2)
{
for(int x=1;x<n;x++)
{
if(ar[x]==0)ar[x]=ar[x-1]-1;
}
ar[0]=ar[n-1]-1;
}
else
{
for(int x=1;x<n;x++)
{
if(ar[x]==0)ar[x]=ar[x-1]+1;
}
ar[0]=ar[n-1]+1;
}
}
for(int x=1;x<n-1;x++)
{
if(ar[x]>ar[x-1]&&ar[x]>ar[x+1])aa--;
else if(ar[x]<ar[x-1]&&ar[x]<ar[x+1])bb--;
}
if(aa==0&&bb==0)s(ar);
else sl(-1);
}
p(sb);
}
void f(){out.flush();}
int di[][]={{-1,0},{1,0},{0,-1},{0,1}};
int de[][]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}};
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;long maxl=Long.MAX_VALUE, minl=Long.
MIN_VALUE;BufferedReader bq=new BufferedReader(new InputStreamReader(in));StringTokenizer st;
StringBuilder sb;public static void main(String[] a)throws Exception{new Main().tq();}int[] so(int ar[])
{Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;
x++)ar[x]=r[x];return ar;}long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)
r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[]) {Character
r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)
ar[x]=r[x];return ar;}void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.
append(s);}void s(char s){sb.append(s);}void s(double s){sb.append(s);}void ss(){sb.append(' ');}void sl
(String s){sb.append(s);sb.append("\n");}void sl(int s){sb.append(s);sb.append("\n");}void sl(long s){sb
.append(s);sb.append("\n");}void sl(char s) {sb.append(s);sb.append("\n");}void sl(double s){sb.append(s)
;sb.append("\n");}void sl(){sb.append("\n");}int l(int v){return 31-Integer.numberOfLeadingZeros(v);}
long l(long v){return 63-Long.numberOfLeadingZeros(v);}int sq(int a){return (int)sqrt(a);}long sq(long a)
{return (long)sqrt(a);}long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}int gcd(int a,int b)
{while(b>0){int c=a%b;a=b;b=c;}return a;}boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=
s.charAt(j--))return false;return true;}boolean[] si(int n) {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]
=true;for(int x=4;x<=n;x+=2)bo[x]=true;for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;
y+=vv)bo[y]=true;}}return bo;}long mul(long a,long b,long m) {long r=1l;a%=m;while(b>0){if((b&1)==1)
r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}int i()throws IOException{if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());return Integer.parseInt(st.nextToken());}long l()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Long.parseLong(st.nextToken());}String
s()throws IOException {if (!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Double.
parseDouble(st.nextToken());}void p(Object p){out.print(p);}void p(String p){out.print(p);}void p(int p)
{out.print(p);}void p(double p){out.print(p);}void p(long p){out.print(p);}void p(char p){out.print(p);}void
p(boolean p){out.print(p);}void pl(Object p){out.println(p);}void pl(String p){out.println(p);}void pl(int p)
{out.println(p);}void pl(char p){out.println(p);}void pl(double p){out.println(p);}void pl(long p){out.
println(p);}void pl(boolean p)
{out.println(p);}void pl(){out.println();}void s(int a[]){for(int e:a)
{sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[])
{for(long e:a){sb.append(e);sb.append(' ')
;}sb.append("\n");}void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append
("\n");}}
void s(char a[])
{for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}void s(char ar[][])
{for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}int[] ari(int n)throws
IOException {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;
x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}int[][] ari(int n,int m)throws
IOException {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if (!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}long[] arl
(int n)throws IOException {long ar[]=new long[n];if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine())
;for(int x=0;x<n;x++)ar[x]=Long.parseLong(st.nextToken());return ar;}long[][] arl(int n,int m)throws
IOException {long ar[][]=new long[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new
StringTokenizer(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException {String ar[] =new String[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken();return ar;}double[] ard
(int n)throws IOException {double ar[] =new double[n];if(!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}double[][] ard
(int n,int m)throws IOException{double ar[][]=new double[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens())
st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++) ar[x][y]=Double.parseDouble(st.nextToken());}
return ar;}char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}char[][]
arc(int n,int m)throws IOException {char ar[][]=new char[n][m];for(int x=0;x<n;x++){String s=bq.readLine();
for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}void p(int ar[])
{StringBuilder sb=new StringBuilder
(2*ar.length);for(int a:ar){sb.append(a);sb.append(' ');}out.println(sb);}void p(int ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(int a[]:ar){for(int aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(long ar[]){StringBuilder sb=new StringBuilder
(2*ar.length);for(long a:ar){ sb.append(a);sb.append(' ');}out.println(sb);}
void p(long ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(long a[]:ar){for(long aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;
StringBuilder sb=new StringBuilder(c);for(String a:ar){sb.append(a);sb.append(' ');}out.println(sb);}
void p(double ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(double a:ar){sb.append(a);
sb.append(' ');}out.println(sb);}void p
(double ar[][]){StringBuilder sb=new StringBuilder(2*
ar.length*ar[0].length);for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n")
;}p(sb);}void p(char ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(char aa:ar){sb.append(aa);
sb.append(' ');}out.println(sb);}void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0]
.length);for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}void pl
(int... ar){for(int e:ar)p(e+" ");pl();}void pl(long... ar){for(long e:ar)p(e+" ");pl();}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | aecc87f699e822aff6713ede7e83b9a4 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.math.BigInteger;
public final class B
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
static long mod=(long) 998244353,INF=Long.MAX_VALUE;
static boolean set[];
static int par[],col[],D[];
static long A[];
public static void main(String args[])throws IOException
{
/*
* star,rope
*/
int T=i();
outer:while(T-->0)
{
int N=i(),a=i(),b=i();
int A[]=new int[N];
if(a+b>N-2 || Math.max(a, b)>(N-1)/2)
{
ans.append("-1\n");
continue;
}
if(Math.abs(a-b)>1)
{
ans.append("-1\n");
continue;
}
if(a==b)
{
A[0]=N;
int it=1,l=1,r=N-1;
for(int i=0; i<a; i++)
{
A[it]=l;
A[it+1]=r;
it+=2;
l+=1;
r-=1;
}
while(it<N)
{
A[it]=r;
r--;
it++;
}
}
else if(a>b)
{
int it=0,l=1,r=N;
for(int i=0; i<a; i++)
{
A[it]=l;
A[it+1]=r;
it+=2;
l+=1;
r-=1;
}
while(it<N)
{
A[it]=r;
r--;
it++;
}
}
else
{
int it=0,l=1,r=N;
for(int i=0; i<b; i++)
{
A[it]=r;
A[it+1]=l;
it+=2;
l+=1;
r-=1;
}
while(it<N)
{
A[it]=l;
l++;
it++;
}
}
for(int x:A)ans.append(x+" ");
ans.append("\n");
}
out.println(ans);
out.close();
}
static boolean f(long m,long H,long A[],int N)
{
long s=m;
for(int i=0; i<N-1;i++)
{
s+=Math.min(m, A[i+1]-A[i]);
}
return s>=H;
}
static boolean f(int i,int j,long last,boolean win[])
{
if(i>j)return false;
if(A[i]<=last && A[j]<=last)return false;
long a=A[i],b=A[j];
//System.out.println(a+" "+b);
if(a==b)
{
return win[i] | win[j];
}
else if(a>b)
{
boolean f=false;
if(b>last)f=!f(i,j-1,b,win);
return win[i] | f;
}
else
{
boolean f=false;
if(a>last)f=!f(i+1,j,a,win);
return win[j] | f;
}
}
static long ask(long l,long r)
{
System.out.println("? "+l+" "+r);
return l();
}
static long f(long N,long M)
{
long s=0;
if(N%3==0)
{
N/=3;
s=N*M;
}
else
{
long b=N%3;
N/=3;
N++;
s=N*M;
N--;
long a=N*M;
if(M%3==0)
{
M/=3;
a+=(b*M);
}
else
{
M/=3;
M++;
a+=(b*M);
}
s=Math.min(s, a);
}
return s;
}
static int ask(StringBuilder sb,int a)
{
System.out.println(sb+""+a);
return i();
}
static void swap(char X[],int i,int j)
{
char x=X[i];
X[i]=X[j];
X[j]=x;
}
static int min(int a,int b,int c)
{
return Math.min(Math.min(a, b), c);
}
static long and(int i,int j)
{
System.out.println("and "+i+" "+j);
return l();
}
static long or(int i,int j)
{
System.out.println("or "+i+" "+j);
return l();
}
static int len=0,number=0;
static void f(char X[],int i,int num,int l)
{
if(i==X.length)
{
if(num==0)return;
//update our num
if(isPrime(num))return;
if(l<len)
{
len=l;
number=num;
}
return;
}
int a=X[i]-'0';
f(X,i+1,num*10+a,l+1);
f(X,i+1,num,l);
}
static boolean is_Sorted(int A[])
{
int N=A.length;
for(int i=1; i<=N; i++)if(A[i-1]!=i)return false;
return true;
}
static boolean f(StringBuilder sb,String Y,String order)
{
StringBuilder res=new StringBuilder(sb.toString());
HashSet<Character> set=new HashSet<>();
for(char ch:order.toCharArray())
{
set.add(ch);
for(int i=0; i<sb.length(); i++)
{
char x=sb.charAt(i);
if(set.contains(x))continue;
res.append(x);
}
}
String str=res.toString();
return str.equals(Y);
}
static boolean all_Zero(int f[])
{
for(int a:f)if(a!=0)return false;
return true;
}
static long form(int a,int l)
{
long x=0;
while(l-->0)
{
x*=10;
x+=a;
}
return x;
}
static int count(String X)
{
HashSet<Integer> set=new HashSet<>();
for(char x:X.toCharArray())set.add(x-'0');
return set.size();
}
static int f(long K)
{
long l=0,r=K;
while(r-l>1)
{
long m=(l+r)/2;
if(m*m<K)l=m;
else r=m;
}
return (int)l;
}
// static void build(int v,int tl,int tr,long A[])
// {
// if(tl==tr)
// {
// seg[v]=A[tl];
// }
// else
// {
// int tm=(tl+tr)/2;
// build(v*2,tl,tm,A);
// build(v*2+1,tm+1,tr,A);
// seg[v]=Math.min(seg[v*2], seg[v*2+1]);
// }
// }
static int [] sub(int A[],int B[])
{
int N=A.length;
int f[]=new int[N];
for(int i=N-1; i>=0; i--)
{
if(B[i]<A[i])
{
B[i]+=26;
B[i-1]-=1;
}
f[i]=B[i]-A[i];
}
for(int i=0; i<N; i++)
{
if(f[i]%2!=0)f[i+1]+=26;
f[i]/=2;
}
return f;
}
static int[] f(int N)
{
char X[]=in.next().toCharArray();
int A[]=new int[N];
for(int i=0; i<N; i++)A[i]=X[i]-'a';
return A;
}
static int max(int a ,int b,int c,int d)
{
a=Math.max(a, b);
c=Math.max(c,d);
return Math.max(a, c);
}
static int min(int a ,int b,int c,int d)
{
a=Math.min(a, b);
c=Math.min(c,d);
return Math.min(a, c);
}
static HashMap<Integer,Integer> Hash(int A[])
{
HashMap<Integer,Integer> mp=new HashMap<>();
for(int a:A)
{
int f=mp.getOrDefault(a,0)+1;
mp.put(a, f);
}
return mp;
}
static long mul(long a, long b)
{
return ( a %mod * 1L * b%mod )%mod;
}
static void swap(int A[],int a,int b)
{
int t=A[a];
A[a]=A[b];
A[b]=t;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
{
par[a]+=par[b];
par[b]=a;
}
}
static boolean isSorted(int A[])
{
for(int i=1; i<A.length; i++)
{
if(A[i]<A[i-1])return false;
}
return true;
}
static boolean isDivisible(StringBuilder X,int i,long num)
{
long r=0;
for(; i<X.length(); i++)
{
r=r*10+(X.charAt(i)-'0');
r=r%num;
}
return r==0;
}
static int lower_Bound(int A[],int low,int high, int x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static String f(String A)
{
String X="";
for(int i=A.length()-1; i>=0; i--)
{
int c=A.charAt(i)-'0';
X+=(c+1)%2;
}
return X;
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static String swap(String X,int i,int j)
{
char ch[]=X.toCharArray();
char a=ch[i];
ch[i]=ch[j];
ch[j]=a;
return new String(ch);
}
static int sD(long n)
{
if (n % 2 == 0 )
return 2;
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0 )
return i;
}
return (int)n;
}
static void setGraph(int N)
{
par=new int[N+1];
D=new int[N+1];
g=new ArrayList[N+1];
set=new boolean[N+1];
col=new int[N+1];
for(int i=0; i<=N; i++)
{
col[i]=-1;
g[i]=new ArrayList<>();
D[i]=Integer.MAX_VALUE;
}
}
static long pow(long a,long b)
{
//long mod=1000000007;
long pow=1;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}
static long toggleBits(long x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;
return ((1<<n)-1)^x;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static long fact(long N)
{
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
static int kadane(int A[])
{
int lsum=A[0],gsum=A[0];
for(int i=1; i<A.length; i++)
{
lsum=Math.max(lsum+A[i],A[i]);
gsum=Math.max(gsum,lsum);
}
return gsum;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(boolean A[][])
{
for(boolean a[]:A)print(a);
}
static void print(long A[][])
{
for(long a[]:A)print(a);
}
static void print(int A[][])
{
for(int a[]:A)print(a);
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
static long GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 690d333d0f7a95de7dfefeb9198ac6d5 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws java.lang.Exception {
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
String str = br.readLine();
int t = 0;
if (str != null)
t = Integer.parseInt(str.trim());
for (int tt = 0; tt < t; tt++) {
String[] s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int a = Integer.parseInt(s[1]);
int b = Integer.parseInt(s[2]);
if (Math.abs(a - b) > 1 || a > (n-1) / 2 || b > (n-1) / 2 || (n % 2 != 0 && (a == (n-1) / 2 && b == (n-1) / 2)))
out.println("-1");
else {
int[] arr = new int[n];
for (int i = 1; i <= n; i++)
arr[i - 1] = i;
if(a>0||b>0) {
if (a != b) {
if (a > b) {
int i = n - 1;
while (a != 0) {
int temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
i -= 2;
a--;
}
} else {
int i = 0;
while (b != 0) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
i += 2;
b--;
}
}
} else {
int i = n - 2;
while (a != 0) {
int temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
i -= 2;
a--;
}
}
}
for(int i:arr)
out.print(i+" ");
}
out.println();
}
out.close();
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 5e2ac60b4947488fa41c8bb0b21286b3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static PrintWriter pr = new PrintWriter(System.out);
static String readLine() throws IOException {
return br.readLine();
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(readLine());
return st.nextToken();
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readChar() throws IOException {
return next().charAt(0);
}
static class Pair implements Comparable<Pair> {
int f, s;
Pair(int f, int s) {
this.f = f;
this.s = s;
}
public int compareTo(Pair other) {
if (this.f != other.f) return this.f - other.f;
return this.s - other.s;
}
}
static void solve() throws IOException {
int n = readInt(), a = readInt(), b = readInt();
if (Math.abs(a - b) > 1 || a + b > n - 2) {
pr.println(-1);
return;
}
if (a > b) {
int L = 1, R = n;
pr.print(L + " ");
++L;
for (int i = 1; i < a; ++i) {
pr.print(R + " ");
pr.print(L + " ");
++L;
--R;
}
for (int i = R; i >= L; --i) pr.print(i + " ");
} else if (a < b) {
int L = 1, R = n;
pr.print(R + " ");
--R;
for (int i = 1; i < b; ++i) {
pr.print(L + " ");
pr.print(R + " ");
++L;
--R;
}
for (int i = L; i <= R; ++i) pr.print(i + " ");
} else {
int L = 1, R = n;
for (int i = 1; i <= a; ++i) {
pr.print(L + " ");
pr.print(R + " ");
++L;
--R;
}
for (int i = L; i <= R; ++i) pr.print(i + " ");
}
pr.println();
}
public static void main(String[] args) throws IOException {
//solve();
for (int t = readInt(); t > 0; --t) solve();
pr.close();
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | eeece255f193a399a16d087dd0392657 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int numTests = in.nextInt();
for (int test = 0; test < numTests; test++) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int x = Math.max(a, b);
int y = Math.min(a, b);
int[] p = new int[n];
int l = 0;
int r = n - 1;
p[0] = l++;
p[1] = r--;
for (int i = 2; i < n; i++) {
if (i % 2 != 0) {
--y;
if (x == 0 && y == 0) {
while (i < n) {
p[i] = l++;
++i;
}
} else {
p[i] = r--;
}
} else {
--x;
if (x == 0 && y == 0) {
while (i < n) {
p[i] = r--;
++i;
}
} else {
p[i] = l++;
}
}
}
if (l != r + 1) {
throw new AssertionError();
}
if (a == 0 && b == 0) {
for (int i = 0; i < n; i++) {
p[i] = i;
}
}
if (a < b) {
for (int i = 0; i < n; i++) {
p[i] = n - 1 - p[i];
}
}
// System.out.println(x + " " + y + " " + Arrays.toString(p));
if (!check(p, a, b)) {
out.println(-1);
continue;
}
for (int i = 0; i < n; i++) {
if (i > 0) {
out.print(" ");
}
out.print(p[i] + 1);
}
out.println();
}
}
private boolean check(int[] p, int a, int b) {
Set<Integer> used = new HashSet<>();
used.add(p[0]);
used.add(p[p.length - 1]);
for (int i = 1; i + 1 < p.length; i++) {
if (p[i] > p[i - 1] && p[i] > p[i + 1]) {
--a;
}
if (p[i] < p[i - 1] && p[i] < p[i + 1]) {
--b;
}
used.add(p[i]);
}
return a == 0 && b == 0 && used.size() == p.length;
}
}
static class FastScanner {
private BufferedReader in;
private StringTokenizer st;
public FastScanner(InputStream stream) {
try {
in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
} catch (Exception e) {
throw new AssertionError();
}
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String rl = in.readLine();
if (rl == null) {
return null;
}
st = new StringTokenizer(rl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f0b7d5d81d7c4578d02fd26c974530b4 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.io.*;
import java.util.*;
public final class Main {
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)};
static int mod = (int) (1e9 + 7);
static int mod2 = 998244353;
public static void main(String[] args) {
int tt = i();
while (tt-- > 0) {
solve();
}
out.flush();
}
public static void solve() {
int n = i();
int a = i();
int b = i();
if (a + b > n - 2 || Math.abs(a - b) > 1) {
out.println(-1);
return;
}
int[] ans = new int[n];
if (a > b) {
for (int i = 0; i < a; i++) {
ans[2 * i + 1] = n - i;
}
for (int i = 0; i < b; i++) {
ans[2 * i + 2] = i + 1;
}
int r = n - a;
for (int i = 0; i < n; i++) {
if (ans[i] == 0) {
ans[i] = r;
r--;
}
}
} else if (a == b) {
for (int i = 0; i < b; i++) {
ans[2 * i + 1] = i + 1;
}
for (int i = 0; i < a; i++) {
ans[2 * i + 2] = n - i;
}
int r = n - a;
for (int i = 0; i < n; i++) {
if (ans[i] == 0) {
ans[i] = r;
r--;
}
}
} else {
for (int i = 0; i < b; i++) {
ans[2 * i + 1] = i + 1;
}
for (int i = 0; i < a; i++) {
ans[2 * i + 2] = n - i;
}
int r = b + 1;
for (int i = 0; i < n; i++) {
if (ans[i] == 0) {
ans[i] = r;
r++;
}
}
}
print(ans);
}
static long[] pre(int[] a) {
long[] pre = new long[a.length + 1];
pre[0] = 0;
for (int i = 0; i < a.length; i++) {
pre[i + 1] = pre[i] + a[i];
}
return pre;
}
static long[] pre(long[] a) {
long[] pre = new long[a.length + 1];
pre[0] = 0;
for (int i = 0; i < a.length; i++) {
pre[i + 1] = pre[i] + a[i];
}
return pre;
}
static void print(char A[]) {
for (char c : A) {
out.print(c);
}
out.println();
}
static void print(boolean A[]) {
for (boolean c : A) {
out.print(c + " ");
}
out.println();
}
static void print(int A[]) {
for (int c : A) {
out.print(c + " ");
}
out.println();
}
static void print(long A[]) {
for (long i : A) {
out.print(i + " ");
}
out.println();
}
static void print(List<Integer> A) {
for (int a : A) {
out.print(a + " ");
}
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static double d() {
return in.nextDouble();
}
static String s() {
return in.nextLine();
}
static String c() {
return in.next();
}
static int[][] inputWithIdx(int N) {
int A[][] = new int[N][2];
for (int i = 0; i < N; i++) {
A[i] = new int[]{i, in.nextInt()};
}
return A;
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[] = new long[N];
for (int i = 0; i < A.length; i++) {
A[i] = in.nextLong();
}
return A;
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long LCM(int a, int b) {
return (long) a / GCD(a, b) * b;
}
static long LCM(long a, long b) {
return a / GCD(a, b) * b;
}
static void shuffleAndSort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
int temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr);
}
static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
int[] temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr, comparator);
}
static void shuffleAndSort(long[] arr) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
long temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr);
}
static boolean isPerfectSquare(double number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static void swap(int A[], int a, int b) {
int t = A[a];
A[a] = A[b];
A[b] = t;
}
static void swap(char A[], int a, int b) {
char t = A[a];
A[a] = A[b];
A[b] = t;
}
static long pow(long a, long b, int mod) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow = (pow * x) % mod;
}
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static long pow(long a, long b) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow *= x;
}
x = x * x;
b /= 2;
}
return pow;
}
static long modInverse(long x, int mod) {
return pow(x, mod - 2, mod);
}
static boolean isPrime(long N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
if (N % 2 == 0 || N % 3 == 0) {
return false;
}
for (int i = 5; i * i <= N; i = i + 6) {
if (N % i == 0 || N % (i + 2) == 0) {
return false;
}
}
return true;
}
public static String reverse(String str) {
if (str == null) {
return null;
}
return new StringBuilder(str).reverse().toString();
}
public static void reverse(int[] arr) {
for (int i = 0; i < arr.length / 2; i++) {
int tmp = arr[i];
arr[arr.length - 1 - i] = tmp;
arr[i] = arr[arr.length - 1 - i];
}
}
public static String repeat(char ch, int repeat) {
if (repeat <= 0) {
return "";
}
final char[] buf = new char[repeat];
for (int i = repeat - 1; i >= 0; i--) {
buf[i] = ch;
}
return new String(buf);
}
public static int[] manacher(String s) {
char[] chars = s.toCharArray();
int n = s.length();
int[] d1 = new int[n];
for (int i = 0, l = 0, r = -1; i < n; i++) {
int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1);
while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) {
k++;
}
d1[i] = k--;
if (i + k > r) {
l = i - k;
r = i + k;
}
}
return d1;
}
public static int[] kmp(String s) {
int n = s.length();
int[] res = new int[n];
for (int i = 1; i < n; ++i) {
int j = res[i - 1];
while (j > 0 && s.charAt(i) != s.charAt(j)) {
j = res[j - 1];
}
if (s.charAt(i) == s.charAt(j)) {
++j;
}
res[i] = j;
}
return res;
}
}
class Pair {
int i;
int j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Pair pair = (Pair) o;
return i == pair.i && j == pair.j;
}
@Override
public int hashCode() {
return Objects.hash(i, j);
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
class Node {
int val;
public Node(int val) {
this.val = val;
}
}
class ST {
int n;
Node[] st;
ST(int n) {
this.n = n;
st = new Node[4 * Integer.highestOneBit(n)];
}
void build(Node[] nodes) {
build(0, 0, n - 1, nodes);
}
private void build(int id, int l, int r, Node[] nodes) {
if (l == r) {
st[id] = nodes[l];
return;
}
int mid = (l + r) >> 1;
build((id << 1) + 1, l, mid, nodes);
build((id << 1) + 2, mid + 1, r, nodes);
st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
}
void update(int i, Node node) {
update(0, 0, n - 1, i, node);
}
private void update(int id, int l, int r, int i, Node node) {
if (i < l || r < i) {
return;
}
if (l == r) {
st[id] = node;
return;
}
int mid = (l + r) >> 1;
update((id << 1) + 1, l, mid, i, node);
update((id << 1) + 2, mid + 1, r, i, node);
st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
}
Node get(int x, int y) {
return get(0, 0, n - 1, x, y);
}
private Node get(int id, int l, int r, int x, int y) {
if (x > r || y < l) {
return new Node(0);
}
if (x <= l && r <= y) {
return st[id];
}
int mid = (l + r) >> 1;
return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y));
}
Node comb(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
return new Node(a.val | b.val);
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | afb387752e439ce55478a88ff98fa4fa | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int test = in.nextInt();
for(int t = 1 ;t<=test;t++){
int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();
if(a+b>(n-2) || (Math.abs(a-b)>1)){
pw.println("-1");
}
else{
int ara[] = new int[n];
for(int i = 0;i<n;i++){
ara[i] = (i+1);
}
if(a==b){
for(int i = 1;a>0;i=i+2){
int temp = ara[i];
ara[i] = ara[i+1];
ara[i+1] = temp;
a--;
}
}
else if(a>b){
for(int i = n-1;a>0;i-=2){
int temp = ara[i];
ara[i] = ara[i-1];
ara[i-1] = temp;
a--;
}
}
else {
for(int i = 0;b>0;i+=2){
int temp = ara[i];
ara[i] = ara[i+1];
ara[i+1] = temp;
b--;
}
}
for(int i = 0;i<n;i++){
pw.print(ara[i]+" ");
}
pw.println();
}
}
pw.close();
}
static void debug(Object... obj) {
System.err.println(Arrays.deepToString(obj));
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 84e63d03dab7583767583fe78067ab8c | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class A {
public static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void print(int[] a) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println();
}
public static String concat(String s1, String s2) {
return new StringBuilder(s1).append(s2).toString();
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t1 = sc.nextInt();
outer: while (t1-- > 0) {
long n = sc.nextLong(),max = sc.nextLong(),min = sc.nextLong();
long a[] = new long[(int)n];
for (int i = 0;i<n;i++) a[i] = i+1;
if (max + min >(n-2) || Math.abs(max-min)>1 ) {
out.println(-1);
}else {
long h = max+min;
long cnt = 0;
if (max >min || max == min) {
for (int i = 0;i<n-2-h;i++) {
out.print(a[i]+" ");
cnt++;
}
long j = n-2-h-1;
for (long i = j+1,k = 0;k<(n-cnt+1)/2;i++,k++) {
out.print(a[(int)i]+" ");
if (a[(int)i] !=a[(int)n-(int)k-1])
out.print(a[(int)n-(int)k-1]+" ");
}
}else {
for (int i = 0,k = (int)n-1;i<n-2-h;i++,k--) {
out.print(a[k]+" ");
cnt++;
}
long j = n-2-h-1;
for (long i = 0,k = 0;k<(n-cnt+1)/2;i++,k++) {
out.print(a[(int)n-(int)cnt-1-(int)i]+" ");
if (a[(int)i] !=a[(int)n-(int)cnt-1-(int)i])
out.print(a[(int)i]+" ");
}
}
}
out.println();
}
out.close();
}
static class Pair implements Comparable<Pair> {
long first;
long second;
public Pair(long first, long second) {
this.first = first;
this.second = second;
}
public int compareTo(Pair p) {
if (first != p.first)
return Long.compare(first, p.first);
else if (second != p.second)
return Long.compare(second, p.second);
else
return 0;
}
}
static class Tuple implements Comparable<Tuple> {
long first;
long second;
long third;
public Tuple(long a, long b, long c) {
first = a;
second = b;
third = c;
}
public int compareTo(Tuple t) {
if (first != t.first)
return Long.compare(first, t.first);
else if (second != t.second)
return Long.compare(second, t.second);
else if (third != t.third)
return Long.compare(third, t.third);
else
return 0;
}
}
static final Random random = new Random();
static void shuffleSort(int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
int r = random.nextInt(n), temp = a[r];
a[r] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
int[] readArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f85ca1a61ef2777b97b63f60e29949e7 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i=0; i<t; i++) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
if (Math.abs(a - b) > 1 || Math.max(a, b) > Math.ceil((double) n / 2) - 1) {
System.out.println(-1);
}
else {
if (n % 2 == 1 && Math.min(a, b) == Math.ceil((double) n / 2) - 1) {
System.out.println(-1);
}
else {
if (a > b) {
// Start on bottom.
for (int j = 1; j <= n - a; j++) {
if (j <= a) {
System.out.print(j + " ");
}
System.out.print(n - j + 1 + " ");
}
}
else if (a < b) {
// Start on top.
for (int j = 1; j <= n - b; j++) {
if (j <= b) {
System.out.print(n - j + 1 + " ");
}
System.out.print(j + " ");
}
}
else {
for (int j = 1; j <= n - a; j++) {
System.out.print(j + " ");
if (j <= a) {
System.out.print(n - j + 1 + " ");
}
}
}
}
}
System.out.println();
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 1f9a6b0dc15620450a511de31b5b8f84 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.Scanner;
public class B1608 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int t=0; t<T; t++) {
int N = in.nextInt();
int A = in.nextInt();
int B = in.nextInt();
boolean ok = true;
if (A+B > N-2) {
ok = false;
}
if (A != B && A != B+1 && B != A+1) {
ok = false;
}
if (ok) {
StringBuilder sb = new StringBuilder();
if (A == B) {
for (int a=1; a<=A+1; a++) {
sb.append(a).append(' ').append(a+(A+1)).append(' ');
}
for (int i=2*(A+1)+1; i<=N; i++) {
sb.append(i).append(' ');
}
} else if (A > B) {
int base = N-2*A;
for (int a=1; a<=A; a++) {
sb.append(base+a).append(' ').append(base+A+a).append(' ');
}
for (int i=base; i>=1; i--) {
sb.append(i).append(' ');
}
} else {
for (int b=1; b<=B; b++) {
sb.append(B+b).append(' ').append(b).append(' ');
}
for (int i=2*B+1; i<=N; i++) {
sb.append(i).append(' ');
}
}
System.out.println(sb);
} else {
System.out.println("-1");
}
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | e785e27dd1f26ab25ac29b2fafeba658 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Ac {
static int MOD = 998244353;
static int MAX = (int)1e8;
static Random rand = new Random();
static FastReader in = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
static StringBuffer sb = new StringBuffer();
public static void main(String[] args) {
int t = i();
out.println();
out.println();
out.println();
// randArr(10, 10, 10);
// out.println(arr[1] + " " + arr[5]);
while (t-- > 0){
sol();
// out.println(sol(arr));
// int[] ans = sol();
// for (int i = 0; i < ans.length; i++){
// out.print(ans[i] + " ");
// }
// out.println();
// boolean ans = sol();
// if (ans){
// out.println("YES");
// }else{
// out.println("NO");
// }
}
out.flush();
out.close();
}
static void sol(){
sb = new StringBuffer();
int n = i();
int a = i(), b = i();
if (a + b == 0){
for (int i = 1 ; i< n + 1; i++){
out.print(i + " ");
}
out.println();
return;
}
if (Math.abs(a - b) > 1 || n < 2 + a + b){
out.println(-1);
return;
}
boolean flag = a > b;
int l = 1, r = n;
if (flag){
out.print(l++ + " " + r-- + " ");
}else{
out.print(r-- + " " + l++ + " ");
}
while (true){
if (a + b < 2){
if (flag){
while (l <= r){
out.print(r-- + " ");
}
}else{
while (l <= r){
out.print(l++ + " ");
}
}
break;
}
if (flag){
out.print(l++ + " ");
a--;
}else{
out.print(r-- + " ");
b--;
}
flag = !flag;
}
out.println();
}
static void randArr(int num, int n, int val){
for (int i = 0; i < num; i++){
int len = rand.nextInt(n + 1);
System.out.println(len);
for (int j = 0; j < len; j++){
System.out.print(rand.nextInt(val) + 1 + " ");
}
System.out.println();
}
}
static void shuffle(int a[], int n){
for (int i = 0; i < n; i++) {
int t = (int)Math.random() * a.length;
int x = a[t];
a[t] = a[i];
a[i] = x;
}
}
static int gcd(int a, int b){
return a % b == 0 ? a : gcd(b, a % b);
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static double d() {
return in.nextDouble();
}
static String s(){
return in.nextLine();
}
static int[] inputI(int n) {
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = i();
}
return nums;
}
static long[] inputL(int n) {
long[] nums = new long[n];
for (int i = 0; i < n; i++) {
nums[i] = l();
}
return nums;
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 67761dc1c5f3f26a3795671163fb79f8 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Solution {
private static Scanner scanner = new Scanner(System.in);
private static final String endl = "\n";
private static int readInt() {
return scanner.nextInt();
}
private static String readString() {
return scanner.next();
}
private static String readLine() {
return scanner.nextLine();
}
private static void print(String str) {
System.out.print(str);
}
private static void print(int v) {
System.out.print(v);
}
public static void main(String[] args) {
int T;
T = readInt();
while (T -- > 0) {
int n;
n = readInt();
int[] x = new int[2];
x[0] = readInt();
x[1] = readInt();
if (x[0] + x[1] > n - 2 || Math.abs(x[0] - x[1]) > 1) {
print("-1\n");
continue;
}
int[] y = new int[2];
y[0] = n;
y[1] = 1;
int p;
if (x[0] >= x[1]) {
print(1);
if (x[0] > 0) p = 0;
else p = 1;
y[1] ++;
} else {
print(n);
if (x[1] > 0) p = 1;
else p = 0;
y[0] --;
}
while (x[0] > 0 || x[1] > 0) {
print(" " + y[p]);
x[p] --;
y[p] += p == 0 ? -1 : 1;
if (x[p ^ 1] > 0) p ^= 1;
}
while (y[0] >= y[1]) {
print(" " + y[p]);
y[p] += p == 0 ? -1 : 1;
}
print("\n");
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f4e937cf0bf00af71374a5f83df5bc8b | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class BuildThePermutation{
static long mod = 1000000007L;
static MyScanner sc = new MyScanner();
static void solve() {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(Math.abs(a-b)>1||(a+b)>n-2)
{
System.out.println(-1);
return;
}
if(a>b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=a;i++)
{
System.out.print(l++ +" ");
System.out.print(r-- +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
else if(a<b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=l;i<=r;i++)System.out.print(i+" ");
System.out.println();
}
else
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
}
static String reverse(String str){
char arr[] = str.toCharArray();
int i = 0;
int j = arr.length-1;
while(i<j){
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
String st = new String(arr);
return st;
}
static boolean isprime(int n){
if(n==1 || n==2) return false;
if(n==3) return true;
if(n%2==0 || n%3==0) return false;
for(int i = 5;i*i<=n;i+= 6){
if(n%i== 0 || n%(i+2)==0){
return false;
}
}
return true;
}
static class Pair implements Comparable<Pair>{
int val;
int freq;
Pair(int v,int f){
val = v;
freq = f;
}
public int compareTo(Pair p){
return this.freq - p.freq;
}
}
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while(t-- >0){
// solve();
solve();
}
// Stop writing your solution here. -------------------------------------
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int[] readIntArray(int n){
int arr[] = new int[n];
for(int i = 0;i<n;i++){
arr[i] = Integer.parseInt(next());
}
return arr;
}
int[] reverse(int arr[]){
int n= arr.length;
int i = 0;
int j = n-1;
while(i<j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
j--;i++;
}
return arr;
}
long[] readLongArray(int n){
long arr[] = new long[n];
for(int i = 0;i<n;i++){
arr[i] = Long.parseLong(next());
}
return arr;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static void sort(int[] arr) {
List<Integer> list = new ArrayList<>();
for (int i=0; i<arr.length; i++){
list.add(arr[i]);
}
Collections.sort(list); // collections.sort uses nlogn in backend
for (int i = 0; i < arr.length; i++){
arr[i] = list.get(i);
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | b214a2b2660ac3ce43b5ccf483bf3ee3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Contest_yandexA{
static final int MAXN = (int)1e6;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
/*int n = input.nextInt();
int k = input.nextInt();
k = k%4;
int[] a = new int[n];
for(int i = 0;i<n;i++){
a[i] = input.nextInt();
}
int[] count = new int[n];
int sum = 0;
for(int tt = 0;tt<k;tt++){
for(int i = 0;i<n;i++){
count[a[i]-1]++;
}
for(int i = 0;i<n;i++){
sum+= count[i];
}
for(int i = 0;i<n;i++){
a[i] = sum;
sum-= count[i];
}
}
for(int i = 0;i<n;i++){
System.out.print(a[i] + " ");
}*/
int t = input.nextInt();
for(int tt = 0;tt<t;tt++){
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
if(Math.abs(a-b)>1||(a+b)>n-2)
{
System.out.println(-1);
continue;
}
if(a>b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=a;i++)
{
System.out.print(l++ +" ");
System.out.print(r-- +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
else if(a<b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=l;i<=r;i++)System.out.print(i+" ");
System.out.println();
}
else
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
}
}
public static int gcd(int a,int b){
if(b == 0){
return a;
}
return gcd(b,a%b);
}
public static int lcm(int a,int b){
return (a / gcd(a, b)) * b;
}
}
class Pair implements Comparable<Pair>{
int l;
int r;
Pair(int l,int r){
this.l = l;
this.r = r;
}
@Override
public int compareTo(Pair p){
return this.l-p.l;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 1dab7abb302e825a5b5139b60925b08a | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Contest_yandexA{
static final int MAXN = (int)1e6;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
/*int n = input.nextInt();
int k = input.nextInt();
k = k%4;
int[] a = new int[n];
for(int i = 0;i<n;i++){
a[i] = input.nextInt();
}
int[] count = new int[n];
int sum = 0;
for(int tt = 0;tt<k;tt++){
for(int i = 0;i<n;i++){
count[a[i]-1]++;
}
for(int i = 0;i<n;i++){
sum+= count[i];
}
for(int i = 0;i<n;i++){
a[i] = sum;
sum-= count[i];
}
}
for(int i = 0;i<n;i++){
System.out.print(a[i] + " ");
}*/
int t = input.nextInt();
for(int tt = 0;tt<t;tt++){
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
if(Math.abs(a-b)>1||(a+b)>n-2)
{
System.out.println(-1);
continue;
}
if(a>b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=a;i++)
{
System.out.print(l++ +" ");
System.out.print(r-- +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
else if(a<b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=l;i<=r;i++)System.out.print(i+" ");
System.out.println();
}
else
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
}
}
public static int gcd(int a,int b){
if(b == 0){
return a;
}
return gcd(b,a%b);
}
public static int lcm(int a,int b){
return (a / gcd(a, b)) * b;
}
}
class Pair implements Comparable<Pair>{
int l;
int r;
Pair(int l,int r){
this.l = l;
this.r = r;
}
@Override
public int compareTo(Pair p){
return this.l-p.l;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 1070d07b3d154ada2c135bf2f22a6675 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
// C:\Users\Lenovo\Desktop\New
//ArrayList<Integer> a=new ArrayList<>();
//List<Integer> lis=new ArrayList<>();
//StringBuilder ans = new StringBuilder();
//HashMap<Integer,Integer> map=new HashMap<>();
public class cf {
static FastReader in=new FastReader();
static final Random random=new Random();
static long mod=1000000007L;
public static void main(String args[]) throws IOException {
FastReader sc=new FastReader();
int t=sc.nextInt();
//int t=1;
while(t-->0){
//boolean check=true;
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
if(Math.abs(a-b)>1){
System.out.println(-1);
}
else if(a+b>n-2){
System.out.println(-1);
}
else{
if(a==b){
int l=1;
int r=n;
for(int i=1;i<=a;i++){
System.out.print(l+" ");
System.out.print(r +" ");
l++;
r--;
}
for(int i=l;i<=r;i++){
System.out.print(i+" ");
}
System.out.println();
}
else if(a>b){
int l=1;
int r=n;
int i;
for(i=1;i<=a;i++)
{
System.out.print(l++ +" ");
System.out.print(r-- +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
else{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=l;i<=r;i++)System.out.print(i+" ");
System.out.println();
}
}
//int k=sc.nextInt();
/*int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}*/
}
}
/* static boolean checkprime(int n1)
{
if(n1%2==0||n1%3==0)
return false;
else
{
for(int i=5;i*i<=n1;i+=6)
{
if(n1%i==0||n1%(i+2)==0)
return false;
}
return true;
}
}
*/
/* static class Pair implements Comparable
{
int a,b;
public String toString()
{
return a+" " + b;
}
public Pair(int x , int y)
{
a=x;b=y;
}
@Override
public int compareTo(Object o) {
Pair p = (Pair)o;
if(p.a!=a){
return a-p.a;//increasing
}
else{
return p.b-b;//decreasing
}
}
}*/
/* public static boolean checkAP(List<Integer> lis){
for(int i=1;i<lis.size()-1;i++){
if(2*lis.get(i)!=lis.get(i-1)+lis.get(i+1)){
return false;
}
}
return true;
}
public static int minBS(int[]arr,int val){
int l=-1;
int r=arr.length;
while(r>l+1){
int mid=(l+r)/2;
if(arr[mid]>=val){
r=mid;
}
else{
l=mid;
}
}
return r;
}
public static int maxBS(int[]arr,int val){
int l=-1;
int r=arr.length;
while(r>l+1){
int mid=(l+r)/2;
if(arr[mid]<=val){
l=mid;
}
else{
r=mid;
}
}
return l;
}
static void ruffleSort(int[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}*/
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f125dc809330b5a738ce49389157bef7 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
public class CodeForces {
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(){
br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
}
public FastScanner(File f){
try {
br=new BufferedReader(new FileReader(f));
st=new StringTokenizer("");
} catch(FileNotFoundException e){
br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
}
}
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a =new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
public static long factorial(int n){
if(n==0)return 1;
return (long)n*factorial(n-1);
}
public static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
public static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
static void sort (int[]a){
ArrayList<Integer> b = new ArrayList<>();
for(int i:a)b.add(i);
Collections.sort(b);
for(int i=0;i<b.size();i++){
a[i]=b.get(i);
}
}
static void sortReversed (int[]a){
ArrayList<Integer> b = new ArrayList<>();
for(int i:a)b.add(i);
Collections.sort(b,new Comparator<Integer>(){
@Override
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
for(int i=0;i<b.size();i++){
a[i]=b.get(i);
}
}
static void sort (long[]a){
ArrayList<Long> b = new ArrayList<>();
for(long i:a)b.add(i);
Collections.sort(b);
for(int i=0;i<b.size();i++){
a[i]=b.get(i);
}
}
static ArrayList<Integer> sieveOfEratosthenes(int n)
{
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
ArrayList<Integer> ans = new ArrayList<>();
for (int i = 2; i <= n; i++)
{
if (prime[i] == true)
ans.add(i);
}
return ans;
}
static int binarySearchSmallerOrEqual(int arr[], int key)
{
int n = arr.length;
int left = 0, right = n;
int mid = 0;
while (left < right) {
mid = (right + left) >> 1;
if (arr[mid] == key) {
while (mid + 1 < n && arr[mid + 1] == key)
mid++;
break;
}
else if (arr[mid] > key)
right = mid;
else
left = mid + 1;
}
while (mid > -1 && arr[mid] > key)
mid--;
return mid;
}
public static int binarySearchStrictlySmaller(int[] arr, int target)
{
int start = 0, end = arr.length-1;
if(end == 0) return -1;
if (target > arr[end]) return end;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (arr[mid] >= target) {
end = mid - 1;
}
else {
ans = mid;
start = mid + 1;
}
}
return ans;
}
static int binarySearch(int arr[], int x)
{
int l = 0, r = arr.length - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (arr[m] == x)
return m;
if (arr[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
static int binarySearch(long arr[], long x)
{
int l = 0, r = arr.length - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (arr[m] == x)
return m;
if (arr[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
static void init(int[]arr,int val){
for(int i=0;i<arr.length;i++){
arr[i]=val;
}
}
static void init(int[][]arr,int val){
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[i].length;j++){
arr[i][j]=val;
}
}
}
static void init(long[]arr,long val){
for(int i=0;i<arr.length;i++){
arr[i]=val;
}
}
static<T> void init(ArrayList<ArrayList<T>>arr,int n){
for(int i=0;i<n;i++){
arr.add(new ArrayList());
}
}
public static int binarySearchStrictlySmaller(ArrayList<Pair> arr, int target)
{
int start = 0, end = arr.size()-1;
if(end == 0) return -1;
if (target > arr.get(end).y) return end;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (arr.get(mid).y >= target) {
end = mid - 1;
}
else {
ans = mid;
start = mid + 1;
}
}
return ans;
}
public static void main(String[] args) {
// StringBuilder sbd = new StringBuilder();
StringBuffer sbf = new StringBuffer();
// PrintWriter p = new PrintWriter("output.txt");
// File input = new File("popcorn.in");
// FastScanner fs = new FastScanner(input);
//
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int testNumber =fs.nextInt();
// ArrayList<Integer> name = new ArrayList<>();
for (int T =0;T<testNumber;T++){
int n= fs.nextInt();
int a= fs.nextInt();
int b= fs.nextInt();
if(Math.abs(a-b)>1||a+b>n-2){
out.print("-1");
}else {
if(a>=b){
int max = n;
int min =2;
boolean bigger=true;
out.print("1 ");
while(max>min){
if(a==0&&b==0)break;
if(bigger){
out.print(max+" ");
max--;
a--;
} else {
out.print(min+" ");
min++;
b--;
}
bigger=!bigger;
}
if(!bigger){
for (int i=max;i>=min;i--)out.print(i+" ");
} else for (int i=min;i<=max;i++)out.print(i+" ");
} else {
int max = n-1;
int min =1;
boolean bigger=false;
out.print(n+" ");
while(max>min){
if(a==0&&b==0)break;
if(bigger){
out.print(max+" ");
max--;
a--;
} else {
out.print(min+" ");
min++;
b--;
}
bigger=!bigger;
}
if(!bigger){
for (int i=max;i>=min;i--)out.print(i+" ");
} else for (int i=min;i<=max;i++)out.print(i+" ");
}
}
out.print("\n");
}
out.flush();
}
static class Pair {
int x;//l
int y;//r
public Pair(int x,int y){
this.x=x;
this.y=y;
}
@Override
public boolean equals(Object o) {
if(o instanceof Pair){
if(o.hashCode()!=hashCode()){
return false;
} else {
return x==((Pair)o).x&&y==((Pair)o).y;
}
}
return false;
}
@Override
public int hashCode() {
return x+2*y;
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | cac60d9e4c6f2684c2c68ca9cc8cd9e5 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class BuildThePermutation {
static void display(Vector<Integer> x){
PrintWriter pw = new PrintWriter(System.out);
for (int i=0; i<x.size() ;i++)
pw.print(x.elementAt(i)+" ");
pw.println();
pw.flush();
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt() , a = sc.nextInt() , b = sc.nextInt();
int left = 1, right = n , back = 0;
Vector<Integer> x = new Vector<>(n);
if(a+b > n-2 || Math.abs(a-b)>1)
System.out.println(-1);
else{
if(a==b){
int h = 0 ;
x.add(left++);
while (h<a){
x.add(right--);
x.add(left++);
h++;
}
for(int i=left; i <= right ;i++)
x.add(i);
}
else if(a>b){
int h = 0 ;
x.add(left++);
while (h<a-1){
x.add(right--);
x.add(left++ );
h++;
}
for(int i=right; i >= left ;i--)
x.add(i);
}
else{
int h = 0 ;
x.add(right);
right--;
while (h<b-1){
x.add(left);
left++;
x.add(right);
right--;
h++;
}
for(int i=left; i <=right ;i++)
x.add(i);
}
display(x);
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int[] nextIntArr(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 6c10106902a7636c24e14dd0591f8e56 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.math.*;
import java.util.* ;
import java.io.* ;
@SuppressWarnings("unused")
public class B
{
static final int mod = (int)1e9+7 ;
static final double pi = 3.1415926536 ;
static boolean not_prime[] = new boolean[1000001] ;
static void sieve() {
for(int i=2 ; i*i<1000001 ; i++) {
if(not_prime[i]==false) {
for(int j=2*i ; j<1000001 ; j+=i) {
not_prime[j]=true ;
}
}
}not_prime[0]=true ; not_prime[1]=true ;
}
public static long bexp(long base , long power)
{
long res=1L ;
base = base%mod ;
while(power>0) {
if((power&1)==1) {
res=(res*base)%mod ;
power-- ;
}
else {
base=(base*base)%mod ;
power>>=1 ;
}
}
return res ;
}
static long modInverse(long n, long p){return power(n, p - 2, p); }
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long nCrModPFermat(int n, int r, long p){if(n<r) return 0 ;if (r == 0)return 1; long[] fac = new long[n + 1];fac[0] = 1;for (int i = 1; i <= n; i++)fac[i] = fac[i - 1] * i % p;return (fac[n] * modInverse(fac[r], p) % p* modInverse(fac[n - r], p) % p) % p;}
static long mod_add(long a, long b){ return ((a % mod) + (b % mod)) % mod; }
static long mod_sub(long a, long b){ return ((a % mod) - (b % mod) + mod) % mod; }
static long mod_mult(long a, long b){ return ((a % mod) * (b % mod)) % mod; }
static long lcm(int a, int b){ return (a / gcd(a, b)) * b; }
static long gcd(long a, long b){if (b == 0) {return a;}return gcd(b, a % b);}
public static void main(String[] args)throws IOException//throws FileNotFoundException
{
FastReader in = new FastReader() ;
StringBuilder op = new StringBuilder() ;
int T = in.nextInt() ;
// int T=1 ;
for(int tt=0 ; tt<T ; tt++)
{
int n = in.nextInt() ;
int a = in.nextInt() ;
int b = in.nextInt() ;
int maxfill=n ;
int minfill=1 ;
if(Math.abs(a-b)>1 || a+b>n-2) {
op.append("-1\n") ; continue ;
}
if(a>b) {
for(int i=1 ; i<=2*a ; i++) {
if((i&1)==1)op.append(minfill++).append(" ") ;
else op.append(maxfill--).append(" ") ;
}
for(int i=2*a+1 ; i<=n ; i++) {
op.append(maxfill--).append(" ") ;
}
}
else if(a<b) {
for(int i=1 ; i<=2*b ; i++) {
if((i&1)==1)op.append(maxfill--).append(" ") ;
else op.append(minfill++).append(" ") ;
}
for(int i=2*b+1 ; i<=n ; i++) {
op.append(minfill++).append(" ") ;
}
}
else if(a!=0){
for(int i=1 ; i<=2*a ; i++) {
if((i&1)==1)op.append(minfill++).append(" ") ;
else op.append(maxfill--).append(" ") ;
}
for(int i=2*a+1 ; i<=n ; i++) {
op.append(minfill++).append(" ") ;
}
}
else {
for(int i=1 ; i<=n ; i++)
op.append(maxfill--).append(" ") ;
}
op.append("\n") ;
}
System.out.println(op.toString());
}
static class pair implements Comparable<pair>
{
int first , second ;
pair(int first , int second){
this.first=first ;
this.second=second;
}
public int compareTo(pair other) {
return this.first-other.first ;
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble(){ return Double.parseDouble(next()); };
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 5ce77c7c9cf158a79818d2c60d6edcfc | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.Scanner;
/**
*
* @author Acer
*/
public class BuildThePermutation_B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-- > 0){
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(Math.abs(a-b) > 1 || a+b > n-2){
System.out.println(-1);
continue;
}
if(a > b){
int l = 1;
int r = n;
for (int i = 1; i <= a; i++) {
System.out.print(l+" ");
l++;
System.out.print(r+" ");
r--;
}
for (int i = r; i >= l; i--) {
System.out.print(i+" ");
}
}
else if(a < b){
int l = 1;
int r = n;
for (int i = 1; i <= b; i++) {
System.out.print(r+" ");
r--;
System.out.print(l+" ");
l++;
}
for (int i = l; i <= r; i++) {
System.out.print(i+" ");
}
}
else{
int l = 1;
int r = n;
for (int i = 1; i <= a; i++) {
System.out.print(l+" ");
l++;
System.out.print(r+" ");
r--;
}
for (int i = l; i <= r; i++) {
System.out.print(i+" ");
}
}
System.out.println();
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 8fad98038edd2cd9f82e27cd338ed104 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
while (t != 0) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
if(a+b+2>n || Math.abs(a-b)>1){
sb.append("-1").append("\n");
}
else{
boolean reverse= a < b;
sb.append(getPermutation(n,Math.max(a,b),Math.min(a,b),reverse)).append("\n");
}
t--;
}
System.out.println(sb);
}
private static String getPermutation(int n, int a, int b, boolean reverse) {
int total=a+b+2;
int start=n;
int end=n-total+1;
int remain=end-1;
StringBuilder sb=new StringBuilder();
boolean toggle=true;
for(int i=0;i<total;i++){
if(toggle){
sb.append(end).append(" ");
end++;
toggle= false;
}
else{
sb.append(start).append(" ");
start--;
toggle= true;
}
}
StringBuilder sb2 = new StringBuilder();
for(int i=1;i<=remain;i++){
sb2.append(i).append(" ");
}
sb2.append(sb.toString().trim());
if(reverse){
return getReverse(n,sb2.toString());
}
return sb2.toString();
}
public static String getReverse(int n,String s){
StringBuilder sb=new StringBuilder();
for(String c:s.split(" ")){
sb.append(n-Integer.parseInt(c)+1).append(" ");
}
return sb.toString().trim();
}
public static void swap(int[] ar,int i,int j){
int temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
public static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 58d3a17b90fbbbbf801b657fd5e697e3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.beans.DesignMode;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.CompletableFuture.AsynchronousCompletionTask;
import org.xml.sax.ErrorHandler;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
public class Solution {
//TEMPLATE -------------------------------------------------------------------------------------
public static boolean Local(){
try{
return System.getenv("LOCAL_SYS")!=null;
}catch(Exception e){
return false;
}
}
public static boolean LOCAL;
static class FastScanner {
BufferedReader br;
StringTokenizer st ;
FastScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
FastScanner(String file) {
try{
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
st = new StringTokenizer("");
}catch(FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("file not found");
e.printStackTrace();
}
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String readLine() throws IOException{
return br.readLine();
}
}
static class Pair<T,X> {
T first;
X second;
Pair(T first,X second){
this.first = first;
this.second = second;
}
@Override
public int hashCode(){
return Objects.hash(first,second);
}
@Override
public boolean equals(Object obj){
return obj.hashCode() == this.hashCode();
}
}
static PrintStream debug = null;
static long mod = (long)(Math.pow(10,9) + 7);
//TEMPLATE -------------------------------------------------------------------------------------END//
public static void main(String[] args) throws Exception {
FastScanner s = new FastScanner();
LOCAL = Local();
//PrintWriter pw = new PrintWriter(System.out);
if(LOCAL){
s = new FastScanner("src/input.txt");
PrintStream o = new PrintStream("src/sampleout.txt");
debug = new PrintStream("src/debug.txt");
System.setOut(o);
// pw = new PrintWriter(o);
} long mod = 1000000007;
int tcr = s.nextInt();
StringBuilder sb = new StringBuilder();
for(int tc=0;tc<tcr;tc++){
int n = s.nextInt();
int a = s.nextInt();
int b = s.nextInt();
if((Math.abs(a-b) <= 1) && ((a+b) <= (n-2))){
if(a > b){
int curr = n;
int ans[] = new int[n];
int index = 1;
int cnt = 0;
while(cnt < a){
ans[index] = curr;
curr--;
cnt++;
index+=2;
}
for(int i=0;i<n;i++){
if(ans[i] == 0){
ans[i] = curr;
curr--;
}
}
for(int i=0;i<n;i++){
sb.append(ans[i]+" ");
}
sb.append('\n');
}else if(a < b){
int curr = 1;
int ans[] = new int[n];
int index = 1;
int cnt = 0;
while(cnt < b){
ans[index] = curr;
curr++;
cnt++;
index+=2;
}
for(int i=0;i<n;i++){
if(ans[i] == 0){
ans[i] = curr;
curr++;
}
}
for(int i=0;i<n;i++){
sb.append(ans[i]+" ");
}
sb.append('\n');
}else{
int curr = n;
int ans[] = new int[n];
int index = 1;
int cnt = 0;
while(cnt < b){
ans[index] = curr;
curr--;
cnt++;
index+=2;
}
int val = 1;
for(int i=0;i<n;i++){
if(ans[i] == 0){
ans[i] = val;
val++;
}
}
for(int i=0;i<n;i++){
sb.append(ans[i]+" ");
}
sb.append('\n');
}
}else{
sb.append("-1\n");
}
}
print(sb.toString());
}
public static List<int[]> print_prime_factors(int n){
List<int[]> list = new ArrayList<>();
for(int i=2;i<=(int)(Math.sqrt(n));i++){
if(n % i == 0){
int cnt = 0;
while( (n % i) == 0){
n = n/i;
cnt++;
}
list.add(new int[]{i,cnt});
}
}
if(n!=1){
list.add(new int[]{n,1});
}
return list;
}
public static List<int[]> prime_factors(int n,List<Integer> sieve){
List<int[]> list = new ArrayList<>();
int index = 0;
while(n > 1 && sieve.get(index) <= Math.sqrt(n)){
int curr = sieve.get(index);
int cnt = 0;
while((n % curr) == 0){
n = n/curr;
cnt++;
}
if(cnt >= 1){
list.add(new int[]{curr,cnt});
}
index++;
}
if(n > 1){
list.add(new int[]{n,1});
}
return list;
}
public static boolean inRange(int r1,int r2,int val){
return ((val >= r1) && (val <= r2));
}
static int len(long num){
return Long.toString(num).length();
}
static long mulmod(long a, long b,long mod)
{
long ans = 0l;
while(b > 0){
long curr = (b & 1l);
if(curr == 1l){
ans = ((ans % mod) + a) % mod;
}
a = (a + a) % mod;
b = b >> 1;
}
return ans;
}
public static void dbg(PrintStream ps,Object... o) throws Exception{
if(ps == null){
return;
}
Debug.dbg(ps,o);
}
public static long modpow(long num,long pow,long mod){
long val = num;
long ans = 1l;
while(pow > 0l){
long bit = pow & 1l;
if(bit == 1){
ans = (ans * (val%mod))%mod;
}
val = (val * val) % mod;
pow = pow >> 1;
}
return ans;
}
public static long pow(long num,long pow){
long val = num;
long ans = 1l;
while(pow > 0l){
long bit = pow & 1l;
if(bit == 1){
ans = (ans * (val));
}
val = (val * val);
pow = pow >> 1;
}
return ans;
}
public static char get(int n){
return (char)('a' + n);
}
public static long[] sort(long arr[]){
List<Long> list = new ArrayList<>();
for(long n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
public static int[] sort(int arr[]){
List<Integer> list = new ArrayList<>();
for(int n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
// return the (index + 1)
// where index is the pos of just smaller element
// i.e count of elemets strictly less than num
public static int justSmaller(long arr[],long num){
// System.out.println(num+"@");
int st = 0;
int e = arr.length - 1;
int ans = -1;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] >= num){
e = mid - 1;
}else{
ans = mid;
st = mid + 1;
}
}
return ans + 1;
}
public static int justSmaller(int arr[],int num){
// System.out.println(num+"@");
int st = 0;
int e = arr.length - 1;
int ans = -1;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] >= num){
e = mid - 1;
}else{
ans = mid;
st = mid + 1;
}
}
return ans + 1;
}
//return (index of just greater element)
//count of elements smaller than or equal to num
public static int justGreater(long arr[],long num){
int st = 0;
int e = arr.length - 1;
int ans = arr.length;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] <= num){
st = mid + 1;
}else{
ans = mid;
e = mid - 1;
}
}
return ans;
}
public static int justGreater(int arr[],int num){
int st = 0;
int e = arr.length - 1;
int ans = arr.length;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] <= num){
st = mid + 1;
}else{
ans = mid;
e = mid - 1;
}
}
return ans;
}
public static void println(Object obj){
System.out.println(obj.toString());
}
public static void print(Object obj){
System.out.print(obj.toString());
}
public static int gcd(int a,int b){
if(b == 0){return a;}
return gcd(b,a%b);
}
public static long gcd(long a,long b){
if(b == 0l){
return a;
}
return gcd(b,a%b);
}
public static int find(int parent[],int v){
if(parent[v] == v){
return v;
}
return parent[v] = find(parent, parent[v]);
}
public static List<Integer> sieve(){
List<Integer> prime = new ArrayList<>();
int arr[] = new int[1000001];
Arrays.fill(arr,1);
arr[1] = 0;
arr[2] = 1;
for(int i=2;i<1000001;i++){
if(arr[i] == 1){
prime.add(i);
for(long j = (i*1l*i);j<1000001;j+=i){
arr[(int)j] = 0;
}
}
}
return prime;
}
static boolean isPower(long n,long a){
long log = (long)(Math.log(n)/Math.log(a));
long power = (long)Math.pow(a,log);
if(power == n){return true;}
return false;
}
private static int mergeAndCount(int[] arr, int l,int m, int r)
{
// Left subarray
int[] left = Arrays.copyOfRange(arr, l, m + 1);
// Right subarray
int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
int i = 0, j = 0, k = l, swaps = 0;
while (i < left.length && j < right.length) {
if (left[i] <= right[j])
arr[k++] = left[i++];
else {
arr[k++] = right[j++];
swaps += (m + 1) - (l + i);
}
}
while (i < left.length)
arr[k++] = left[i++];
while (j < right.length)
arr[k++] = right[j++];
return swaps;
}
// Merge sort function
private static int mergeSortAndCount(int[] arr, int l,int r)
{
// Keeps track of the inversion count at a
// particular node of the recursion tree
int count = 0;
if (l < r) {
int m = (l + r) / 2;
// Total inversion count = left subarray count
// + right subarray count + merge count
// Left subarray count
count += mergeSortAndCount(arr, l, m);
// Right subarray count
count += mergeSortAndCount(arr, m + 1, r);
// Merge count
count += mergeAndCount(arr, l, m, r);
}
return count;
}
static class Debug{
//change to System.getProperty("ONLINE_JUDGE")==null; for CodeForces
public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;
private static <T> String ts(T t) {
if(t==null) {
return "null";
}
try {
return ts((Iterable<T>) t);
}catch(ClassCastException e) {
if(t instanceof int[]) {
String s = Arrays.toString((int[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof long[]) {
String s = Arrays.toString((long[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof char[]) {
String s = Arrays.toString((char[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof double[]) {
String s = Arrays.toString((double[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof boolean[]) {
String s = Arrays.toString((boolean[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}
try {
return ts((Object[]) t);
}catch(ClassCastException e1) {
return t.toString();
}
}
}
private static <T> String ts(T[] arr) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: arr) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}");
return ret.toString();
}
private static <T> String ts(Iterable<T> iter) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: iter) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}\n");
return ret.toString();
}
public static void dbg(PrintStream ps,Object... o) throws Exception {
if(LOCAL) {
System.setErr(ps);
System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [\n");
for(int i = 0; i<o.length; i++) {
if(i!=0) {
System.err.print(", ");
}
System.err.print(ts(o[i]));
}
System.err.println("]");
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 0a0ff5ba861f304f7dab10a6f81ab526 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BuildthePermutation {
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
String s = br.readLine();
String s1[] = s.split(" ");
int n = Integer.parseInt(s1[0]);
long a = Long.parseLong(s1[1]);
long b = Long.parseLong(s1[2]);
if(Math.abs(a-b)>1||(a+b)>n-2)
{
System.out.println(-1);
continue;
}
if(a>b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=a;i++)
{
System.out.print(l++ +" ");
System.out.print(r-- +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
else if(a<b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=l;i<=r;i++)System.out.print(i+" ");
System.out.println();
}
else
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 1020b76e3a8fdabcac70f5a2ddc84996 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Codeforces {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int small = 1, big = n, start = 2;
boolean flag = true;
int[] arr = new int[n + 1];
if (a + b + 2 <= n && Math.abs(a - b) <= 1) {
if (a > b) {
while (a > 0) {
if (flag) {
arr[start++] = big--;
a--;
} else {
arr[start++] = small++;
}
flag = !flag;
}
for (int i = 1; i <= n; i++) {
if (arr[i] == 0) {
arr[i] = big--;
}
}
for (int i = 1; i <= n; i++) {
System.out.print(arr[i] + " ");
}
} else if (a < b) {
while (b > 0) {
if (flag) {
arr[start++] = small++;
b--;
} else {
arr[start++] = big--;
}
flag = !flag;
}
for (int i = 1; i <= n; i++) {
if (arr[i] == 0) {
arr[i] = small++;
}
}
for (int i = 1; i <= n; i++) {
System.out.print(arr[i] + " ");
}
} else {
int x = a + b;
while (x-- > 0) {
if (flag) {
arr[start++] = small++;
} else {
arr[start++] = big--;
}
flag = !flag;
}
for (int i = 1; i <= n; i++) {
if (arr[i] == 0) {
arr[i] = big--;
}
}
for (int i = 1; i <= n; i++) {
System.out.print(arr[i] + " ");
}
}
System.out.println();
} else {
System.out.println(-1);
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 8909cd1cefbdcb547656ea5c81acf696 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.*;
public class CF1 {
public static void main(String[] args) {
FastScanner sc=new FastScanner();
int T=sc.nextInt();
for (int tt=0; tt<T; tt++){
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if (b!=a && b!=a-1 && b!=a+1 || a+b+2>n) System.out.println(-1);
else if (a==b || a==b+1){
StringBuilder sb= new StringBuilder();
for (int i=1; i<=n-a-b-2; i++){
sb.append(i+" ");
}
int x=1;
int i=n-a-b-1;
int j=n;
while (i<=j){
if (x%2==1){
sb.append(i+" ");
i++;
x=0;
}
else {
sb.append(j+" ");
j--;
x=1;
}
}
System.out.println(sb.toString());
}
else {
StringBuilder sb= new StringBuilder();
int x=0;
int i=1;
int j=a+b+2;
while (i<=j){
if (x%2==1){
sb.append(i+" ");
i++;
x=0;
}
else {
sb.append(j+" ");
j--;
x=1;
}
}
for (i=a+b+3; i<=n; i++){
sb.append(i+" ");
}
System.out.println(sb.toString());
}
}
}
static long mod =998244353L;
static long power (long a, long b){
long res=1;
while (b>0){
if ((b&1)== 1){
res= (res * a % mod)%mod;
}
a=(a%mod * a%mod)%mod;
b=b>>1;
}
return res;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sortLong(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static int gcd (int n, int m){
if (m==0) return n;
else return gcd(m, n%m);
}
static class Pair{
int x,y;
public Pair(int x, int y){
this.x = x;
this.y = y;
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 9a8f4c4cc2c894d81de7efce2d362437 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Nipuna Samarasekara
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
FastPrinter out = new FastPrinter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, FastScanner in, FastPrinter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int a = in.nextInt(), b = in.nextInt();
int nh = 1;
ArrayList<Integer> ans = new ArrayList<>();
int ns = 1, nl = n;
int fin = 0;
if (a > b) {
ans.add(1);
ns++;
ans.add(n);
nl--;
nh = 0;
fin = 1;
} else {
ans.add(n);
ans.add(1);
ns++;
nl--;
nh = 1;
}
while (ns <= nl) {
if (nh == 0) {
if (a > 0) {
ans.add(ns);
ns++;
nh = 1;
a--;
} else {
break;
}
} else {
if (b > 0) {
ans.add(nl);
nl--;
nh = 0;
b--;
} else {
break;
}
}
}
if (a == 0 && b == 0) {
ans.remove(ans.size() - 1);
if (nh == 0) {
nl++;
for (int i = ns; i <= nl; i++) {
ans.add(i);
}
} else {
ns--;
for (int i = nl; i >= ns; i--) {
ans.add(i);
}
}
for (int i = 0; i < n; i++) {
out.print(ans.get(i) + " ");
}
out.println();
} else {
out.println(-1);
}
}
}
}
static class FastScanner extends BufferedReader {
public FastScanner(InputStream is) {
super(new InputStreamReader(is));
}
public int read() {
try {
int ret = super.read();
// if (isEOF && ret < 0) {
// throw new InputMismatchException();
// }
// isEOF = ret == -1;
return ret;
} catch (IOException e) {
throw new InputMismatchException();
}
}
static boolean isWhiteSpace(int c) {
return c >= 0 && c <= 32;
}
public int nextInt() {
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int ret = 0;
while (c >= 0 && !isWhiteSpace(c)) {
if (c < '0' || c > '9') {
throw new NumberFormatException("digit expected " + (char) c + " found");
}
ret = ret * 10 + c - '0';
c = read();
}
return ret * sgn;
}
public String readLine() {
try {
return super.readLine();
} catch (IOException e) {
return null;
}
}
}
static class FastPrinter extends PrintWriter {
public FastPrinter(OutputStream out) {
super(out);
}
public FastPrinter(Writer out) {
super(out);
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 4462d4107c7a50e5ce86ec8fa91d5248 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class new1{
public static void print(int max, int min, int st, int n) {
int x = 2; int y = n;
if(st == 0) {
x = 1; y = n - 1;
}
//System.out.println(x + " " + y + " ! " + st + " " + n);
for(int i = 1; i < n; i++) {
if(st % 2 == 1 && max > 0) {
System.out.print(y + " ");
y--;
max--;
st++;
}
else if(st % 2 == 1 && max == 0) {
System.out.print(x + " ");
x++;
}
else if(st % 2 == 0 && min > 0) {
System.out.print(x + " ");
x++;
min--;
st++;
}
else if(st % 2 == 0 && min == 0) {
System.out.print(y + " ");
y--;
}
}
}
public static void main(String[] args) throws IOException{
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
FastReader s = new FastReader();
int t = s.nextInt();
for(int z = 0; z < t; z++) {
int n = s.nextInt();
int max = s.nextInt();
int min = s.nextInt();
if(min + max > n - 2) {
System.out.println(-1);
continue;
}
if(Math.abs(max - min) > 1) {
System.out.println(-1);
continue;
}
if(max >= min) {
System.out.print(1 + " ");
print(max, min, 1, n);
}
else {
System.out.print(n + " ");
print(max, min, 0, n);
}
System.out.println();
}
// output.flush();
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 8637d78c6ea010d3ead6633e4fe70730 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[])
{
FastReader input=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int T=input.nextInt();
while(T-->0)
{
int n=input.nextInt();
int a=input.nextInt();
int b=input.nextInt();
if(a+b<=n-2)
{
int d=Math.abs(a-b);
if(d>1)
{
out.println(-1);
}
else
{
int arr[]=new int[n];
if(a==b)
{
int x=n;
for(int i=1;i<n && a>0;i+=2)
{
arr[i]=x;
x--;
a--;
}
x=1;
for(int i=0;i<n;i++)
{
if(arr[i]==0)
{
arr[i]=x;
x++;
}
}
}
else if(a>b)
{
int x=n;
for(int i=1;i<n && a>0;i+=2)
{
arr[i]=x;
x--;
a--;
}
for(int i=0;i<n;i++)
{
if(arr[i]==0)
{
arr[i]=x;
x--;
}
}
}
else
{
int x=1;
for(int i=1;i<n && b>0;i+=2)
{
arr[i]=x;
x++;
b--;
}
// for(int i=0;i<n;i++)
// {
// out.print(arr[i]+" ");
// }
// out.println();
for(int i=0;i<n;i++)
{
if(arr[i]==0)
{
arr[i]=x;
x++;
}
}
}
for(int i=0;i<n;i++)
{
out.print(arr[i]+" ");
}
out.println();
}
}
else
{
out.println(-1);
}
}
out.close();
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | d6740525d2e84ba8450c293fbe33df25 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String []args)
{
int t;
Scanner in=new Scanner(System.in);
t=in.nextInt();
while((t--)!=0)
{
int n;
n=in.nextInt();
int a,b;
a=in.nextInt();
b=in.nextInt();
if(Math.abs(a-b)>1||(a+b)>n-2)
{
System.out.println(-1);
continue;
}
if(a>b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=a;i++)
{
System.out.print(l++ +" ");
System.out.print(r-- +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
else if(a<b)
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=l;i<=r;i++)System.out.print(i+" ");
System.out.println();
}
else
{
int l=1;
int r=n;
int i;
for(i=1;i<=b;i++)
{
System.out.print(r-- +" ");
System.out.print(l++ +" ");
}
for(i=r;i>=l;i--)System.out.print(i+" ");
System.out.println();
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | ba124c066e80bb065298a273176bf011 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
new B().run();
}
BufferedReader br;
PrintWriter out;
long mod = (long) (1e9 + 7), inf = (long) (3e18);
class pair {
int F, S;
pair(int f, int s) {
F = f; S = s;
}
}
void solve() {
int t = ni();
while(t-- > 0) {
//TODO:
int n= ni();
int a= ni();
int b=ni();
int l=1, r=n;
ArrayList<Integer> ans=new ArrayList<>();
if((a+b)>n-2 || Math.abs(a-b)>1){
out.println("-1");
continue;
}
if(a==b){
int h=0;
ans.add(l);
l++;
while(h<a){
ans.add(r);
r--;
ans.add(l);
l++;
h++;
}
for(int i=l; i<=r; i++){
ans.add(i);
}
}
else if(a>b){
int h=0;
ans.add(l);
l++;
while(h<a-1){
ans.add(r);
r--;
ans.add(l);
l++;
h++;
}
for(int i=r; i>=l; i--){
ans.add(i);
}
}
else{
ans.add(r);
r--;
int v=0;
while(v<b-1){
ans.add(l);
l++;
ans.add(r);
r--;
v++;
}
for(int i=l; i<=r; i++){
ans.add(i);
}
}
for(int e: ans){
out.print(e+" ");
}
out.println();
}
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
int[] na(int n) {
int a[] = new int[n];
for(int i = 0; i < n; i++) a[i] = ni();
return a;
}
StringTokenizer ip;
String ns() {
if(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
if(ip == null || !ip.hasMoreTokens())
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void run() {
try {
if (System.getProperty("ONLINE_JUDGE") == null) {
br = new BufferedReader(new FileReader("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt"));
out = new PrintWriter("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt");
} else {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
solve();
out.flush();
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 08c9113ad96acea9d14b03adabf08263 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
////***************************************************************************
/* public class E_Gardener_and_Tree implements Runnable{
public static void main(String[] args) throws Exception {
new Thread(null, new E_Gardener_and_Tree(), "E_Gardener_and_Tree", 1<<28).start();
}
public void run(){
WRITE YOUR CODE HERE!!!!
JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!!
}
}
*/
/////**************************************************************************
public class B_Build_the_Permutation{
public static void main(String[] args) {
FastScanner s= new FastScanner();
//PrintWriter out=new PrintWriter(System.out);
//end of program
//out.println(answer);
//out.close();
StringBuilder res = new StringBuilder();
int t=s.nextInt();
int p=0;
while(p<t){
long n=s.nextLong();
long a=s.nextLong();
long b=s.nextLong();
long sum=a+b;
if(sum>n-2){
res.append("-1 \n");
}
else{
long diff=Math.abs(a-b);
if(diff>1){
res.append("-1 \n");
}
else{
if(diff==1){
if(a>b){
long array[]= new long[(int)n];
long big=a;
long yo=1;
for(int i=0;i<n;i+=2){
if(yo>big){
break;
}
array[i]=yo;
yo++;
}
long yo1=n;
long lim=n-big;
int pos=-1;
for(int i=1;i<n+4;i+=2){
// System.out.println("hh "+yo1);
if(yo1==lim){
pos=i-1;
break;
}
array[i]=yo1;
yo1--;
}
for(long i=yo1;i>=yo;i--){
array[pos]=i;
pos++;
}
for(int i=0;i<n;i++){
res.append(array[i]+" ");
}
res.append(" \n");
}
else{// b>a
long array[]= new long[(int)n];
long big=b;
long yo1=n;
long lim=n-big;
for(int i=0;i<n;i+=2){
if(yo1==lim){
// pos=i-1;
break;
}
array[i]=yo1;
yo1--;
}
long yo=1;
int pos=-1;
for(int i=1;i<n+4;i+=2){
if(yo>big){
pos=i-1;
break;
}
array[i]=yo;
yo++;
}
for(long i=yo;i<=yo1;i++){
array[pos]=i;
pos++;
}
for(int i=0;i<n;i++){
res.append(array[i]+" ");
}
res.append(" \n");
}
}
else{// diff==0
long array[]= new long[(int)n];
long big=a;
long yo=1;
for(int i=0;i<n;i+=2){
if(yo>big){
break;
}
array[i]=yo;
yo++;
}
long yo1=n;
long lim=n-big;
int pos=-1;
for(int i=1;i<n+4;i+=2){
if(yo1==lim){
pos=i-1;
break;
}
array[i]=yo1;
yo1--;
}
for(long i=yo;i<=yo1;i++){
array[pos]=i;
pos++;
}
for(int i=0;i<n;i++){
res.append(array[i]+" ");
}
res.append(" \n");
}
}
}
p++;
}
System.out.println(res);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
static long modpower(long x, long y, long p)
{
long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// SIMPLE POWER FUNCTION=>
static long power(long x, long y)
{
long res = 1; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = res * x;
// y must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
}
return res;
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | fa677b87fe82f1b7d66c1213f9a197a3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int i = 0; i < T; i++) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
if(Math.abs(a-b) > 1 || n - (a+b) < 2){
System.out.println("-1");
continue;
}
if(a == 0 && b == 0) {
for (int j = 1; j <= n; j++) {
System.out.print(j + " ");
}
System.out.println();
continue;
}
boolean up = false;
int top = n;
int bot = 1;
if(a>b) {
System.out.print(bot + " ");
up = true;
bot++;
} else {
System.out.print(top + " ");
top--;
}
boolean bLast = false;
while(top >= bot) {
if(a == 0 && b == 0) {
if(up) {
System.out.print(bot + " ");
bot++;
}else {
System.out.print(top + " ");
top--;
}
}
else if(a > b || (a == b && bLast)) {
System.out.print(top-- + " ");
up = false;
bLast = false;
a--;
}else {
System.out.print(bot++ + " ");
up = true;
bLast = true;
b--;
}
}
System.out.println();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | c4bfedd98e2d7998b7cb09bc627f3c07 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class a {
public static void main(String[] args){
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(a + b > n-2){
System.out.println(-1);
continue;
}
if(Math.abs(a-b) > 1){
System.out.println(-1);
continue;
}
if(a > b){
int ans[] = new int[n];
for(int i=0; i<a; i++){
ans[2*i] = i+1;
}
for(int i=0; i<b; i++){
ans[2*i+1] = n-i;
}
int idx = -1;
for(int i=0; i<ans.length; i++){
if(ans[i] == 0){
idx = i;
break;
}
}
int count = n-b;
for(int i=idx; i<n; i++){
ans[i] = count;
count--;
}
for(int i=0; i<n; i++){
System.out.print(ans[i] + " ");
}
System.out.println();
}
if(a < b){
int ans[] = new int[n];
for(int i=0; i<b; i++){
ans[2*i] = n-i;
}
for(int i=0; i<a; i++){
ans[2*i+1] = i+1;
}
int idx = -1;
for(int i=0; i<ans.length; i++){
if(ans[i] == 0){
idx = i;
break;
}
}
int count = a+1;
for(int i=idx; i<n; i++){
ans[i] = count;
count++;
}
for(int i=0; i<n; i++){
System.out.print(ans[i] + " ");
}
System.out.println();
}
if(a == b){
int ans[] = new int[n];
for(int i=0; i<a; i++){
ans[2*i] = i+1;
}
for(int i=0; i<b; i++){
ans[2*i+1] = n-i;
}
int idx = -1;
for(int i=0; i<ans.length; i++){
if(ans[i] == 0){
idx = i;
break;
}
}
int count = a+1;
for(int i=idx; i<n; i++){
ans[i] = count;
count++;
}
for(int i=0; i<n; i++){
System.out.print(ans[i] + " ");
}
System.out.println();
}
}
}
}
class FastScanner
{
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] nextInts(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = getChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | e06d5bac15ee49f94d64bc910c6fd59a | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
int t;
t = in.nextInt();
//t = 1;
while (t > 0) {
solver.call(in,out);
t--;
}
out.close();
}
static class TaskA {
public void call(InputReader in, PrintWriter out) {
int n, a, b;
n = in.nextInt();
a = in.nextInt();
b = in.nextInt();
if(a + b > n - 2){
out.println(-1);
return;
}
int max = Math.max(a, b);
if(n%2 == 0){
if (max > n / 2 - 1 || Math.abs(a-b) > 1) {
out.println(-1);
return;
}
}
else{
if (max > n / 2|| Math.abs(a-b) > 1) {
out.println(-1);
return;
}
}
if(a+b==0){
for (int i = 1; i <=n ; i++) {
out.print(i+" ");
}
out.println();
return;
}
int i = 1, j = n;
if(a > b){
out.print(1+" ");
i++;
while(a!=0){
out.print(j+" ");
j--;
if(a==1){
break;
}
out.print(i+" ");
i++;
a--;
}
for (int k = j; k >=i; k--) {
out.print(k+" ");
}
out.println();
}
else if(a==b) {
out.print(1 + " ");
i++;
while (a != 0) {
out.print(j + " ");
j--;
out.print(i + " ");
i++;
a--;
}
for (int k = i; k <= j; k++) {
out.print(k+" ");
}
out.println();
}
else{
out.print(n+" ");
j--;
while(b!=0){
out.print(i+" ");
i++;
if(b==1){
break;
}
out.print(j+" ");
j--;
b--;
}
for (int k = i; k <= j; k++) {
out.print(k+" ");
}
out.println();
}
}
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static class answer implements Comparable<answer>{
int a,b;
public answer(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(answer o) {
return o.a - this.a;
}
}
static class arrayListClass {
ArrayList<Integer> arrayList2 ;
public arrayListClass(ArrayList<Integer> arrayList) {
this.arrayList2 = arrayList;
}
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static void sort(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static final Random random=new Random();
static void shuffleSort(int[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 3de5d76decf84af6c7a21cf1e11182b4 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static final PrintWriter out =new PrintWriter(System.out);
static final FastReader sc = new FastReader();
//I invented a new word!Plagiarism!
//Did you hear about the mathematician who’s afraid of negative numbers?He’ll stop at nothing to avoid them
//What do Alexander the Great and Winnie the Pooh have in common? Same middle name.
//I finally decided to sell my vacuum cleaner. All it was doing was gathering dust!
//ArrayList<Integer> a=new ArrayList <Integer>();
//char[] a = s.toCharArray();
public static void main (String[] args) throws java.lang.Exception
{ int tes=sc.nextInt();
while(tes-->0)
{
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int i;
if(a+b>n-2 || Math.abs(a-b)>1)
{
System.out.println("-1");
continue;
}
if(a==b)
{
for(i=0;i<a;i++)
System.out.print((i+1)+" "+(n-i)+" ");
for(i=a+1;i<=n-a;i++)
System.out.print(i+" ");
System.out.println();
continue;
}
if(a>b)
{
for(i=0;i<a;i++)
System.out.print((i+1)+" "+(n-i)+" ");
for(i=n-a;i>=a+1;i--)
System.out.print(i+" ");
System.out.println();
continue;
}
if(b>a)
{
for(i=0;i<b;i++)
System.out.print((n-i)+" "+(i+1)+" ");
for(i=b+1;i<=n-b;i++)
System.out.print(i+" ");
System.out.println();
continue;
}
}
}
public static int lis(int[] arr) {
int n = arr.length;
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(arr[0]);
for(int i = 1 ; i<n;i++) {
int x = al.get(al.size()-1);
if(arr[i]>=x) {
al.add(arr[i]);
}else {
int v = upper_bound(al, 0, al.size(), arr[i]);
al.set(v, arr[i]);
}
}
return al.size();
}
public static long lower_bound(ArrayList<Long> ar,long lo , long hi , long k)
{
long s=lo;
long e=hi;
while (s !=e)
{
long mid = s+e>>1;
if (ar.get((int)mid) <k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}
public static int upper_bound(ArrayList<Integer> ar,int lo , int hi, int k)
{
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get(mid) <=k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static long fact(long N)
{
long mod=1000000007;
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}
private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 17 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 317e8aea13bb4fe0acd32a6258d3d86f | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 0; tc < t; ++tc) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(solve(n, a, b));
}
sc.close();
}
static String solve(int n, int a, int b) {
if (Math.abs(a - b) >= 2 || a + b > n - 2 || Math.min(a, b) > (n - 2) / 2) {
return "-1";
}
int[] result = IntStream.rangeClosed(1, n).toArray();
if (a < b) {
for (int i = 0; i < b; ++i) {
swap(result, i * 2, i * 2 + 1);
}
} else if (a > b) {
for (int i = 0; i < a; ++i) {
swap(result, result.length - 1 - i * 2, result.length - 2 - i * 2);
}
} else {
for (int i = 0; i < a; ++i) {
swap(result, i * 2 + 1, i * 2 + 2);
}
}
return Arrays.stream(result).mapToObj(String::valueOf).collect(Collectors.joining(" "));
}
static void swap(int[] x, int index1, int index2) {
int temp = x[index1];
x[index1] = x[index2];
x[index2] = temp;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 17 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 0d18912c7c489e01e5f392228b7a6fca | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.util.function.*;
import java.io.*;
// you can compare with output.txt and expected out
public class Round758B {
MyPrintWriter out;
MyScanner in;
// final static long FIXED_RANDOM;
// static {
// FIXED_RANDOM = System.currentTimeMillis();
// }
final static String IMPOSSIBLE = "IMPOSSIBLE";
final static String POSSIBLE = "POSSIBLE";
final static String YES = "YES";
final static String NO = "NO";
private void initIO(boolean isFileIO) {
if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) {
try{
in = new MyScanner(new FileInputStream("input.txt"));
out = new MyPrintWriter(new FileOutputStream("output.txt"));
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}
else{
in = new MyScanner(System.in);
out = new MyPrintWriter(new BufferedOutputStream(System.out));
}
}
public static void main(String[] args){
// Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
Round758B sol = new Round758B();
sol.run();
}
private void run() {
boolean isDebug = false;
boolean isFileIO = true;
boolean hasMultipleTests = true;
initIO(isFileIO);
int t = hasMultipleTests? in.nextInt() : 1;
for (int i = 1; i <= t; ++i) {
if(isDebug){
out.printf("Test %d\n", i);
}
getInput();
solve();
printOutput();
}
in.close();
out.close();
}
// use suitable one between matrix(2, n) or matrix(n, 2) for graph edges, pairs, ...
int n, a, b;
void getInput() {
n = in.nextInt();
a = in.nextInt();
b = in.nextInt();
}
void printOutput() {
out.printlnAns(ans);
}
int[] ans;
void solve(){
// p0 > p1 < p2
// p1 < p2 > p3 -> 1 local max
// p1 < p2 < p3 ... > pk -> 1 local max
// so diff of a and b <= 1
// a is # local max
// a <= b: n 1 n-1 2 n-2 > n-3 > ...
// a > b: 1 n 2 n-1 3
if(Math.abs(a-b) > 1 || a + b > n-2) {
ans = new int[] {-1};
return;
}
if(a <= b) {
ans = solve(a, b);
}
else {
ans = solve(b, a);
for(int i=0; i<n; i++)
ans[i] = n+1-ans[i];
}
}
int[] solve(int a, int b) {
int[] ans = new int[n];
int max = n;
int min = 1;
int pos = 0;
ans[pos++] = max--;
boolean isLastMax = true;
// a = b or a + 1 = b
while(b > 0 || a > 0) {
if(pos % 2 == 1) {
ans[pos++] = min++;
isLastMax = false;
b--;
}
else {
ans[pos++] = max--;
isLastMax = true;
a--;
}
}
for(; pos<n; pos++)
ans[pos] = isLastMax? max--: min++;
return ans;
}
static class Pair implements Comparable<Pair>{
final static long FIXED_RANDOM = System.currentTimeMillis();
int first, second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
// http://xorshift.di.unimi.it/splitmix64.c
long x = first;
x <<= 32;
x += second;
x += FIXED_RANDOM;
x += 0x9e3779b97f4a7c15l;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebl;
return (int)(x ^ (x >> 31));
}
@Override
public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
Pair other = (Pair) obj;
return first == other.first && second == other.second;
}
@Override
public String toString() {
return "[" + first + "," + second + "]";
}
@Override
public int compareTo(Pair o) {
int cmp = Integer.compare(first, o.first);
return cmp != 0? cmp: Integer.compare(second, o.second);
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
// 32768?
public MyScanner(InputStream is, int bufferSize) {
br = new BufferedReader(new InputStreamReader(is), bufferSize);
}
public MyScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
// br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[][] nextMatrix(int n, int m) {
return nextMatrix(n, m, 0);
}
int[][] nextMatrix(int n, int m, int offset) {
int[][] mat = new int[n][m];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
mat[i][j] = nextInt()+offset;
}
}
return mat;
}
int[][] nextTransposedMatrix(int n, int m){
return nextTransposedMatrix(n, m, 0);
}
int[][] nextTransposedMatrix(int n, int m, int offset){
int[][] mat = new int[m][n];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
mat[j][i] = nextInt()+offset;
}
}
return mat;
}
int[] nextIntArray(int len) {
return nextIntArray(len, 0);
}
int[] nextIntArray(int len, int offset){
int[] a = new int[len];
for(int j=0; j<len; j++)
a[j] = nextInt()+offset;
return a;
}
long[] nextLongArray(int len) {
return nextLongArray(len, 0);
}
long[] nextLongArray(int len, int offset){
long[] a = new long[len];
for(int j=0; j<len; j++)
a[j] = nextLong()+offset;
return a;
}
String[] nextStringArray(int len) {
String[] s = new String[len];
for(int i=0; i<len; i++)
s[i] = next();
return s;
}
}
public static class MyPrintWriter extends PrintWriter{
public MyPrintWriter(OutputStream os) {
super(os);
}
public void printlnAns(long ans) {
println(ans);
}
public void printlnAns(int ans) {
println(ans);
}
public void printlnAns(boolean ans) {
if(ans)
println(YES);
else
println(NO);
}
public void printAns(long[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(long[] arr){
printAns(arr);
println();
}
public void printAns(int[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(int[] arr){
printAns(arr);
println();
}
public <T> void printAns(ArrayList<T> arr){
if(arr != null && arr.size() > 0){
print(arr.get(0));
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i));
}
}
}
public <T> void printlnAns(ArrayList<T> arr){
printAns(arr);
println();
}
public void printAns(int[] arr, int add){
if(arr != null && arr.length > 0){
print(arr[0]+add);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]+add);
}
}
}
public void printlnAns(int[] arr, int add){
printAns(arr, add);
println();
}
public void printAns(ArrayList<Integer> arr, int add) {
if(arr != null && arr.size() > 0){
print(arr.get(0)+add);
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i)+add);
}
}
}
public void printlnAns(ArrayList<Integer> arr, int add){
printAns(arr, add);
println();
}
public void printlnAnsSplit(long[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public void printlnAnsSplit(int[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public <T> void printlnAnsSplit(ArrayList<T> arr, int split){
if(arr != null && !arr.isEmpty()){
for(int i=0; i<arr.size(); i+=split){
print(arr.get(i));
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr.get(j));
}
println();
}
}
}
}
static private void permutateAndSort(long[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
long temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private void permutateAndSort(int[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
int temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private int[][] constructChildren(int n, int[] parent, int parentRoot){
int[][] childrens = new int[n][];
int[] numChildren = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
numChildren[parent[i]]++;
}
for(int i=0; i<n; i++) {
childrens[i] = new int[numChildren[i]];
}
int[] idx = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
childrens[parent[i]][idx[parent[i]]++] = i;
}
return childrens;
}
static private int[][][] constructDirectedNeighborhood(int n, int[][] e){
int[] inDegree = new int[n];
int[] outDegree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outDegree[u]++;
inDegree[v]++;
}
int[][] inNeighbors = new int[n][];
int[][] outNeighbors = new int[n][];
for(int i=0; i<n; i++) {
inNeighbors[i] = new int[inDegree[i]];
outNeighbors[i] = new int[outDegree[i]];
}
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outNeighbors[u][--outDegree[u]] = v;
inNeighbors[v][--inDegree[v]] = u;
}
return new int[][][] {inNeighbors, outNeighbors};
}
static private int[][] constructNeighborhood(int n, int[][] e) {
int[] degree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
degree[u]++;
degree[v]++;
}
int[][] neighbors = new int[n][];
for(int i=0; i<n; i++)
neighbors[i] = new int[degree[i]];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
neighbors[u][--degree[u]] = v;
neighbors[v][--degree[v]] = u;
}
return neighbors;
}
static private void drawGraph(int[][] e) {
makeDotUndirected(e);
try {
final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot")
.redirectOutput(new File("graph.png"))
.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
static private void makeDotUndirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict graph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "--" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
static private void makeDotDirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict digraph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "->" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 17 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 4e3a3ea451aa59e3939ca4211f77c05a | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
import java.time.*;
import static java.lang.Math.*;
@SuppressWarnings("unused")
public class A {
static boolean DEBUG = false;
static Reader fs;
static PrintWriter pw;
static void solve() {
int n = fs.nextInt(), a = fs.nextInt(), b = fs.nextInt();
/*
* a == b
* l r l r l r r to l
* a > b
* l r l r l r l to r
* b > a
* r l r l r l r to l
*/
if (a + b > n - 2) {
pw.println(-1);
return;
}
ArrayList<Integer>ans = new ArrayList<>();
int l = 1, r = n;
if (a == b + 1) {
int cnt = 0;
while(cnt < a) {
ans.add(l++);
ans.add(r--);
cnt++;
// System.out.println(cnt + " " + l + " " + r);
}
for(int i = r ; i >= l ; i--)ans.add(i);
}
else if (b == a + 1) {
int cnt = 0;
while(cnt < b) {
ans.add(r--);
ans.add(l++);
cnt++;
}
for(int i = l ; i <= r ; i++) {
ans.add(i);
}
}
else if (a == b) {
int cnt =0;
while(cnt < a) {
ans.add(r--);
ans.add(l++);
cnt++;
}
for(int i = r ; i >= l ; i--)ans.add(i);
}
else {
pw.println(-1);
return;
}
for(int x : ans)pw.print(x + " ");pw.println();
}
public static void main(String[] args) throws IOException {
Instant start = Instant.now();
if (args.length == 2) {
System.setIn(new FileInputStream(new File("D:\\program\\javaCPEclipse\\CodeForces\\src\\input.txt")));
// System.setOut(new PrintStream(new File("output.txt")));
System.setErr(new PrintStream(new File("D:\\program\\javaCPEclipse\\CodeForces\\src\\error.txt")));
DEBUG = true;
}
fs = new Reader();
pw = new PrintWriter(System.out);
int t = fs.nextInt();
while (t-- > 0) {
solve();
}
Instant end = Instant.now();
if (DEBUG) {
pw.println(Duration.between(start, end));
}
pw.close();
}
public static void print(long a, long b, long c, PrintWriter pw) {
pw.println(a + " " + b + " " + c);
return;
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
int[][] read2Array(int n, int m) {
int a[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = nextInt();
}
}
return a;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | e7af986d7a07ea0be7126d5ec1a3698b | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.*;
public class Main {
public static void main(String[] args){
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
solve(in, out);
out.close();
}
static String reverse(String s) {
return (new StringBuilder(s)).reverse().toString();
}
static void sieveOfEratosthenes(int n, int factors[], ArrayList<Integer> ar)
{
factors[1]=1;
int p;
for(p = 2; p*p <=n; p++)
{
if(factors[p] == 0)
{
ar.add(p);
factors[p]=p;
for(int i = p*p; i <= n; i += p)
if(factors[i]==0)
factors[i] = p;
}
}
for(;p<=n;p++){
if(factors[p] == 0)
{
factors[p] = p;
ar.add(p);
}
}
}
static void sort(int ar[]) {
int n = ar.length;
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(ar[i]);
Collections.sort(a);
for (int i = 0; i < n; i++)
ar[i] = a.get(i);
}
static void sort1(long ar[]) {
int n = ar.length;
ArrayList<Long> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(ar[i]);
Collections.sort(a);
for (int i = 0; i < n; i++)
ar[i] = a.get(i);
}
static long ncr(long n, long r, long mod) {
if (r == 0)
return 1;
long val = ncr(n - 1, r - 1, mod);
val = (n * val) % mod;
val = (val * modInverse(r, mod)) % mod;
return val;
}
static int findMax(int a[], int n, int vis[], int i, int d){
if(i>=n)
return 0;
if(vis[i]==1)
return findMax(a, n, vis, i+1, d);
int max = 0;
for(int j=i+1;j<n;j++){
if(Math.abs(a[i]-a[j])>d||vis[j]==1)
continue;
vis[j] = 1;
max = Math.max(max, 1 + findMax(a, n, vis, i+1, d));
vis[j] = 0;
}
return max;
}
static void findSub(ArrayList<ArrayList<Integer>> ar, int n, ArrayList<Integer> a, int i){
if(i==n){
ArrayList<Integer> b = new ArrayList<Integer>();
for(int y:a){
b.add(y);
}
ar.add(b);
return;
}
for(int j=0;j<n;j++){
if(j==i)
continue;
a.set(i,j);
findSub(ar, n, a, i+1);
}
}
// *-------------------code starts here--------------------------------------------------*
public static void solve(InputReader sc, PrintWriter pw){
long mod=(long)1e9+7;
int t=sc.nextInt();
// int t=1;
L : while(--t>=0){
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
if(a+b>n-2){
pw.println(-1);
continue;
}
if(Math.abs(a-b)>1){
pw.println(-1);
continue;
}
int arr[]=new int[n+1];
for(int i=1;i<=n;i++){
arr[i]=i;
}
if(a==b){
for(int i=2,k=1;k<=a;k++,i+=2)
swap(arr,i,i+1);
}
else{
for(int i=1,k=1;k<=Math.max(a,b);k++,i+=2)
swap(arr,i,i+1);
if(a==b+1){
for(int i=1;i<=n;i++)
arr[i]=n-arr[i]+1;
}
}
for(int i=1;i<=n;i++){
pw.print(arr[i] +" ");
}
pw.println();
}
}
static void swap(int a[],int i,int j){
int tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}
// *-------------------code ends here-----------------------------------------------------*
static void assignAnc(ArrayList<Integer> ar[],int sz[], int pa[] ,int curr, int par){
sz[curr] = 1;
pa[curr] = par;
for(int v:ar[curr]){
if(par==v)
continue;
assignAnc(ar, sz, pa, v, curr);
sz[curr] += sz[v];
}
}
static int findLCA(int a, int b, int par[][], int depth[]){
if(depth[a]>depth[b]){
a = a^b;
b = a^b;
a = a^b;
}
int diff = depth[b] - depth[a];
for(int i=19;i>=0;i--){
if((diff&(1<<i))>0){
b = par[b][i];
}
}
if(a==b)
return a;
for(int i=19;i>=0;i--){
if(par[b][i]!=par[a][i]){
b = par[b][i];
a = par[a][i];
}
}
return par[a][0];
}
static void formArrayForBinaryLifting(int n, int par[][]){
for(int j=1;j<20;j++){
for(int i=0;i<n;i++){
if(par[i][j-1]==-1)
continue;
par[i][j] = par[par[i][j-1]][j-1];
}
}
}
static long lcm(int a, int b){
return a*b/gcd(a,b);
}
static class Pair1 {
long a;
long b;
Pair1(long a, long b) {
this.a = a;
this.b = b;
}
}
static class Pair implements Comparable<Pair> {
int a;
int b;
// int c;
Pair(int a, int b) {
this.a = a;
this.b = b;
// this.c = c;
}
public int compareTo(Pair p) {
return Integer.compare(a,p.a);
}
}
static boolean isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long fast_pow(long base, long n, long M) {
if (n == 0)
return 1;
if (n == 1)
return base % M;
long halfn = fast_pow(base, n / 2, M);
if (n % 2 == 0)
return (halfn * halfn) % M;
else
return (((halfn * halfn) % M) * base) % M;
}
static long modInverse(long n, long M) {
return fast_pow(n, M - 2, M);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 9992768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 80aa0db554b3221b98cdc4544a4fedcb | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
/**
*
* @author eslam
*/
public class BuildThePermutation {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) throws IOException {
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
FastReader input = new FastReader();
int t = input.nextInt();
for (int i = 0; i < t; i++) {
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
if (a > n / 2 || b > n / 2 || Math.abs(a - b) > 1) {
log.write("-1");
} else if (n - (a + b) < 2) {
log.write("-1");
} else if (a == 1 && b == 0) {
int y = n;
log.write(1 + " " + y + " ");
y--;
while (y > 1) {
log.write(y-- + " ");
}
} else if (b == 1 && a == 0) {
int y = 1;
log.write(n + " " + 1 + " ");
y++;
while (y < n) {
log.write(y++ + " ");
}
} else if (a > b) {
int x = 1;
int y = n;
int l = 1;
// 1 10 2
while (y >= x&&a!=0) {
if (l % 2 == 1) {
log.write(x++ + " ");
} else {
log.write(y-- + " ");
a--;
}
l++;
}
while (y >= x) {
log.write(y-- + " ");
}
} else if (a == b) {
int x = 1;
int y = n;
int l = 1;
while (y >= x) {
if (l % 2 == 1) {
log.write(x++ + " ");
if(a==0){
break;
}
} else {
log.write(y-- + " ");
a--;
}
l++;
}
while (y >= x) {
log.write(x++ + " ");
}
} else {
int x = 1;
int y = n;
int l = 1;
while (y >= x&&b!=0) {
if (l % 2 == 1) {
log.write(y-- + " ");
} else {
log.write(x++ + " ");
b--;
}
l++;
}
while (y >= x) {
log.write(x++ + " ");
}
}
log.write("\n");
}
log.flush();
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f11edcf4aeeff3fe5da0a8085b6752f9 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
public class Main {
// static final File ip = new File("input.txt");
// static final File op = new File("output.txt");
// static {
// try {
// System.setOut(new PrintStream(op));
// System.setIn(new FileInputStream(ip));
// } catch (Exception e) {
// }
// }
public static void main(String[] args) {
FastReader sc = new FastReader();
int test = 1;
test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int left = 1;
int right = n;
// int[] ans = new int[n + 1];
ArrayList<Integer> ans = new ArrayList<>();
if (Math.abs(a - b) > 1 || a+b > n-2)
System.out.println("-1");
else{
if(a == b)
{
int h = 0;
int v = 0;
ans.add(left);
left++;
while(h < a)
{
ans.add(right);
right--;
ans.add(left);
left++;
h++;
}
for(int i=left;i<=right;i++) ans.add(i);
}
else if(a > b)
{
int h = 0;
ans.add(left);
left++;
while(h < a-1)
{
ans.add(right);
right--;
ans.add(left);
left++;
h++;
}
for(int i=right;i>=left;i--) ans.add(i);
}
else
{
int v = 0;
ans.add(right);
right--;
while(v < b-1)
{
ans.add(left);
left++;
ans.add(right);
right--;
v++;
}
for(int i=left;i<=right;i++) ans.add(i);
}
for(int i : ans) System.out.print(i+" ");
System.out.println();
}
}
}
static long power(long x, long y, long p) {
long res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
public static int countSetBits(long number) {
int count = 0;
while (number > 0) {
++count;
number &= number - 1;
}
return count;
}
static int lower_bound(long target, long[] a, int pos) {
if (pos >= a.length)
return -1;
int low = pos, high = a.length - 1;
while (low < high) {
int mid = low + (high - low) / 2;
if (a[mid] < target)
low = mid + 1;
else
high = mid;
}
return a[low] >= target ? low : -1;
}
private static <T> void swap(int[] a, int i, int j) {
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
static class pair {
long a;
long b;
pair(long x, long y) {
this.a = x;
this.b = y;
}
}
static class first implements Comparator<pair> {
public int compare(pair p1, pair p2) {
if (p1.a > p2.a)
return -1;
else if (p1.a < p2.a)
return 1;
return 0;
}
}
static class second implements Comparator<pair> {
public int compare(pair p1, pair p2) {
if (p1.b > p2.b)
return 1;
else if (p1.b < p2.b)
return -1;
return 0;
}
}
private static long getSum(int[] array) {
long sum = 0;
for (int value : array) {
sum += value;
}
return sum;
}
private static boolean isPrime(Long x) {
if (x < 2)
return false;
for (long d = 2; d * d <= x; ++d) {
if (x % d == 0)
return false;
}
return true;
}
static long[] reverse(long a[]) {
int n = a.length;
int i, k;
long t;
for (i = 0; i < n / 2; i++) {
t = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = t;
}
return a;
}
private static boolean isPrimeInt(int x) {
if (x < 2)
return false;
for (int d = 2; d * d <= x; ++d) {
if (x % d == 0)
return false;
}
return true;
}
public static String reverse(String input) {
StringBuilder str = new StringBuilder("");
for (int i = input.length() - 1; i >= 0; i--) {
str.append(input.charAt(i));
}
return str.toString();
}
private static int[] getPrimes(int n) {
boolean[] used = new boolean[n + 1];
used[0] = used[1] = true;
// int size = 0;
for (int i = 2; i <= n; ++i) {
if (!used[i]) {
// ++size;
for (int j = 2 * i; j <= n; j += i) {
used[j] = true;
}
}
}
int[] primes = new int[n + 1];
for (int i = 0; i <= n; ++i) {
if (!used[i]) {
primes[i] = 1;
}
}
return primes;
}
private static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
private static long gcd(long a, long b) {
return (a == 0 ? b : gcd(b % a, a));
}
static void sortI(int[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
Arrays.sort(arr);
}
static void shuffleList(ArrayList<Long> arr) {
int n = arr.size();
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = arr.get(i);
int randomPos = i + rnd.nextInt(n - i);
arr.set(i, arr.get(randomPos));
arr.set(randomPos, tmp);
}
}
static void factorize(long n) {
int count = 0;
while (!(n % 2 > 0)) {
n >>= 1;
count++;
}
if (count > 0) {
// System.out.println("2" + " " + count);
}
long i = 0;
for (i = 3; i <= (long) Math.sqrt(n); i += 2) {
count = 0;
while (n % i == 0) {
count++;
n = n / i;
}
if (count > 0) {
// System.out.println(i + " " + count);
}
}
if (n > 2) {
// System.out.println(i + " " + count);
}
}
static void sortL(long[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
Arrays.sort(arr);
}
////////////////////////////////// DSU START ///////////////////////////
static class DSU {
int[] parent, rank, total_Elements;
DSU(int n) {
parent = new int[n + 1];
rank = new int[n + 1];
total_Elements = new int[n + 1];
for (int i = 0; i <= n; i++) {
parent[i] = i;
rank[i] = 1;
total_Elements[i] = 1;
}
}
int find(int u) {
if (parent[u] == u)
return u;
return parent[u] = find(parent[u]);
}
void unionByRank(int u, int v) {
int pu = find(u);
int pv = find(v);
if (pu != pv) {
if (rank[pu] > rank[pv]) {
parent[pv] = pu;
total_Elements[pu] += total_Elements[pv];
} else if (rank[pu] < rank[pv]) {
parent[pu] = pv;
total_Elements[pv] += total_Elements[pu];
} else {
parent[pu] = pv;
total_Elements[pv] += total_Elements[pu];
rank[pv]++;
}
}
}
boolean unionBySize(int u, int v) {
u = find(u);
v = find(v);
if (u != v) {
parent[u] = v;
total_Elements[v] += total_Elements[u];
total_Elements[u] = 0;
return true;
}
return false;
}
}
////////////////////////////////// DSU END /////////////////////////////
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public boolean hasNext() {
return false;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | ff7205330bfea877a8d905eff4726119 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.lang.*;
import java.util.*;
public class ComdeFormces {
public static int cc2;
public static pair pr;
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
// Reader.init(System.in);
FastReader sc=new FastReader();
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
// OutputStream out = new BufferedOutputStream ( System.out );
int t=sc.nextInt();
while(t--!=0) {
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int mx=Math.max(a,b);
int mn=Math.min(a, b);
if(Math.abs(a-b)<=1 && ((n%2!=0 && mx<=(n-1)/2 && mn<=((n-1)/2)-1) || (n%2==0 && a<=(n-1)/2 && b<=(n-1)/2))){
int x[]=new int[n];
for(int i=1;i<=n;i++)x[i-1]=i;
if(a>=b) {
if(a==b && a>0) {
int temp=x[0];
x[0]=x[1];
x[1]=temp;
}
for(int i=n-1;i>=0 && a>0;i-=2) {
int temp=x[i];
x[i]=x[i-1];
x[i-1]=temp;
a--;
}
}
else {
for(int i=0;i<n && b>0;i+=2) {
int temp=x[i];
x[i]=x[i+1];
x[i+1]=temp;
b--;
}
}
for(int i=0;i<n;i++)log.write(x[i]+" ");
log.write("\n");
}
else log.write("-1\n");
log.flush();
}
}
public static void shr(int a[][]) {
for(int i=0;i<a.length;i++) {
for(int j=0;j<a[0].length;j++) {
a[i][(j+1)%a.length]=a[i][j];
}
}
}
public static void shl(int a[][]) {
for(int i=0;i<a.length;i++) {
for(int j=a[0].length-1;j>=0;j--) {
a[i][(j-1+a.length)%a.length]=a[i][j];
}
}
}
public static void shu(int a[][]) {
for(int i=0;i<a.length;i++) {
for(int j=0;j<a[0].length;j++) {
a[(i+1)%a.length][j]=a[i][j];
}
}
}
public static void shd(int a[][]) {
for(int i=0;i<a.length;i++) {
for(int j=0;j<a[0].length;j++) {
a[(i-1+a.length)%a.length][j]=a[i][j];
}
}
}
public static void radixSort(int a[]) {
int n=a.length;
int res[]=new int[n];
int p=1;
for(int i=0;i<=8;i++) {
int cnt[]=new int[10];
for(int j=0;j<n;j++) {
a[j]=res[j];
cnt[(a[j]/p)%10]++;
}
for(int j=1;j<=9;j++) {
cnt[j]+=cnt[j-1];
}
for(int j=n-1;j>=0;j--) {
res[cnt[(a[j]/p)%10]-1]=a[j];
cnt[(a[j]/p)%10]--;
}
p*=10;
}
}
static int bits(long n) {
int ans=0;
while(n!=0) {
if((n&1)==1)ans++;
n>>=1;
}
return ans;
}
static long flor(ArrayList<Long> ar,long el) {
int s=0;
int e=ar.size()-1;
while(s<=e) {
int m=s+(e-s)/2;
if(ar.get(m)==el)return ar.get(m);
else if(ar.get(m)<el)s=m+1;
else e=m-1;
}
return e>=0?e:-1;
}
public static int kadane(int a[]) {
int sum=0,mx=Integer.MIN_VALUE;
for(int i=0;i<a.length;i++) {
sum+=a[i];
mx=Math.max(mx, sum);
if(sum<0) sum=0;
}
return mx;
}
public static int m=1000000007;
public static int mul(int a, int b) {
return ((a%m)*(b%m))%m;
}
public static long mul(long a, long b) {
return ((a%m)*(b%m))%m;
}
public static int add(int a, int b) {
return ((a%m)+(b%m))%m;
}
public static long add(long a, long b) {
return ((a%m)+(b%m))%m;
}
//debug
public static <E> void p(E[][] a,String s) {
System.out.println(s);
for(int i=0;i<a.length;i++) {
for(int j=0;j<a[0].length;j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
public static void p(int[] a,String s) {
System.out.print(s+"=");
for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
System.out.println();
}
public static void p(long[] a,String s) {
System.out.print(s+"=");
for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
System.out.println();
}
public static <E> void p(E a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(ArrayList<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(LinkedList<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(HashSet<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(Stack<E> a,String s){
System.out.println(s+"="+a);
}
public static <E> void p(Queue<E> a,String s){
System.out.println(s+"="+a);
}
//utils
static ArrayList<Integer> divisors(int n){
ArrayList<Integer> ar=new ArrayList<>();
for (int i=2; i<=Math.sqrt(n); i++){
if (n%i == 0){
if (n/i == i) {
ar.add(i);
}
else {
ar.add(i);
ar.add(n/i);
}
}
}
return ar;
}
static int primeDivisor(int n){
ArrayList<Integer> ar=new ArrayList<>();
int cnt=0;
boolean pr=false;
while(n%2==0) {
pr=true;
n/=2;
}
if(pr)ar.add(2);
for(int i=3;i*i<=n;i+=2) {
pr=false;
while(n%i==0) {
n/=i;
pr=true;
}
if(pr)ar.add(i);
}
if(n>2) ar.add(n);
return ar.size();
}
static long gcd(long a,long b) {
if(b==0)return a;
else return gcd(b,a%b);
}
static int gcd(int a,int b) {
if(b==0)return a;
else return gcd(b,a%b);
}
static long factmod(long n,long mod,long img) {
if(n==0)return 1;
long ans=1;
long temp=1;
while(n--!=0) {
if(temp!=img) {
ans=((ans%mod)*((temp)%mod))%mod;
}
temp++;
}
return ans%mod;
}
static int ncr(int n, int r){
if(r>n-r)r=n-r;
int ans=1;
for(int i=0;i<r;i++){
ans*=(n-i);
ans/=(i+1);
}
return ans;
}
public static class trip{
int a,b;
int c;
public trip(int a,int b,int c) {
this.a=a;
this.b=b;
this.c=c;
}
public int compareTo(trip q) {
return this.b-q.b;
}
}
static void mergesort(long[] a,int start,int end) {
if(start>=end)return ;
int mid=start+(end-start)/2;
mergesort(a,start,mid);
mergesort(a,mid+1,end);
merge(a,start,mid,end);
}
static void merge(long[] a, int start,int mid,int end) {
int ptr1=start;
int ptr2=mid+1;
long b[]=new long[end-start+1];
int i=0;
while(ptr1<=mid && ptr2<=end) {
if(a[ptr1]<=a[ptr2]) {
b[i]=a[ptr1];
ptr1++;
i++;
}
else {
b[i]=a[ptr2];
ptr2++;
i++;
}
}
while(ptr1<=mid) {
b[i]=a[ptr1];
ptr1++;
i++;
}
while(ptr2<=end) {
b[i]=a[ptr2];
ptr2++;
i++;
}
for(int j=start;j<=end;j++) {
a[j]=b[j-start];
}
}
public static class FastReader {
BufferedReader b;
StringTokenizer s;
public FastReader() {
b=new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(s==null ||!s.hasMoreElements()) {
try {
s=new StringTokenizer(b.readLine());
}
catch(IOException e) {
e.printStackTrace();
}
}
return s.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str="";
try {
str=b.readLine();
}
catch(IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
if (s != null && s.hasMoreTokens()) {
return true;
}
String tmp;
try {
b.mark(1000);
tmp = b.readLine();
if (tmp == null) {
return false;
}
b.reset();
} catch (IOException e) {
return false;
}
return true;
}
}
public static class pair{
int a;
int b;
public pair(int a,int b) {
this.a=a;
this.b=b;
}
public int compareTo(pair b) {
return this.a-b.a;
}
// public int compareToo(pair b) {
// return this.b-b.b;
// }
@Override
public String toString() {
return "{"+this.a+" "+this.b+"}";
}
}
static long pow(long a, long pw) {
long temp;
if(pw==0)return 1;
temp=pow(a,pw/2);
if(pw%2==0)return temp*temp;
return a*temp*temp;
}
static int pow(int a, int pw) {
int temp;
if(pw==0)return 1;
temp=pow(a,pw/2);
if(pw%2==0)return temp*temp;
return a*temp*temp;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 49c245b0de1fade1a7f0ef70289f9edd | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class ComdeFormces {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
FastReader sc=new FastReader();
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
int t=sc.nextInt();
while(t--!=0) {
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int arr[]=new int[n];
for(int i=1;i<=n;i++) {
arr[i-1]=i;
}
if(a>b) {
for(int i=n-2;i>=0;i-=2) {
if(a==0 && b==0)break;
int temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
if(i+2<n && i-1>=0) {
a--;
b--;
}
else if(i==n-2){
if(arr[i]<arr[i+1] && i-1>=0 && arr[i]<arr[i-1])b--;
else if(arr[i]>arr[i+1] && i-1>=0 && arr[i]>arr[i-1])a--;
}
else if(i==0) {
if(arr[i+1]<arr[i] && i+2<n && arr[i+1]<arr[i+2])b--;
else if(arr[i+1]>arr[i] && i+2<n && arr[i+1]>arr[i+2])a--;
}
}
}
else {
int s=1;
if(a==b)s=2;
for(int i=s;i<n;i+=2) {
if(a==0 && b==0)break;
int temp=arr[i];
arr[i]=arr[i-1];
arr[i-1]=temp;
if(i-2>=0 && i+1<n) {
a--;
b--;
}
else if(i==n-1) {
if(arr[i-1]>arr[i] && i-2>=0 && arr[i-1]>arr[i-2])a--;
else if(arr[i-1]<arr[i] && i-2>=0 && arr[i-1]<arr[i-2])b--;
}
else if(i==1) {
if(arr[i]>arr[i-1] && i+1<n && arr[i]>arr[i+1])a--;
else if(arr[i]<arr[i-1] && i+1<n && arr[i]<arr[i+1])b--;
}
}
}
if(a==0 && b==0) {
for(int i=0;i<n;i++) {
log.write(arr[i]+" ");
}
}
else log.write("-1");
log.write("\n");
log.flush();
}
}
static long bs(long end ,long cnt,long prev,long n) {
long start=1;
long st=end;
while(start<=end) {
long mid=start+(end-start)/2;
if(mid*cnt+prev==n)return mid;
else if(mid*cnt+prev>n)end=mid-1;
else start=mid+1;
}
if(start<=st && start*cnt+prev>=n)return start;
return -1;
}
//utils
static void mergesort(long[] a,int start,int end) {
if(start>=end)return;
int mid=start+(end-start)/2;
mergesort(a,start,mid);
mergesort(a,mid+1,end);
merge(a,start,mid,end);
}
static void merge(long []a, int start,int mid,int end) {
int ptr1=start;
int ptr2=mid+1;
long b[]=new long[end-start+1];
int i=0;
while(ptr1<=mid && ptr2<=end) {
if(a[ptr1]<=a[ptr2]) {
b[i]=a[ptr1];
ptr1++;
i++;
}
else {
b[i]=a[ptr2];
ptr2++;
i++;
}
}
while(ptr1<=mid) {
b[i]=a[ptr1];
ptr1++;
i++;
}
while(ptr2<=end) {
b[i]=a[ptr2];
ptr2++;
i++;
}
for(int j=start;j<=end;j++) {
a[j]=b[j-start];
}
}
public static class FastReader {
BufferedReader b;
StringTokenizer s;
public FastReader() {
b=new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(s==null ||!s.hasMoreElements()) {
try {
s=new StringTokenizer(b.readLine());
}
catch(IOException e) {
e.printStackTrace();
}
}
return s.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str="";
try {
str=b.readLine();
}
catch(IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
if (s != null && s.hasMoreTokens()) {
return true;
}
String tmp;
try {
b.mark(1000);
tmp = b.readLine();
if (tmp == null) {
return false;
}
b.reset();
} catch (IOException e) {
return false;
}
return true;
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 29238a8cfee759fef3ac6c80e88deb00 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class abhishek {
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 3
// 2
// 3
// 1
// 7
// 1
// 5
// 3
// 8
// 0,7,6,5,4
// _ _
// 0---->1048575 100000
public static void solve(int a,int b,int n)
{
System.out.print(1+" ");
if(n==1)return;
int i=0;
for( i=2;i<n;i+=2)
{ if(a==0)break;
System.out.print(i+1+" "+i+" ");
a--;
}
for(int j=i;j<n;j++)System.out.print(j+" ");
System.out.print(n+" ");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
// if(a>b)
// {
// if((a+b-1)>(n-4))
// {
// System.out.println(-1);
// continue;
// }
// }
int diff=(int)Math.abs(a-b);
if(diff>1 || (a+b)>(n-2))
{
System.out.println(-1);
}
else
{
if(a==b)
{
System.out.print(1+" ");
int i=0;
for( i=2;i<n;i+=2)
{ if(a==0)break;
System.out.print(i+1+" "+i+" ");
a--;
}
for(int j=i;j<n;j++)System.out.print(j+" ");
System.out.println(n);
}else
{
if(a>b)
{
int i=1;
int j=n;
while(a-->0)
{
System.out.print(i+" "+j+" ");
i++;
j--;
}
//i--;
//j++;
for(int k=j;k>=i;k--)
{
System.out.print(k+" ");
}
System.out.println();
}else
{ int i=b;
int j=b+1;
while(i!=0)
{
System.out.print(j+" "+i+" ");
i--;
j++;
}
//j--;
for(int k=j;k<=n;k++)
{
System.out.print(k+" ");
}
System.out.println();}
}
}}}} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | c7c25bec51f3699c675c6102f0d18fb0 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class buildthepermutation{
public static void main(String ...asada){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int []c=new int[n];
for(int i=0;i<n;i++)
c[i]=i+1;
if(Math.abs(a-b)>1 || a+b+2>n){
System.out.println(-1);
continue;
}
if(a==1 && b==0){
int temp=c[n-1];
c[n-1]=c[n-2];
c[n-2]=temp;for(int i=0;i<n;i++)
System.out.print(c[i]+" ");
System.out.println();continue;
}
if(a==0 && b==1){
int temp=c[0];
c[0]=c[1];c[1]=temp;for(int i=0;i<n;i++)
System.out.print(c[i]+" ");
System.out.println();continue;
}
else if((a-b)==0){
for(int i=1;i<n-1 && b>0;i+=2,b--){
int cd=c[i+1];
c[i+1]=c[i];
c[i]=cd;
}
}
else if(b-a==1){
int temp=c[0];
c[0]=c[1];c[1]=temp;
for(int i=2;i<n-1 && a>0;i+=2,a--){
int cd=c[i+1];
c[i+1]=c[i];
c[i]=cd;
}
}
else{
for(int i=1;i<n-1 && b>0;i+=2,b--){
int cd=c[i+1];
c[i+1]=c[i];
c[i]=cd;
}
int temp=c[n-1];
c[n-1]=c[n-2];
c[n-2]=temp;
}
// else{
// if(a>=b){
// int i=1,j=n;
// while(a-->0){
// System.out.print(i+" ");
// System.out.print(j+" ");i++;j--;b--;
// }
// i--;
// while((i++)<j)
// System.out.print(i+" ");
// }
// else if(b>=a){
// int i=n,j=1;
// while(b-->0){
// System.out.print(i+" ");
// System.out.print(j+" ");i--;j++;
// }
// j--;
// while((j++)<i)
// System.out.print(j+" ");
// }
// System.out.println();
for(int i=0;i<n;i++)
System.out.print(c[i]+" ");
System.out.println();
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 031d1fa51115d8ad74e3d224925d6774 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class minMax {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(a==0&&b==0){
for (int i = 1; i <= n; i++) {
out.print(i + " ");
}
}else if(a==b){
if (a + b <= n - 2) {
for (long i = 1; i <= (a + b + 2) / 2; i++) {
out.print(i + " " + (((a + b + 2) / 2) + i) + " ");
}
for (long i = (a + b + 3); i <= n; i++) {
out.print(i + " ");
}
}else{
out.print(-1);
}
} else if (a>b) {
int tmp=n-(a+b+2);
if (b + 1 == a && a + b + 2 <= n) {
for(long m=1;m<=tmp; m++)
out.print(m+" ");
for(long m=0; m<a;m++)
out.print((tmp+m+1)+" "+(n-a+1+m)+" ");
out.print(n-a);
}else
out.print(-1);
}else if (b>a) {
if (a+1==b &&a+b+2<=n){
for(int i=1;i<=n;i++){
if (b > 0) {
out.print(i+1 + " " + i + " ");
i++;
b--;
}else
out.print(i+" ");
}
} else
out.print(-1);
}
out.println();
}
out.close();
}static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public boolean hasNext() {
return st.hasMoreTokens();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | df1409aeb38b2f9883f81fafd644a043 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.Stack;
import java.util.StringTokenizer;
public class minMax {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(a==0&&b==0){
for (int i = 1; i <= n; i++) {
out.print(i + " ");
}
}else if(a==b){
if (a + b <= n - 2) {
for (long i = 1; i <= (a + b + 2) / 2; i++) {
out.print(i + " " + (((a + b + 2) / 2) + i) + " ");
}
for (long i = (a + b + 3); i <= n; i++) {
out.print(i + " ");
}
}else{
out.print(-1);
}
} else if (a>b) {
int tmp=n-(a+b+2);
if (b + 1 == a && a + b + 2 <= n) {
for(long m=1;m<=tmp; m++)
out.print(m+" ");
for(long m=0; m<a;m++)
out.print((tmp+m+1)+" "+(n-a+1+m)+" ");
out.print(n-a);
}else
out.print(-1);
}else if (b > a) {
long tmp = 0;
Stack<Integer> st = new Stack<>();
for (int i = 0; i < n; i++) {
st.add(n - i);
}
if (a+1==b &&a+b+2<=n){
while (!st.empty()) {
if (b > 0) {
tmp = st.pop();
out.print(st.pop() + " " + tmp + " ");
b--;
}else
out.print(st.pop()+" ");
}
} else
out.print(-1);
}
out.println();
}
out.close();
}static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public boolean hasNext() {
return st.hasMoreTokens();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 57401892fc5e308b5b76484c4d7e2b92 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | /******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(n==1 && a==0 && b==0)
System.out.println(1);
else if(a - b > 1)
System.out.println(-1);
else if(b - a > 1)
System.out.println(-1);
else if(a + b > n-2)
System.out.println(-1);
else{
int arr[] = new int[n];
for(int i = 0;i<n;i++)
arr[i] = -999;
if(a == b)
{
int j = n;
int count = 0;
for(int i = 1; i<n && count < a;i=i+2)
{
arr[i] = j;
j--;
count++;
}
int z = 1;
for(int i = 0;i<n && z<=j;i++)
{
if(arr[i] == -999)
{
arr[i] = z;
z++;
}
}
}
else if(a > b)
{
int j = n;
int count = 0;
for(int i = 1; i<n && count < a;i=i+2)
{
arr[i] = j;
j--;
count++;
}
for(int i = 0;i<n;i++)
{
if(arr[i] == -999)
{
arr[i] = j;
j--;
}
}
}
else
{
int j = 1;
int count = 0;
for(int i = 1;i<n && count < b;i=i+2)
{
arr[i] = j;
j++;
count++;
}
for(int i = 0;i<n;i++)
{
if(arr[i] == -999)
{
arr[i] = j;
j++;
}
}
}
for(int i = 0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 86182749e19c4a9ded5f602e0bf67617 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static long mod = (int)1e9+7;
// static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc =new FastReader();
int t=sc.nextInt();
// int t=1;
while(t-->0)
{
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++)
{
arr[i] = i + 1;
}
if(n%2==0)
{
int req = n - 2;
int maxi = req/2;
int mini = req/2;
if(a + b > n -2 || Math.abs(a - b) > 1)
{
System.out.println(-1);
}
else
{
int count_a = 0 , count_b = 0;
if(a == b)
{
for(int i=1;i<n-1;i+=2)
{
if(count_a < a && count_b < b)
{
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
count_a++;
count_b++;
}
else
{
break;
}
}
}
else if(a > b)
{
for(int i=n-1;i>0;i-=2)
{
int temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
count_a++;
if(count_a >= a)
{
break;
}
}
}
else
{
for(int i=0;i<n-1;i+=2)
{
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
count_b++;
if(count_b >= b)
{
break;
}
}
}
for(int x:arr)
{
System.out.print(x+" ");
}
System.out.println();
}
}
else
{
int req = n - 2;
int maxi = n/2;
int mini = n/2;
if(a + b > n - 2 || Math.abs(a - b) > 1)
{
System.out.println(-1);
}
else
{
int count_a = 0 , count_b = 0;
if(a > b)
{
for(int i=n-1;i>0;i-=2)
{
int temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
count_a++;
if(count_a >= a)
{
break;
}
}
}
else if(a < b)
{
for(int i=0;i<n-1;i+=2)
{
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
count_b++;
if(count_b >= b)
{
break;
}
}
}
else
{
for(int i=1;i<n-1;i+=2)
{
if(count_a < a && count_b < b)
{
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
count_a++;
count_b++;
}
else
{
break;
}
}
}
for(int x:arr)
{
System.out.print(x+" ");
}
System.out.println();
}
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
static void reverse_sorted(int[] arr)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<arr.length;i++)
{
list.add(arr[i]);
}
Collections.sort(list , Collections.reverseOrder());
for(int i=0;i<arr.length;i++)
{
arr[i] = list.get(i);
}
}
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value
int l=-1,r=list.size();
while(l+1<r) {
int m=(l+r)>>>1;
if(list.get(m)<=x) l=m;
else r=m;
}
return l+1;
}
public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
// put data from sorted list to hashmap
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static class Queue_Pair implements Comparable<Queue_Pair> {
int first , second;
public Queue_Pair(int first, int second) {
this.first=first;
this.second=second;
}
public int compareTo(Queue_Pair o) {
return Integer.compare(o.first, first);
}
}
static void leftRotate(int arr[], int d, int n)
{
for (int i = 0; i < d; i++)
leftRotatebyOne(arr, n);
}
static void leftRotatebyOne(int arr[], int n)
{
int i, temp;
temp = arr[0];
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[n-1] = temp;
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(char arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
public static void reverse_Long(long[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
long temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static long getSum(long n)
{
long sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
if (b == 0)
return a;
return gcdLong(b, a % b);
}
static void swap(int i, int j)
{
int temp = i;
i = j;
j = temp;
}
static int countDigit(int n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
}
class Pair
{
int first;
int second;
Pair(int first , int second)
{
this.first = first;
this.second = second;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | a7f41a2f78d8a932ec46894b4bd84d63 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
// Working program with FastReader
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.lang.*;
public class B_Build_the_Permutation {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int max = sc.nextInt();
int min = sc.nextInt();
// int mid=n/2;
if((min+max)<=(n-2) && Math.abs(min-max)<=1){
int arr[]=new int[n];
int mc=0,Mc=0;
for(int i=0;i<n;i++) arr[i]=i+1;
if((min-max)==0){
for(int i=1;i+1<n;i=i+2){
if(mc==min && Mc==max) break;
int temp=arr[i+1];
arr[i+1]=arr[i];
arr[i]=temp;
if(i==0){
++mc;
}
else {
++mc;
++Mc;
}
}
}
if((min-max)==1){
for(int i=0;(i+2)<n;i=i+2){
if(mc==min && Mc==max) break;
int temp=arr[i+1];
arr[i+1]=arr[i];
arr[i]=temp;
if(i==0){
++mc;
}
else {
++mc;
++Mc;
}
}
}
if(max-min==1){
for(int i=n-1;(i-1)>=0;i=i-2){
if(mc==min && Mc==max) break;
int temp=arr[i];
arr[i]=arr[i-1];
arr[i-1]=temp;
if(i==(n-1)){
++Mc;
}else{
++mc;
++Mc;
}
}
}
for(int i:arr) System.out.print(i+" ");
System.out.println();
}else{
System.out.println(-1);
}
}
}
}
/**
0 1 2 3
1 2 3 4 => 0,0
2 1 3 4 => 1,0
2 1 4 3 => 1,1
*/ | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | cce30ddc1e97e87768089bdec237a120 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import java.math.*;
//
public class Main{
public static void main(String[] args) {
TaskA solver = new TaskA();
// boolean[]prime=seive(3*100001);
int t = in.nextInt();
for (int i = 1; i <= t ; i++) {
solver.solve(1, in, out);
}
// solver.solve(1, in, out);
out.flush();
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n= in.nextInt();int a= in.nextInt();int b=in.nextInt();
if(a+b+2>n||Math.abs(a-b)>1) {
System.out.println (-1);return;
}
int []ans=new int[n];
if(a>b) {
for(int i=0;i<a;i++) {
ans[2*i+1]=n-i;ans[2*i]=i+1;
}
for(int i=2*a;i<n;i++) {
ans[i]=ans[i-1]-1;
}
}
else if(a==b) {
for(int i=0;i<a;i++) {
ans[2*i+1]=n-i;ans[2*i]=i+1;
}
int x=a+1;
for(int i=2*a;i<n;i++) {
ans[i]=x;x++;
}
}
else {
for(int i=0;i<b;i++) {
ans[2*i+1]=i+1;
}
int x=b+1;
for(int i=0;i<n;i++) {
if(ans[i]==0) {
ans[i]=x;x++;
}
}
}
printIArray(ans);
}
}
private static void printIArray(int[] arr) {
for (int i = 0; i < arr.length; i++)
System .out.print(arr[i] + " ");
System.out.println(" ");
}
static int dis(int a,int b,int c,int d) {
return Math.abs(c-a)+Math.abs(d-b);
}
static long ceil(long a,long b) {
return (a/b + Math.min(a%b, 1));
}
static char[] rev(char[]ans,int n) {
for(int i=ans.length-1;i>=n;i--) {
ans[i]=ans[ans.length-i-1];
}
return ans;
}
static int countStep(int[]arr,long sum,int k,int count1) {
int count=count1;
int index=arr.length-1;
while(sum>k&&index>0) {
sum-=(arr[index]-arr[0]);
count++;
if(sum<=k) {
break;
}
index--;
// println("c");
}
if(sum<=k) {
return count;
}
else {
return Integer.MAX_VALUE;
}
}
static long pow(long b, long e) {
long ans = 1;
while (e > 0) {
if (e % 2 == 1)
ans = ans * b % mod;
e >>= 1;
b = b * b % mod;
}
return ans;
}
static void sortDiff(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return (p1.second-p1.first)-(p2.second-p1.first);
}
return (p1.second-p1.first)-(p2.second-p2.first);
}
});
}
static void sortF(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return p1.second-p2.second;
}
return p1.first - p2.first;
}
});
}
static int[] shift (int[]inp,int i,int j){
int[]arr=new int[j-i+1];
int n=j-i+1;
for(int k=i;k<=j;k++) {
arr[(k-i+1)%n]=inp[k];
}
for(int k=0;k<n;k++ ) {
inp[k+i]=arr[k];
}
return inp;
}
static long[] fac;
static long mod = (long) 1000000007;
static void initFac(long n) {
fac = new long[(int)n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (fac[i - 1] * i) % mod;
}
}
static long nck(int n, int k) {
if (n < k)
return 0;
long den = inv((int) (fac[k] * fac[n - k] % mod));
return fac[n] * den % mod;
}
static long inv(long x) {
return pow(x, mod - 2);
}
static void sort(int[] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static void sort(long[] a) {
ArrayList<Long> q = new ArrayList<>();
for (long i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) {
Queue<Integer>q=new LinkedList<>();
q.add(source);
visited[source]=true;
int distance=0;
while(!q.isEmpty()) {
int curr=q.poll();
distance++;
for(int neighbour:a[curr]) {
if(!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
}
}
}
return distance;
}
public static Set<Integer>factors(int n){
Set<Integer>ans=new HashSet<>();
ans.add(1);
for(int i=2;i*i<=n;i++) {
if(n%i==0) {
ans.add(i);
ans.add(n/i);
}
}
return ans;
}
public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) {
boolean[]visited=new boolean[a.length];
int[]parent=new int[a.length];
Queue<Integer>q=new LinkedList<>();
int distance=0;
q.add(source);
visited[source]=true;
parent[source]=-1;
while(!q.isEmpty()) {
int curr=q.poll();
if(curr==destination) {
break;
}
for(int neighbour:a[curr]) {
if(neighbour!=-1&&!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
parent[neighbour]=curr;
}
}
}
int cur=destination;
while(parent[cur]!=-1) {
distance++;
cur=parent[cur];
}
return distance;
}
static int bs(int size,int[]arr) {
int x = -1;
for (int b = size/2; b >= 1; b /= 2) {
while (!ok(arr));
}
int k = x+1;
return k;
}
static boolean ok(int[]x) {
return false;
}
public static int solve1(ArrayList<Integer> A) {
long[]arr =new long[A.size()+1];
int n=A.size();
for(int i=1;i<=A.size();i++) {
arr[i]=((i%2)*((n-i+1)%2))%2;
arr[i]%=2;
}
int ans=0;
for(int i=0;i<A.size();i++) {
if(arr[i+1]==1) {
ans^=A.get(i);
}
}
return ans;
}
public static String printBinary(long a) {
String str="";
for(int i=31;i>=0;i--) {
if((a&(1<<i))!=0) {
str+=1;
}
if((a&(1<<i))==0 && !str.isEmpty()) {
str+=0;
}
}
return str;
}
public static String reverse(long a) {
long rev=0;
String str="";
int x=(int)(Math.log(a)/Math.log(2))+1;
for(int i=0;i<32;i++) {
rev<<=1;
if((a&(1<<i))!=0) {
rev|=1;
str+=1;
}
else {
str+=0;
}
}
return str;
}
////////////////////////////////////////////////////////
static void sortS(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
return p1.second - p2.second;
}
});
}
static class Pair implements Comparable<Pair>
{
int first ;int second ;
public Pair(int x, int y)
{
this.first = x ;this.second = y ;
}
@Override
public boolean equals(Object obj)
{
if(obj == this)return true ;
if(obj == null)return false ;
if(this.getClass() != obj.getClass()) return false ;
Pair other = (Pair)(obj) ;
if(this.first != other.first)return false ;
if(this.second != other.second)return false ;
return true ;
}
@Override
public int hashCode()
{
return this.first^this.second ;
}
@Override
public String toString() {
String ans = "" ;ans += this.first ; ans += " "; ans += this.second ;
return ans ;
}
@Override
public int compareTo(Main.Pair o) {
{ if(this.first==o.first) {
return this.second-o.second;
}
return this.first - o.first;
}
}
}
//////////////////////////////////////////////////////////////////////////
static int nD(long num) {
String s=String.valueOf(num);
return s.length();
}
static int CommonDigits(int x,int y) {
String s=String.valueOf(x);
String s2=String.valueOf(y);
return 0;
}
static int lcs(String str1, String str2, int m, int n)
{
int L[][] = new int[m + 1][n + 1];
int i, j;
// Following steps build L[m+1][n+1] in
// bottom up fashion. Note that L[i][j]
// contains length of LCS of str1[0..i-1]
// and str2[0..j-1]
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
L[i][j] = 0;
else if (str1.charAt(i - 1)
== str2.charAt(j - 1))
L[i][j] = L[i - 1][j - 1] + 1;
else
L[i][j] = Math.max(L[i - 1][j],
L[i][j - 1]);
}
}
// L[m][n] contains length of LCS
// for X[0..n-1] and Y[0..m-1]
return L[m][n];
}
/////////////////////////////////
boolean IsPowerOfTwo(int x)
{
return (x != 0) && ((x & (x - 1)) == 0);
}
////////////////////////////////
static long power(long a,long b,long m ) {
long ans=1;
while(b>0) {
if(b%2==1) {
ans=((ans%m)*(a%m))%m; b--;
}
else {
a=(a*a)%m;b/=2;
}
}
return ans%m;
}
///////////////////////////////
public static boolean repeatedSubString(String string) {
return ((string + string).indexOf(string, 1) != string.length());
}
static int search(char[]c,int start,int end,char x) {
for(int i=start;i<end;i++) {
if(c[i]==x) {return i;}
}
return -2;
}
////////////////////////////////
static long gcd(long a, long b) {
while (b != 0) {
long t = b;
b = a % b;
a = t;
}
return a;
}
static long fac(long a)
{
if(a== 0L || a==1L)return 1L ;
return a*fac(a-1L) ;
}
static ArrayList al() {
ArrayList<Integer>a =new ArrayList<>();
return a;
}
static HashSet h() {
return new HashSet<Integer>();
}
static void debug(int[][]a) {
int n= a.length;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
out.print(a[i][j]+" ");
}
out.print("\n");
}
}
static void debug(int[]a) {
out.println(Arrays.toString(a));
}
static void debug(ArrayList<Integer>a) {
out.println(a.toString());
}
static boolean[]seive(int n){
boolean[]b=new boolean[n+1];
for (int i = 2; i <= n; i++)
b[i] = true;
for(int i=2;i*i<=n;i++) {
if(b[i]) {
for(int j=i*i;j<=n;j+=i) {
b[j]=false;
}
}
}
return b;
}
static int longestIncreasingSubseq(int[]arr) {
int[]sizes=new int[arr.length];
Arrays.fill(sizes, 1);
int max=1;
for(int i=1;i<arr.length;i++) {
for(int j=0;j<i;j++) {
if(arr[j]<arr[i]) {
sizes[i]=Math.max(sizes[i],sizes[j]+1);
max=Math.max(max, sizes[i]);
}
}
}
return max;
}
public static ArrayList primeFactors(long n)
{
ArrayList<Long>h= new ArrayList<>();
// Print the number of 2s that divide n
if(n%2 ==0) {h.add(2L);}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (long i = 3; i <= Math.sqrt(n); i+= 2)
{
if(n%i==0) {h.add(i);}
}
if (n > 2)
h.add(n);
return h;
}
static boolean Divisors(long n){
if(n%2==1) {
return true;
}
for (long i=2; i<=Math.sqrt(n); i++){
if (n%i==0 && i%2==1){
return true;
}
}
return false;
}
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static InputReader in = new InputReader(inputStream);
static PrintWriter out = new PrintWriter(outputStream);
public static void superSet(int[]a,ArrayList<String>al,int i,String s) {
if(i==a.length) {
al.add(s);
return;
}
superSet(a,al,i+1,s);
superSet(a,al,i+1,s+a[i]+" ");
}
public static long[] makeArr() {
long size=in.nextInt();
long []arr=new long[(int)size];
for(int i=0;i<size;i++) {
arr[i]=in.nextInt();
}
return arr;
}
public static long[] arr(int n) {
long []arr=new long[n+1];
for(int i=1;i<n+1;i++) {
arr[i]=in.nextLong();
}
return arr;
}
public static void sort(long arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
static void println(long x) {
out.println(x);
}
static void print(long c) {
out.print(c);
}
static void print(int c) {
out.print(c);
}
static void println(int x) {
out.println(x);
}
static void print(String s) {
out.print(s);
}
static void println(String s) {
out.println(s);
}
public static void merge(long arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long[n1];
long R[] = new long[n2];
//Copy data to temp arrays
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
public static void reverse(int[] array)
{
int n = array.length;
for (int i = 0; i < n / 2; i++) {
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
}
public static long nCr(int n,int k)
{
long ans=1L;
k=k>n-k?n-k:k;
for( int j=1;j<=k;j++,n--)
{
if(n%j==0)
{
ans*=n/j;
}else
if(ans%j==0)
{
ans=ans/j*n;
}else
{
ans=(ans*n)/j;
}
}
return ans;
}
static int searchMax(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]>inp[index]) {
index+=1;
}
return index;
}
static int searchMin(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]<inp[index]) {
index+=1;
}
return index;
}
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
static class Pairr implements Comparable<Pairr>{
private int index;
private int cumsum;
private ArrayList<Integer>indices;
public Pairr(int index,int cumsum) {
this.index=index;
this.cumsum=cumsum;
indices=new ArrayList<Integer>();
}
public int compareTo(Pairr other) {
return Integer.compare(cumsum, other.cumsum);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 1e9a4ac5c52c3be9db1ca27cae80732e | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | //package com.shroom;
import java.util.*;
public class dec {
private static final Scanner in = new Scanner(System.in);
public static void main(String[] args) throws Exception {
//
int t = in.nextInt();
//
while (t-- > 0) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = i + 1;
}
if (a + b + 2 > n || Math.abs(b-a) > 1) {
System.out.println(-1);
continue;
}
if(b>a) {
int i=0;
while(b>0 && i<n-1) {
int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
b--;
i+=2;
}
}
else if(a>b) {
int i=n-1;
while(a>0 && i>1) {
int temp = arr[i];
arr[i] = arr[i-1];
arr[i-1] = temp;
a--;
i-=2;
}
}
else {
int i=1;
while(a>0 && i<n-1) {
int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
a--;
i+=2;
}
}
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
}
// public static long gcd(long a, long b)
// {
// if(a > b)
// a = (a+b)-(b=a);
// if(a == 0L)
// return b;
// return gcd(b%a, a);
// }
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | b44dff94cabdd591eccb981124e6e23e | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.util.*;
import java.io.*;
public class C {
static class Node implements Comparable<Node>{
int index;
String string;
Node(int v1, String val){
this.index= v1;
this.string=val;
}
Node(){}
int getindex() {
return index;
}
String getvalue() {
return string;
}
public int compareTo(Node p) {
for(int i=0;i<this.string.length();i++) {
if(i%2==0) {
if(this.string.charAt(i)>p.getvalue().charAt(i))return 1;
else if(this.string.charAt(i)<p.getvalue().charAt(i))return -1;
}
else {
if(this.string.charAt(i)<p.getvalue().charAt(i))return 1;
else if(this.string.charAt(i)>p.getvalue().charAt(i))return -1;
}
}
return 0;
}
}
//static class SortingComparator implements Comparator<Node>{
// @Override
// public int compare(Node n1, Node n2) {
// if(n1.value<n2.value)return -1;
// else if(n1.value>n2.value)return 1;
// return n2.index-n1.index;
// }
//}
static ArrayList<Node> arr = new ArrayList<>();
static int[] seat= new int[301];
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t= sc.nextInt();
while(t--!=0) {
str="";
int n= sc.nextInt();
int a= sc.nextInt();
int b = sc.nextInt();
int total=n-2;
int[] arr = new int[n+1];
for(int i=1;i<=n;i++)arr[i]=i;
if(a==0 && b==0) {
for(int i=1;i<=n;i++) {
str+=i+" ";
}
System.out.println(str);
}
else if(a+b>n-2)System.out.println(-1);
else if(Math.abs(a-b)>1)System.out.println(-1);
else {
if(a==1 && b==0) {
arr[n]=n-1;
arr[n-1]=n;
}
else if(b==1 && a==0) {
arr[1]=2;
arr[2]=1;
}
else if(a>b) {
maxfirst(n, a, b, arr);
}
else if(a<b) {
minfirst(n, a, b, arr);
}
else {
maxequal(n, a, b, arr);
}
for (int i = 1; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
}
}
}
static String str="";
public static void maxequal(int n, int a, int b, int[] arr) {
int si = 1, ei = n;
for(int i=1; i<=n; i++){
if(i > a+b){
arr[i] = ei;
ei--;
}
else{
if(i % 2 != 1){
arr[i] = si;
si++;
}
else{
arr[i] = ei;
ei--;
}
}
}
}
public static void maxfirst(int n , int a, int b, int[] arr) {
int k =n-( a+b+1);
for(int i=n;i>k;i=i-2) {
int t= arr[i];
arr[i]= arr[i-1];
arr[i-1]=t;
}
}
static boolean f= false;
public static void minfirst(int n , int a, int b, int[] arr) {
int k =( a+b+1);
for(int i=1;i<=k;i=i+2) {
int t= arr[i];
arr[i]= arr[i+1];
arr[i+1]=t;
}
}
public static void solve(int n, int a, int b) {
// if(a>b)
}
static long highestPowerof2(long x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
static boolean ispowerTwo (long x)
{
return x!=0 && ((x&(x-1)) == 0);
}
static boolean isPalindrome(char[] s) {
int i=0;
int j= s.length-1;
while(i<j) {
if(s[i]!=s[j])return false;
i++;
j--;
}
return true;
}
static long fastPower(long a, long b, int n) {
long res= 1;
while(b>0) {
if((b&1)!=0) {
res= (res*a%n)%n;
}
a= (a%n*a%n)%n;
b= b>>1;
}
return res;
}
// static int count=0;
// public static void path(int n, int m, char[][] mat, int pat, int a, int b) {
//
// int [] dx= {0, -1, 0, 1};
// int[] dy = {-1, 0, 1, 0};
//// System.out.println("yesss");
// if(a==n && b==m) {
// min=pat;
// System.out.println("changing min");
// return;
// }
// for(int i=0;i<4;i++) {
// count++;
// if(isValid(n, m, mat, a+dx[i], b+dy[i])) {
//// System.out.println("changing");
// path(n, m, mat, pat+1, a+dx[i],b+dy[i] );
// }
// }
// count--;
// return;
// }
// public static boolean isValid(int n, int m, char[][] mat, int x, int y) {
// if(x>n || y>m || x<1 || y<1)return false;
// for(int i=1;i<=m;i++) {
// if(mat[x][i]=='R' || mat[x][i]=='C') {
// if(i==y) {
// if(mat[x][i]=='C' && count%2==0)return false;
// else if(mat[x][i]=='R' && count%2==0)return false;
// }
// }
// }
// for(int i=1;i<=n;i++) {
// if(mat[i][y]=='R' || mat[i][y]=='C') {
// if(i==y) {
// if(mat[i][y]=='C' && count%2==0)return false;
// else if(mat[i][y]=='R' && count%2==0)return false;
// }
// }
// }
// return true;
// }
//
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 267adcc2fb86390caf0d3dfe5ad69fc6 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader fr = new FastReader();
int t = fr.nextInt();
while(t-->0)
{
int n = fr.nextInt();
int a = fr.nextInt();
int b = fr.nextInt();
int t1 = a;
int t2 = b;
if(a+b+2>n)
{
System.out.println(-1);
continue;
}
// if((a!=0 && b==0)||(b!=0 && a==0))
// {
// System.out.println(-1);
// continue;
// }
if(Math.abs(a-b)>1)
{
System.out.println(-1);
continue;
}
int[] output = new int[n];
if(a>b)
{
int max = n;
int min = 1;
// output[0] = 1;
int i = 1;
while(a-->0 && i<n)
{
output[i] = max;
max--;
i+=2;
}
i = 2;
while(b-->0 && i<n)
{
output[i] = min;
min++;
i+=2;
}
output[0] = max--;
a = t1;
b = t2;
for(i = a + b + 1;i<n;++i)
{
output[i] = max;
max--;
}
}else if(b>a)
{
int max = n;
int min = 1;
output[0] = n;
int i = 1;
while(b-->0 && i<n-1)
{
output[i] = min;
min++;
i+=2;
}
i = 2;
while(a-->0 && i<n)
{
output[i] = max;
max--;
i+=2;
}
output[0] = min++;
a = t1;
b = t2;
for(i = (a+b+1);i<n;++i)
{
output[i] = min;
min++;
}
}else{
if(a==0)
{
for(int i = 0;i<n;++i)
output[i] = i+1;
}
else{
int max = n;
int min = 1;
int i = 1;
while(a-->0)
{
output[i] = max--;
i+=2;
}
i = 2;
while(b-->0)
{
output[i] = min++;
i+=2;
}
output[0] = min++;
a = t1;
b = t2;
for(i = a+b+1;i<n;++i)
output[i] = min++;
}
}
for(int i = 0;i<n;++i)
System.out.print(output[i]+" ");
System.out.println();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 864358fd2c73defb5433ac95faa8990a | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.util.*;
public class Main {
public static void main(String[] args) {
/*Scanner in = new Scanner(System.in);
HashMap<Integer, Integer> map = new HashMap<>();
var n = in.nextInt();
for (int i = 0; i < n; i++) {
var a = in.nextInt();
if(map.containsKey(a))
map.put(a,map.get(a)+1);
else
map.put(a,1);
}
for (Map.Entry<Integer,Integer> item: map.entrySet()) {
System.out.println(item.getKey() + " " + item.getValue());
}*/
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int n = in.nextInt(),a=in.nextInt(),b=in.nextInt();
if(Math.abs(a-b) > 1 || n - (Math.min(a,b)*2 + 2) - (Math.max(a,b) - Math.min(a,b)) < 0)
System.out.print(-1);
else {
if(n == 2){
System.out.println("1 2");
continue;
}
if(a == b){
int chet = a+b, index = 1;
System.out.print(1 + " ");
for (int j = 2; j <= n -1; j++) {
if(chet == 0)
break;
if(j%2 == 0)
System.out.print(j+1 + " ");
else
System.out.print(j-1 + " ");
chet--;
index = j;
}
for (int j = index + 1; j <= n ; j++) {
System.out.print(j + " ");
}
}
else {
if(a > b){
int chet = a+b -1, index = 1;
System.out.print(1 + " ");
for (int j = 2; j <= n - 1; j++) {
if(chet == 0)
break;
if(j%2 ==0)
System.out.print(j+1 + " ");
else
System.out.print(j-1 + " ");
chet--;
index = j;
}
for (int j = index + 1; j <= n-2 ; j++)
System.out.print(j + " ");
System.out.print(n + " " + (n-1));
}
else{
int chet = a + b - 1, index = 2;
System.out.print(2 + " " + 1 + " " );
for (int j = 3; j <= n - 1; j++) {
if(chet == 0)
break;
if(j % 2 == 1)
System.out.print(j+1 + " ");
else
System.out.print(j-1 + " ");
chet--;
index = j;
}
for (int j = index + 1; j <= n ; j++)
System.out.print(j + " ");
}
}
}
System.out.println();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | f2e687b51699fb1b663d98a39c9984bc | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Anubhav
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
BBuildThePermutation solver = new BBuildThePermutation();
solver.solve(1, in, out);
out.close();
}
static class BBuildThePermutation {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
if (a + b + 2 > n) {
out.println(-1);
continue;
}
int done[] = new int[n + 1];
int el = a + b + 2;
int ar[] = new int[n];
int arr[] = new int[n];
int c = 1;
for (int i = 0; i < el; i += 2) {
ar[i] = c;
done[c] = 1;
c++;
}
for (int i = 1; i < el; i += 2) {
ar[i] = c;
done[c] = 1;
c++;
}
c = 1;
for (int i = 1; i < el; i += 2) {
arr[i] = c;
c++;
}
for (int i = 0; i < el; i += 2) {
arr[i] = c;
c++;
}
if (el % 2 == 0) {
c = el + 1;
for (int i = el; i < n; i++) {
ar[i] = c;
c++;
}
StringBuilder sb1 = new StringBuilder();
for (int i = 0; i < n; i++) {
sb1.append(ar[i]).append(" ");
}
int aa = 0;
int bb = 0;
for (int i = 1; i < n - 1; i++) {
if (ar[i] < ar[i - 1] && ar[i] < ar[i + 1])
bb++;
if (ar[i] > ar[i - 1] && ar[i] > ar[i + 1])
aa++;
}
if (aa == a && bb == b) {
out.println(sb1.toString());
} else
out.println(-1);
} else {
c = el + 1;
for (int i = el; i < n; i++) {
arr[i] = c;
c++;
}
if (el < n) {
done[ar[el - 1]] = 0;
done[ar[el - 2]] = 0;
ar[el - 1] = n - 1;
ar[el - 2] = n;
}
c = n - 2;
int ii = el;
while (ii < n) {
if (done[c] == 1) {
c--;
continue;
}
ar[ii] = c;
done[c] = 1;
c--;
ii++;
}
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (int i = 0; i < n; i++) {
sb1.append(ar[i]).append(" ");
sb2.append(arr[i]).append(" ");
}
int aa = 0;
int bb = 0;
for (int i = 1; i < n - 1; i++) {
if (ar[i] < ar[i - 1] && ar[i] < ar[i + 1])
bb++;
if (ar[i] > ar[i - 1] && ar[i] > ar[i + 1])
aa++;
}
if (aa == a && bb == b) {
out.println(sb1.toString());
} else {
aa = 0;
bb = 0;
for (int i = 1; i < n - 1; i++) {
if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1])
bb++;
if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1])
aa++;
}
if (aa == a && bb == b) {
out.println(sb2.toString());
} else
out.println(-1);
}
}
}
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | e51d1b9f4b69eb542373be8588ca7a5f | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
void go() {
// add code
int n = Reader.nextInt();
int a = Reader.nextInt();
int b = Reader.nextInt();
if(2 * a + 1 > n || 2 * b + 1 > n || a + b + 2 > n || Math.abs(a - b) > 1) {
Writer.print(-1 + "\n");
return;
}
int[] arr = new int[n];
int l = 0;
int r = n - 1;
int st1 = 0;
int st2 = 0;
if(a >= b) {
st1 = 1;
st2 = 2;
} else {
st1 = 2;
st2 = 1;
}
for(int i = 0; i < b; i++, l++) {
arr[2 * i + st2] = l + 1;
}
for(int i = 0; i < a; i++, r--) {
arr[2 * i + st1] = r + 1;
}
if(a > b) {
for(int i = 0; i < n; i++) {
if(arr[i] == 0) {
arr[i] = r + 1;
r--;
}
}
} else {
for(int i = 0; i < n; i++) {
if(arr[i] == 0) {
arr[i] = l + 1;
l++;
}
}
}
for(int i = 0; i < n - 1; i++) {
Writer.print(arr[i] + " ");
}
Writer.print(arr[n - 1] + "\n");
}
void solve() {
for(int T = Reader.nextInt(); T > 0; T--) go();
}
void run() throws Exception {
Reader.init(System.in);
Writer.init(System.out);
solve();
Writer.close();
}
public static void main(String[] args) throws Exception {
new B().run();
}
public static class Reader {
public static StringTokenizer st;
public static BufferedReader br;
public static void init(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
public static String next() {
while(!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new InputMismatchException();
}
}
return st.nextToken();
}
public static int nextInt() {
return Integer.parseInt(next());
}
public static long nextLong() {
return Long.parseLong(next());
}
public static double nextDouble() {
return Double.parseDouble(next());
}
}
public static class Writer {
public static PrintWriter pw;
public static void init(OutputStream os) {
pw = new PrintWriter(new BufferedOutputStream(os));
}
public static void print(String s) {
pw.print(s);
}
public static void print(char c) {
pw.print(c);
}
public static void print(int x) {
pw.print(x);
}
public static void print(long x) {
pw.print(x);
}
public static void println(String s) {
pw.println(s);
}
public static void println(char c) {
pw.println(c);
}
public static void println(int x) {
pw.println(x);
}
public static void println(long x) {
pw.println(x);
}
public static void close() {
pw.close();
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 46565417c0269115e2bb7c4af57a0cf4 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class codeforces_758_B {
private static void solve(FastIOAdapter in, PrintWriter out) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int left = n - 2;
int maxHalf = (left + 1) / 2;
int rest = left - maxHalf;
if (Math.max(a, b) > maxHalf || Math.min(a, b) > rest || Math.abs(a - b) > 1) {
out.println(-1);
} else {
int max = Math.max(a, b);
int min = Math.min(a, b);
boolean eq = max > 0 && max == min;
int st;
int end;
if (max == a) {
st = n;
end = n - max - (eq ? 1 : 0);
out.print(end-- + " ");
for (int i = 0; i < max; i++) {
out.print(st-- + " ");
if (end > 0) {
out.print(end-- + " ");
}
}
for (int i = end; i > 0; i--) {
out.print(i + " ");
}
} else {
st = 1;
end = max + 1 + (eq ? 1 : 0);
out.print(end++ + " ");
for (int i = 0; i < max; i++) {
out.print(st++ + " ");
if (end <= n) {
out.print(end++ + " ");
}
}
for (int i = end; i <= n; i++) {
out.print(i + " ");
}
}
if (eq) {
out.print(st + " ");
}
out.println();
}
}
public static void main(String[] args) throws Exception {
try (FastIOAdapter ioAdapter = new FastIOAdapter()) {
int count = 1;
count = ioAdapter.nextInt();
while (count-- > 0) {
solve(ioAdapter, ioAdapter.out);
}
}
}
static void ruffleSort(int[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
Arrays.sort(arr);
}
static class FastIOAdapter implements AutoCloseable {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter((System.out))));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
@Override
public void close() throws Exception {
out.flush();
out.close();
br.close();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 9bd60bdbde3c4cd669d86aca54636319 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
static int MOD = 1000000007;
// After writing solution, quick scan for:
// array out of bounds
// special cases e.g. n=1?
// npe, particularly in maps
//
// Big numbers arithmetic bugs:
// int overflow
// sorting, or taking max, after MOD
void solve() throws IOException {
int T = ri();
for (int Ti = 0; Ti < T; Ti++) {
int[] nab = ril(3);
int n = nab[0];
int a = nab[1]; // maxima
int b = nab[2]; // minima
int[] p = new int[n];
Arrays.fill(p, -1);
boolean done = false;
if (a == 0 && b == 0) {
for (int i = 1; i <= n; i++) pw.print(i + " ");
pw.println();
continue;
}
if (n == 2) {
pw.println("-1");
continue;
}
// place maxima at index 1, 3, 5, 7, ...
if (a >= b) {
int val = n;
for (int i = 0; i < a; i++) {
if (1 + 2 * i >= n-1) {
done = true;
break;
}
p[1 + 2 * i] = val--;
}
if (!done) {
if (b == a-1) {
for (int i = 0; i < n; i++) {
if (p[i] == -1) p[i] = val--;
}
} else if (b == a && n >= a * 2 + 2) {
for (int i = 0; i < n; i++) {
if (p[i] == -1) p[i] = val--;
p[n-2] = 1;
p[n-1] = 2;
}
} else {
done = true;
}
}
} else {
int val = 1;
for (int i = 0; i < b; i++) {
if (1 + 2 * i >= n-1) {
done = true;
break;
}
p[1 + 2 * i] = val++;
}
if (!done) {
if (a == b-1) {
for (int i = 0; i < n; i++) {
if (p[i] == -1) p[i] = val++;
}
} else {
done = true;
}
}
}
if (done) {
pw.println("-1");
continue;
}
for (int ai : p) {
pw.print(ai + " ");
}
pw.println();
}
}
// IMPORTANT
// DID YOU CHECK THE COMMON MISTAKES ABOVE?
// Template code below
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
Main m = new Main();
m.solve();
m.close();
}
void close() throws IOException {
pw.flush();
pw.close();
br.close();
}
int ri() throws IOException {
return Integer.parseInt(br.readLine().trim());
}
long rl() throws IOException {
return Long.parseLong(br.readLine().trim());
}
int[] ril(int n) throws IOException {
int[] nums = new int[n];
int c = 0;
for (int i = 0; i < n; i++) {
int sign = 1;
c = br.read();
int x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
nums[i] = x * sign;
}
while (c != '\n' && c != -1) c = br.read();
return nums;
}
long[] rll(int n) throws IOException {
long[] nums = new long[n];
int c = 0;
for (int i = 0; i < n; i++) {
int sign = 1;
c = br.read();
long x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
nums[i] = x * sign;
}
while (c != '\n' && c != -1) c = br.read();
return nums;
}
int[] rkil() throws IOException {
int sign = 1;
int c = br.read();
int x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
return ril(x);
}
long[] rkll() throws IOException {
int sign = 1;
int c = br.read();
int x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
return rll(x);
}
char[] rs() throws IOException {
return br.readLine().toCharArray();
}
void sort(int[] A) {
Random r = new Random();
for (int i = A.length-1; i > 0; i--) {
int j = r.nextInt(i+1);
int temp = A[i];
A[i] = A[j];
A[j] = temp;
}
Arrays.sort(A);
}
void printDouble(double d) {
pw.printf("%.16f", d);
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 10dd7734f70d275f93a11eacf46aad36 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class BuildPermutation {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
int count=0;
while(count<t){
count++;
solve(br);
}
}
public static void solve(BufferedReader br) throws IOException {
String[] temp=br.readLine().trim().split(" ");
int n=Integer.parseInt(temp[0]);
int a=Integer.parseInt(temp[1]);
int b=Integer.parseInt(temp[2]);
if(Math.abs(b-a)>1||a+b>n-2){
System.out.println(-1);
return;
}
if(a==b&&a==0){
for(int i=1;i<=n;i++){
System.out.print(i);
if(i!=n){
System.out.print(' ');
}
}
System.out.print('\n');
return;
}
Deque<Integer> queue=new LinkedList<>();
for(int i=1;i<=n;i++){
queue.add(i);
}
if(a==b){
int first=n/2;
int[] res=new int[n];
int index=1;
res[0]=first;
int countMin=0;
while(index!=n){
if(queue.size()!=0&&queue.peekFirst()==first){
queue.pollFirst();
}
if(queue.size()!=0&&queue.peekLast()==first){
queue.pollLast();
}
if(index%2==1){
res[index]=queue.pollLast();
index++;
}
else{
res[index]=queue.pollFirst();
index++;
countMin++;
if(countMin==b){
break;
}
}
}
if(index!=n){
List<Integer> remain=new ArrayList<>(queue);
Collections.sort(remain);
for(int i=0;i<remain.size();i++){
if(remain.get(i)==first){
continue;
}
res[index]=remain.get(i);
index++;
}
}
output(res);
}
else if(b>a){
int[] res=new int[n];
res[0]=queue.pollLast();
int index=1;
int countMin=0;
while(index<n){
if(index%2==1){
res[index]=queue.pollFirst();
countMin++;
index++;
if(countMin==b){
break;
}
}
else{
res[index]=queue.pollLast();
index++;
}
}
List<Integer> remain=new ArrayList<>(queue);
Collections.sort(remain);
for(int i=0;i<remain.size();i++){
res[index]=remain.get(i);
index++;
}
output(res);
}
else{
int[] res=new int[n];
res[0]=queue.pollFirst();
int countMax=0;
int index=1;
while(index<n){
if(index%2==1){
res[index]=queue.pollLast();
countMax++;
index++;
if(countMax==a){
break;
}
}
else{
res[index]=queue.pollFirst();
index++;
}
}
List<Integer> remain=new ArrayList<>(queue);
Collections.sort(remain);
Collections.reverse(remain);
for(int i=0;i<remain.size();i++){
res[index]=remain.get(i);
index++;
}
output(res);
}
}
public static void output(int[] res){
int n=res.length;
for(int i=0;i<n;i++){
System.out.print(res[i]);
if(i!=n-1){
System.out.print(' ');
}
}
System.out.print('\n');
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | fd607b26e2c86752b3e3b452083de5d5 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int k = input.nextInt();
while (k-- != 0) {
int n = input.nextInt();
int a = input.nextInt(); // 大于两边
int b = input.nextInt(); // 小于两边
if (Math.abs(a - b) > 1 || a + b > n - 2) {
System.out.println(-1);
continue;
}
int[] ans = new int[n];
for (int i = 0; i < n; i++) {
ans[i] = i + 1;
}
if(a == 0 && b == 0){
for (int i = 0; i < n; i++) {
System.out.print(ans[i]);
System.out.print(i == n-1 ?"\n" : " ");
}
continue;
}
if(a == b){
swap(ans,0,1);
swap(ans,n-1,n-2);
for (int i = 1; i <= a - 1; i ++){
swap(ans,i*2,i*2+1);
}
} else if(a > b){
swap(ans, n - 1, n - 2);
for (int i = 1; i <= b; i++) {
swap(ans, n-2-i*2, n-1-i*2);
}
} else {
swap(ans,0,1);
for (int i = 1; i <= a; i ++){
swap(ans,i*2,i*2+1);
}
}
for (int i = 0; i < n; i++) {
System.out.print(ans[i]);
System.out.print(i == n-1? "\n" : " ");
}
}
}
static void swap(int[] ans, int index1, int index2) {
int mid = ans[index1];
ans[index1] = ans[index2];
ans[index2] = mid;
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 149e56e7616d00006b9b64267b4f28dc | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Rough {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long test = sc.nextLong();
// 2 5
// 1 5
while (test > 0) {
int num = sc.nextInt();
int[] arr = new int[num];
int a = sc.nextInt();
int b = sc.nextInt();
if (a + b > num - 2) {
System.out.println(-1);
} else if (Math.abs(a - b) > 1) {
System.out.println(-1);
} else {
if (a > b) {
int i = 0;
int highest = num;
while (a > 0) {
arr[2 * i + 1] = highest;
highest--;
a--;
i++;
}
// System.out.println("a ka kaam ho gya hai ");
// for (int idx = 0; idx < arr.length; idx++) {
// System.out.print(arr[idx] + " ");
// }
i = 0;
int lowest = 1;
while (b > 0) {
arr[2 * i + 2] = lowest;
lowest++;
b--;
i++;
}
// System.out.println("b ka kaam ho gya hai ");
// for (int idx = 0; idx < arr.length; idx++) {
// System.out.print(arr[idx] + " ");
// }
for (int idx = 0; idx < arr.length; idx++) {
if (arr[idx] == 0) {
arr[idx] = highest--;
}
}
for (int idx = 0; idx < arr.length; idx++) {
System.out.print(arr[idx] + " ");
}
} else if (b > a) {
int i = 0;
int highest = num;
while (a > 0) {
arr[2 * i + 2] = highest;
highest--;
a--;
i++;
}
// System.out.println("a ka kaam ho gya hai ");
// for (int idx = 0; idx < arr.length; idx++) {
// System.out.print(arr[idx] + " ");
// }
i = 0;
int lowest = 1;
while (b > 0) {
arr[2 * i + 1] = lowest;
lowest++;
b--;
i++;
}
// System.out.println("b ka kaam ho gya hai ");
// for (int idx = 0; idx < arr.length; idx++) {
// System.out.print(arr[idx] + " ");
// }
for (int idx = 0; idx < arr.length; idx++) {
if (arr[idx] == 0) {
arr[idx] = lowest++;
}
}
System.out.println();
for (int idx = 0; idx < arr.length; idx++) {
System.out.print(arr[idx] + " ");
}
System.out.println();
} else {
int i = 0;
int highest = num;
while (a > 0) {
arr[2 * i + 1] = highest;
highest--;
a--;
i++;
}
i = 0;
int lowest = 1;
while (b > 0) {
arr[2 * i + 2] = lowest;
lowest++;
b--;
i++;
}
for (int idx = 0; idx < arr.length; idx++) {
if (arr[idx] == 0) {
arr[idx] = lowest++;
}
}
for (int idx = 0; idx < arr.length; idx++) {
System.out.print(arr[idx] + " ");
}
}
}
test--;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 7b9c64c1aae3e5f35481ed639d882065 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
try {
int t = sc.nextInt();
while (t-- > 0)
solve();
} catch (Exception e) {
e.printStackTrace();
}
out.flush();
}
// SOLUTION STARTS HERE
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
static void solve() {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if (a == 0 && b == 0) {
for (int i = 1; i <= n; i++)
System.out.print(i + " ");
System.out.println();
return;
}
/*
* hill of size a needs a+1 more elements and as abs(a-b) <= 1 for answer so we
* need a+b+2(extra elements for sides) total a+b+2 should be <=n for answer.
*/
if (a + b + 2 > n) {
System.out.println(-1);
return;
}
if (Math.abs(a - b) > 1) {
System.out.println(-1);
return;
}
if (a > b) {
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = n - i;
for (int i = 0; a-- > 0; i += 2) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
sc.printIntArray(arr);
System.out.println();
return;
}
if (a == b) {
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = i + 1;
for (int i = 1; a-- > 0; i += 2) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
sc.printIntArray(arr);
System.out.println();
return;
}
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = i + 1;
for (int i = 0; b-- > 0; i += 2) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
sc.printIntArray(arr);
System.out.println();
}
// SOLUTION ENDS HERE
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
static class DSU {
int rank[];
int parent[];
DSU(int n) {
rank = new int[n + 1];
parent = new int[n + 1];
for (int i = 1; i <= n; i++) {
parent[i] = i;
}
}
int findParent(int node) {
if (parent[node] == node)
return node;
return parent[node] = findParent(parent[node]);
}
boolean union(int x, int y) {
int px = findParent(x);
int py = findParent(y);
if (px == py)
return false;
if (rank[px] < rank[py]) {
parent[px] = py;
} else if (rank[px] > rank[py]) {
parent[py] = px;
} else {
parent[px] = py;
rank[py]++;
}
return true;
}
}
static boolean[] seiveOfEratosthenes(int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
for (int i = 2; i * i <= n; i++) {
for (int j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
return isPrime;
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static boolean isPrime(long n) {
if (n < 2)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
char[][] readCharMatrix(int n, int m) {
char a[][] = new char[n][m];
for (int i = 0; i < n; i++) {
String s = sc.next();
for (int j = 0; j < m; j++) {
a[i][j] = s.charAt(j);
}
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
int[] readIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(next());
}
return a;
}
void printIntArray(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
long[] readLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Long.parseLong(next());
}
return a;
}
void printLongArray(long a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
private static final FastReader sc = new FastReader();
private static final FastWriter out = new FastWriter(System.out);
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 4e7cb3ab936f373891fb2052ba29e724 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | //package Codeforces.Round1200;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class BuildPermu {
public static void main(String[] args) throws Exception {new BuildPermu().run();}
long mod = 1000000000 + 7;
int ans=0;
// int[][] ar;
void solve() throws Exception {
int t=ni();
while(t-->0){
int n = ni();
int a = ni();
int b = ni();
int k = n-2;
if(a+b>n-2){
out.println(-1);
continue;
}
if(Math.abs(a-b)>1){
out.println(-1);
continue;
}
if(a==0 && b==0){
for(int i=1;i<=n;i++){
out.print(i+" ");
}
out.println();
continue;
}
int[] aa = new int[n];
if(a==1 && b==1){
for(int i=0;i<n;i++){
aa[i] = i+1;
}
int tmpp = aa[0];
aa[0] = aa[1];
aa[1] = tmpp;
tmpp = aa[n-1];
aa[n-1] = aa[n-2];
aa[n-2] = tmpp;
for(int i=0;i<n;i++){
out.print(aa[i]+" ");
}
out.println();
continue;
}
if(a>b){
int tmp = a;
for(int i=0;i<n;i++){
aa[i] = i+1;
}
swapLast(aa,2*tmp);
if((a-b)==0){
int tmpp = aa[0];
aa[0] = aa[1];
aa[1] = tmpp;}
}else{
int tmp = b;
//int[] aa = new int[n];
for(int i=0;i<n;i++){
aa[i] = i+1;
}
swapFront(aa,2*tmp);
//a-=(b-1);
if(a-b==0){
int tmpp = aa[n-1];
aa[n-1] = aa[n-2];
aa[n-2] = tmpp;}
}
for(int i=0;i<n;i++){
out.print(aa[i]+" ");
}
out.println();
}
}
void swapFront(int[] a,int c){
int n= a.length;
for(int i=0;i<c;i+=2){
int tmp = a[i];
a[i] = a[i+1];
a[i+1]= tmp;
}
}
void swapLast(int[] a,int c){
int n= a.length;
int j = n-c;
for(int i=j;i<n;i+=2){
int tmp = a[i];
a[i] = a[i+1];
a[i+1]= tmp;
}
}
long helper(int[] a,long mid){
long res=0;
int n =a.length;
for(int i=1;i<n;i++){
if(a[i]-a[i-1]>=mid) res+=mid;
else res+=(a[i]-a[i-1]);
}
res+=mid;
return res;
}
// void buildMatrix(){
//
// for(int i=1;i<=1000;i++){
//
// ar[i][1] = (i*(i+1))/2;
//
// for(int j=2;j<=1000;j++){
// ar[i][j] = ar[i][j-1]+(j-1)+i-1;
// }
// }
// }
/* FAST INPUT OUTPUT & METHODS BELOW */
private byte[] buf = new byte[1024];
private int index;
private InputStream in;
private int total;
private SpaceCharFilter filter;
PrintWriter out;
int min(int... ar) {
int min = Integer.MAX_VALUE;
for (int i : ar)
min = Math.min(min, i);
return min;
}
long min(long... ar) {
long min = Long.MAX_VALUE;
for (long i : ar)
min = Math.min(min, i);
return min;
}
int max(int... ar) {
int max = Integer.MIN_VALUE;
for (int i : ar)
max = Math.max(max, i);
return max;
}
long max(long... ar) {
long max = Long.MIN_VALUE;
for (long i : ar)
max = Math.max(max, i);
return max;
}
void shuffle(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i = 0; i < a.length; i++)
al.add(a[i]);
Collections.sort(al);
for (int i = 0; i < a.length; i++)
a[i] = al.get(i);
}
long lcm(long a, long b) {
return (a * b) / (gcd(a, b));
}
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
/*
* for (1/a)%mod = ( a^(mod-2) )%mod ----> use expo to calc -->(a^(mod-2))
*/
long expo(long p, long q) /* (p^q)%mod */
{
long z = 1;
while (q > 0) {
if (q % 2 == 1) {
z = (z * p) % mod;
}
p = (p * p) % mod;
q >>= 1;
}
return z;
}
void run() throws Exception {
in = System.in;
out = new PrintWriter(System.out);
solve();
out.flush();
}
private int scan() throws IOException {
if (total < 0)
throw new InputMismatchException();
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
private int ni() throws IOException {
int c = scan();
while (isSpaceChar(c))
c = scan();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = scan();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = scan();
} while (!isSpaceChar(c));
return res * sgn;
}
private long nl() throws IOException {
long num = 0;
int b;
boolean minus = false;
while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = scan();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = scan();
}
}
private double nd() throws IOException {
return Double.parseDouble(ns());
}
private String ns() throws IOException {
int c = scan();
while (isSpaceChar(c))
c = scan();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = scan();
} while (!isSpaceChar(c));
return res.toString();
}
private String nss() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
return br.readLine();
}
private char nc() throws IOException {
int c = scan();
while (isSpaceChar(c))
c = scan();
return (char) c;
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
private boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhiteSpace(c);
}
private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 93bfe8eef7f522d86856540a9e1caaa1 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Main{
static int [] path;
static int tmp;
static boolean find;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if((a+b)>(n-2) || Math.abs(a-b)>1) System.out.println(-1);
else{
int [] arr = new int [n];
if(a>b){
int last = n;
int first = 1;
int tmp = a;
for (int i = 0; i <n ; i++) {
if(tmp!=0) {
if (i % 2 != 0) {
arr[i] = last--;
tmp--;
} else arr[i] = first++;
}else{
arr[i] = last--;
}
}
}else if(b>a){
int last = 1;
int first = n;
int tmp = b;
for (int i = 0; i <n ; i++) {
if(tmp!=0) {
if (i % 2 != 0) {
arr[i] = last++;
tmp--;
}
else arr[i] = first--;
}else{
arr[i] = last++;
}
}
}else{
int last = n;
int first = 1;
int tmp = a;
for (int i = 0; i <n ; i++) {
if (i % 2 != 0 && tmp!=0) {
arr[i] = last--;
tmp--;
}
else arr[i] = first++;
}
}
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 361c6df6986b61ae0af68d2dcf82ce58 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static long mod = (int)1e9+7;
// static PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc =new FastReader();
int t=sc.nextInt();
// int t=1;
while(t-->0)
{
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
if(a==0 && b==0)
{
for(int i=1;i<=n;i++)
{
System.out.print(i+" ");
}
System.out.println();
continue;
}
int a1[]=new int[n];
for(int i=0;i<n;i++)
{
a1[i]=i+1;
}
if(n%2==0)
{
if((int)Math.abs(a-b)>1 || a+b>n-2)
{
System.out.println("-1");
continue;
}
if(a==b )
{
for(int i=1;i<n-1;i+=2)
{
int temp=a1[i];
a1[i]=a1[i+1];
a1[i+1]=temp;
b--;
if(b==0)
{
break;
}
}
}
else if(b>a)
{
for(int i=0;i<n-1;i+=2)
{
int temp=a1[i];
a1[i]=a1[i+1];
a1[i+1]=temp;
b--;
if(b==0)
{
break;
}
}
}
else
{
for(int i=n-1;i>=1;i-=2)
{
int temp=a1[i];
a1[i]=a1[i-1];
a1[i-1]=temp;
a--;
if(a==0)
{
break;
}
}
}
}
else
{
if((int)Math.abs(a-b)>1 || a+b>n-2)
{
System.out.println("-1");
continue;
}
if(a==b)
{
for(int i=1;i<n-1;i+=2)
{
int temp=a1[i];
a1[i]=a1[i+1];
a1[i+1]=temp;
b--;
if(b==0)
{
break;
}
}
}
else if(a>b)
{
for(int i=n-1;i>=0;i-=2)
{
int temp=a1[i];
a1[i]=a1[i-1];
a1[i-1]=temp;
a--;
if(a==0)
{
break;
}
}
}
else
{
for(int i=0;i<n-1;i+=2)
{
int temp=a1[i];
a1[i]=a1[i+1];
a1[i+1]=temp;
b--;
if(b==0)
{
break;
}
}
}
}
for(int i=0;i<n;i++)
{
System.out.print(a1[i]+" ");
}
System.out.println();
}
// out.flush();
}
static int findfrequencies(int a[],int n)
{
int count=0;
for(int i=0;i<a.length;i++)
{
if(a[i]==n)
{
count++;
}
}
return count;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
static int[] EvenOddArragement(int a[])
{
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<a.length;i++)
{
if(a[i]%2==0)
{
list.add(a[i]);
}
}
for(int i=0;i<a.length;i++)
{
if(a[i]%2!=0)
{
list.add(a[i]);
}
}
for(int i=0;i<a.length;i++)
{
a[i]=list.get(i);
}
return a;
}
static int gcd(int a, int b) {
while (b != 0) {
int t = a;
a = b;
b = t % b;
}
return a;
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
// put data from sorted list to hashmap
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static int DigitSum(int n)
{
int r=0,sum=0;
while(n>=0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
return sum;
}
static boolean checkPerfectSquare(int number)
{
double sqrt=Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static boolean isPowerOfTwo(int n)
{
if(n==0)
return false;
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static boolean isPrime2(int n)
{
if (n <= 1)
{
return false;
}
if (n == 2)
{
return true;
}
if (n % 2 == 0)
{
return false;
}
for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
static String minLexRotation(String str)
{
int n = str.length();
String arr[] = new String[n];
String concat = str + str;
for(int i=0;i<n;i++)
{
arr[i] = concat.substring(i, i + n);
}
Arrays.sort(arr);
return arr[0];
}
static String maxLexRotation(String str)
{
int n = str.length();
String arr[] = new String[n];
String concat = str + str;
for (int i = 0; i < n; i++)
{
arr[i] = concat.substring(i, i + n);
}
Arrays.sort(arr);
return arr[arr.length-1];
}
static class P implements Comparable<P> {
int i, j;
public P(int i, int j) {
this.i=i;
this.j=j;
}
public int compareTo(P o) {
return Integer.compare(i, o.i);
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 7c545aefa9e944e89a58e6fc2b4b7b52 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.util.*;
public class Codeforces {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
while(sc.hasNext()) {
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
if(n<=2) {
if(x ==0 && y == 0) {
System.out.print(1 +" "+2);
}
else {
System.out.print(-1);
}
}
else {
int cnt = 0;
int cnt1 = 0;
for(int i =1 ; i<=n-2 ; i+=2) {
cnt++;
}
for(int i = 2 ; i <= n-2 ; i+=2) {
cnt1++;
}
int a[] = new int[n];
a[0] = 1;
if(x == y) {
int i = 1;
int val = n;
while(x>0 && i<=n-2){
a[i] = val;
i+=2;
val--;
x--;
}
i = 2;
val = 2;
while(y>0 && i<=n-2) {
a[i] = val;
i+=2;
val++;
y--;
}
//System.out.println(x +" "+y);
if(x != 0 || y != 0) {
System.out.print(-1);
}
else {
for( i =0 ; i <n;i++) {
if(a[i] == 0) {
a[i] = a[i-1] + 1;
}
System.out.print(a[i] +" ");
}
}
}
else if(x - y == 1) {
a[0] = 1;
int i = 1;
int val = n;
while(x>0 && i<=n-2) {
a[i] = val;
i+=2;
val--;
x--;
}
i = 2;
val = 2;
while(y>0 && i<=n-2) {
a[i] = val;
i+=2;
val++;
y--;
}
if(x != 0 || y != 0) {
System.out.print(-1);
}
else {
for( i = 0 ;i<n ; i++) {
if(a[i] == 0) {
a[i] = a[i-1] -1;
}
System.out.print(a[i] +" ");
}
}
}
else if(x -y == -1) {
a[0] = n;
int i = 1;
int val = 1;
while(y>0 && i<=n-2) {
a[i] = val;
val++;
i+=2;
y--;
}
i = 2;
val = n-1;
while(x>0 && i<=n-2) {
a[i] = val;
val--;
i+=2;
x--;
}
if(x != 0 || y!=0) {
System.out.print(-1);
}
else {
for( i = 0; i<n;i++) {
if(a[i] == 0) {
a[i] = a[i-1] + 1;
}
System.out.print(a[i] +" ");
}
}
}
else {
System.out.print(-1);
}
}
System.out.println();
}
}
}
static void primeFactors(long n , ArrayList<Integer> al) {
while(n%2 == 0) {
al.add(2);
n = n/2;
}
for(int i = 3 ; i*i<= n;i+=2) {
while(n%i == 0) {
al.add(i);
n = n/i;
}
}
if(n>2) {
al.add((int) n);
}
}
static class Pair implements Comparable<Pair>{
int a;
int b;
Pair(int a, int b){
this.a = a;
this.b = b;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
int temp = this.a - o.a;
if(temp == 0) {
return this.b - o.b;
}
else {
return temp;
}
}
}
static long gcd(long a , long b) {
if(b == 0) {
return a;
}
return gcd(b, a%b);
}
static boolean isPalindrome(int a[]) {
int i= 0;
int j = a.length - 1;
while(i<=j) {
if(a[i] != a[j]) {
return false;
}
i++;
j--;
}
return true;
}
static boolean isSubsequence(String a , String b) {
int i = 0 , j = 0;
while(i<a.length() && j<b.length()) {
if(a.charAt(i) == b.charAt(j)) {
i++;
j++;
}
else {
j++;
}
}
if(i == a.length()) {
return true;
}
return false;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | ff6506136287045b632b98eda014f16d | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long mod = 1000000007;
static long max ;
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int t = sc.nextInt();
while( t-- > 0) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
boolean check = false;
if( a >= b) {
int x =a;
int y =b;
if( x== 0 && y == 0 && n>2) {
check = false;
}
ArrayDeque<Integer> arr = new ArrayDeque<>();
int i = 1;
int j = n;
int count = 2;
arr.add(i);
arr.add(j);
j--;
i++;
while( j>=i && (b!= 0 || a!= 0)) {
// out.println(arr + " " + a + " " + b);
if( count %2 != 0){
arr.add(j);
b--;
j--;
}
else {
a--;
arr.add(i);
i++;
}
count++;
}
// out.println(arr + " " + a + " " + b);
// out.println(arr);
if( 1 < 2) {
// out.println(arr);
if( 1 < 2) {
int fst = arr.pollLast();
int scnd = arr.pollLast();
i--;
j++;
}
if( x!= y) {
for( int c = j ; c>= i ; c--) {
arr.add(c);
}
}
else {
for( int c = i ; c<= j ; c++) {
arr.add(c);
}
}
}
if(!check && a== 0 &&b == 0 ) {
while( !arr.isEmpty()) {
out.print(arr.pollFirst()+" ");
}
out.println();
}
else {
out.println(-1);
}
}
else {
ArrayDeque<Integer> arr = new ArrayDeque<>();
int i = 1;
int j = n;
int count = 1;
arr.add(j);
arr.add(i);
j--;
i++;
while( j>=i && (b!=0 || a!= 0)) {
// out.println(arr + " " + a + " " + b);
if( count %2 != 0){
arr.add(j);
b--;
j--;
}
else {
a--;
arr.add(i);
i++;
}
count++;
}
// out.println(arr + " " + a + " " + b);
int fst = arr.pollLast();
int scnd = arr.pollLast();
i--;
j++;
for( int c = i ; c<= j ; c++) {
arr.add(c);
}
if( a== 0 &&b == 0) {
while( !arr.isEmpty()) {
out.print(arr.pollFirst()+" ");
}
out.println();
}
else {
out.println(-1);
}
}
}
out.flush();
}
/*
* WARNING -> DONT EVER USE ARRAYS.SORT() IN ANY WAY.
* FIRST AND VERY IMP -> READ AND UNDERSTAND THE QUESTION VERY CAREFULLY.
* WARNING -> DONT CODE BULLSHIT , ALWAYS CHECK THE LOGIC ON MULTIPLE TESTCASES AND EDGECASES BEFORE.
* SECOND -> TRY TO FIND RELEVENT PATTERN SMARTLY.
* WARNING -> IF YOU THINK YOUR SOLUION IS JUST DUMB DONT SUBMIT IT BEFORE RECHECKING ON YOUR END.
*/
public static boolean ifpowof2(long n ) {
return ((n&(n-1)) == 0);
}
static boolean isprime(long x ) {
if( x== 2) {
return true;
}
if( x%2 == 0) {
return false;
}
for( long i = 3 ;i*i <= x ;i+=2) {
if( x%i == 0) {
return false;
}
}
return true;
}
static boolean[] sieveOfEratosthenes(long n) {
boolean prime[] = new boolean[(int)n + 1];
for (int i = 0; i <= n; i++) {
prime[i] = true;
}
for (long p = 2; p * p <= n; p++) {
if (prime[(int)p] == true) {
for (long i = p * p; i <= n; i += p)
prime[(int)i] = false;
}
}
return prime;
}
public static int[] nextLargerElement(int[] arr, int n) {
Stack<Integer> stack = new Stack<>();
int rtrn[] = new int[n];
rtrn[n-1] = -1;
stack.push( n-1);
for( int i = n-2 ;i >= 0 ; i--){
int temp = arr[i];
int lol = -1;
while( !stack.isEmpty() && arr[stack.peek()] <= temp){
if(arr[stack.peek()] == temp ) {
lol = stack.peek();
}
stack.pop();
}
if( stack.isEmpty()){
if( lol != -1) {
rtrn[i] = lol;
}
else {
rtrn[i] = -1;
}
}
else{
rtrn[i] = stack.peek();
}
stack.push( i);
}
return rtrn;
}
static void mysort(int[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
int loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static void mySort(long[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
long loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
static long rightmostsetbit(long n) {
return n&-n;
}
static long leftmostsetbit(long n)
{
long k = (long)(Math.log(n) / Math.log(2));
return 1 << k;
}
static HashMap<Long,Long> primefactor( long n){
HashMap<Long ,Long> hm = new HashMap<>();
long temp = 0;
while( n%2 == 0) {
temp++;
n/=2;
}
if( temp!= 0) {
hm.put( 2L, temp);
}
long c = (long)Math.sqrt(n);
for( long i = 3 ; i <= c ; i+=2) {
temp = 0;
while( n% i == 0) {
temp++;
n/=i;
}
if( temp!= 0) {
hm.put( i, temp);
}
}
if( n!= 1) {
hm.put( n , 1L);
}
return hm;
}
static ArrayList<Integer> allfactors(int abs) {
HashMap<Integer,Integer> hm = new HashMap<>();
ArrayList<Integer> rtrn = new ArrayList<>();
for( int i = 2 ;i*i <= abs; i++) {
if( abs% i == 0) {
hm.put( i , 0);
hm.put(abs/i, 0);
}
}
for( int x : hm.keySet()) {
rtrn.add(x);
}
if( abs != 0) {
rtrn.add(abs);
}
return rtrn;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 70e70613701d8744bd9cd9aa56f917eb | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class div2 {
public static void main(String[] args) throws IOException {
Reader sc=new Reader();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
if((a+b)>n-2||Math.abs(a-b)>1)
{
System.out.print("-1");
}
else
{
if(a==b)
{
int low=1;
int high=n;
System.out.print("1"+" ");
low++;
int k=1;
while(k<=a)
{
System.out.print(high+" ");
high--;
System.out.print(low+" ");
low++;
k++;
}
while(low<=high)
{
System.out.print(low+" ");
low++;
}
}
else if(a>b)
{
int low=1;
int high=n;
System.out.print("1"+" ");
low++;
int k=1;
while(k<a)
{
System.out.print(high+" ");
high--;
System.out.print(low+" ");
low++;
k++;
}
while(low<=high)
{
System.out.print(high+" ");
high--;
}
}
else
{
int low=1;
int high=n;
System.out.print(high+" ");
high--;
int k=1;
while(k<b)
{
System.out.print(low+" ");
low++;
System.out.print(high+" ");
high--;
k++;
}
while(low<=high)
{
System.out.print(low+" ");
low++;
}
}
}
System.out.println();
}
}
}
class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 69459719bd9e59fae95819b4b1948418 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
/*
-> Give your 100%, that's it!
-> Rules To Solve Any Problem:
1. Read the problem.
2. Think About It.
3. Solve it!
*/
public class Template {
static int mod = 1000000007;
static int a = 0, b = 0;
public static void main(String[] args){
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int yo = sc.nextInt();
while (yo-- > 0) {
int n = sc.nextInt();
a = sc.nextInt(); b = sc.nextInt();
ok = false;
int[] arr = new int[n];
for(int i = 0; i < n; i++) arr[i] = i+1;
if(n == 2){
if(a != 0 || b != 0){
out.println("-1");
}
else {
out.println("1 2");
}
continue;
}
if(a == 0 && b == 0){
print(arr,out);
continue;
}
// bf
// List<List<Integer>> list = permute(arr);
// for(List<Integer> l : list){
// for(int e : l){
// out.print(e + " ");
// }
// out.println();
// }
// if(list.size() == 0){
// out.println(-1);
// }
int[] which = new int[n];
if(a > b){
int tempA = 0;
int tempB = 0;
for(int i = 1; i < n-1; i++){
if(tempA == a && tempB == b){
ok = true;
break;
}
if(i % 2 == 1){
which[i] = 1;
tempA++;
}
else {
which[i] = 2;
tempB++;
}
}
if(!ok && (tempA != a && tempB != b)){
out.println(-1);
}
else {
int left = 1;
int right = n;
for(int i = 1; i < n-1; i++){
if(which[i] == 1){
which[i] = right--;
}
else if(which[i] == 2){
which[i] = left++;
}
}
which[0] = left++;
for(int i = 0; i < n; i++){
if(which[i] == 0){
which[i] = right--;
}
}
if(valid(which)){
print(which,out);
}
else {
// print(which,out);
out.println(-1);
}
}
}
else if(a == b){
int tempA = 0;
int tempB = 0;
for(int i = 1; i < n-1; i++){
if(tempA == a && tempB == b){
ok = true;
break;
}
if(i % 2 == 1){
which[i] = 1;
tempB++;
}
else {
which[i] = 2;
tempA++;
}
}
if(!ok && (tempA != a && tempB != b)){
out.println(-1);
}
else {
int left = 1;
int right = n;
for(int i = 1; i < n-1; i++){
if(which[i] == 1){
which[i] = left++;
}
else if(which[i] == 2){
which[i] = right--;
}
}
which[0] = left++;
for(int i = 0; i < n; i++){
if(which[i] == 0){
which[i] = right--;
}
}
if(valid(which)){
print(which,out);
}
else {
// print(which,out);
out.println(-1);
}
}
}
else {
int tempA = 0;
int tempB = 0;
for(int i = 1; i < n-1; i++){
if(tempA == a && tempB == b){
ok = true;
break;
}
if(i % 2 == 1){
which[i] = 1;
tempB++;
}
else {
which[i] = 2;
tempA++;
}
}
if(!ok && (tempA != a && tempB != b)){
out.println(-1);
}
else {
int left = 1;
int right = n;
for(int i = 1; i < n-1; i++){
if(which[i] == 1){
which[i] = left++;
}
else if(which[i] == 2){
which[i] = right--;
}
}
which[0] = left++;
for(int i = 0; i < n; i++){
if(which[i] == 0){
which[i] = left++;
}
}
if(valid(which)){
print(which,out);
}
else {
// print(which,out);
out.println(-1);
}
}
}
}
out.close();
}
public static List<List<Integer>> permute(int[] nums) {
List<List<Integer>> res = new ArrayList<>();
boolean[] vis = new boolean[nums.length];
List<Integer> list = new ArrayList<>();
helper(nums,res,list,vis);
return res;
}
static boolean ok = false;
public static void helper(int[] nums, List<List<Integer>> res, List<Integer> list, boolean[] vis){
if(res.size() == 1) return;
if(list.size() == nums.length){
if(valid(list)){
res.add(new ArrayList<>(list));
ok = true;
}
return;
}
for(int i = 0; i < nums.length; i++){
if(!vis[i]){
vis[i] = true;
list.add(nums[i]);
helper(nums,res,list,vis);
list.remove(list.size()-1);
vis[i] = false;
}
}
}
static boolean valid(List<Integer> l){
int da = 0;
int db = 0;
for(int i = 1; i < l.size()-1; i++){
if(l.get(i) > l.get(i-1) && l.get(i) > l.get(i+1)){
da++;
}
else if(l.get(i) < l.get(i-1) && l.get(i) < l.get(i+1)){
db++;
}
}
return da == a && db == b;
}
static boolean valid(int[] l){
int da = 0;
int db = 0;
for(int i = 1; i < l.length-1; i++){
if(l[i] > l[i-1] && l[i] > l[i+1]){
da++;
}
else if(l[i] < l[i-1] && l[i] < l[i+1]){
db++;
}
}
return da == a && db == b;
}
/*
Source: hu_tao
Random stuff to try when stuck:
- use bruteforcer
- check for n = 1, n = 2, so on
-if it's 2C then it's dp
-for combo/probability problems, expand the given form we're interested in
-make everything the same then build an answer (constructive, make everything 0 then do something)
-something appears in parts of 2 --> model as graph
-assume a greedy then try to show why it works
-find way to simplify into one variable if multiple exist
-treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them)
-find lower and upper bounds on answer
-figure out what ur trying to find and isolate it
-see what observations you have and come up with more continuations
-work backwards (in constructive, go from the goal to the start)
-turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements)
-instead of solving for answer, try solving for complement (ex, find n-(min) instead of max)
-draw something
-simulate a process
-dont implement something unless if ur fairly confident its correct
-after 3 bad submissions move on to next problem if applicable
-do something instead of nothing and stay organized
-write stuff down
Random stuff to check when wa:
-if code is way too long/cancer then reassess
-switched N/M
-int overflow
-switched variables
-wrong MOD
-hardcoded edge case incorrectly
Random stuff to check when tle:
-continue instead of break
-condition in for/while loop bad
Random stuff to check when rte:
-switched N/M
-long to int/int overflow
-division by 0
-edge case for empty list/data structure/N=1
*/
public static class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void sort(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
for (int i = 0; i < arr.length; i++)
arr[i] = ls.get(i);
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static boolean[] sieve(int N) {
boolean[] sieve = new boolean[N + 1];
for (int i = 2; i <= N; i++)
sieve[i] = true;
for (int i = 2; i <= N; i++) {
if (sieve[i]) {
for (int j = 2 * i; j <= N; j += i) {
sieve[j] = false;
}
}
}
return sieve;
}
public static long power(long x, long y, long p) {
long res = 1L;
x = x % p;
while (y > 0) {
if ((y & 1) == 1)
res = (res * x) % p;
y >>= 1;
x = (x * x) % p;
}
return res;
}
public static void print(int[] arr, PrintWriter out) {
//for debugging only
for (int x : arr)
out.print(x + " ");
out.println();
}
public static int log2(int a){
return (int)(Math.log(a)/Math.log(2));
}
public static long ceil(long x, long y){
return (x + 0l + y - 1) / y;
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readInts(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
// For Input.txt and Output.txt
// FileInputStream in = new FileInputStream("input.txt");
// FileOutputStream out = new FileOutputStream("output.txt");
// PrintWriter pw = new PrintWriter(out);
// Scanner sc = new Scanner(in);
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | c7d3b042b844db84de6ecb27055ccd75 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | //import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import javax.print.DocFlavor.STRING;
public class Simple{
public static Deque<Integer> possible(int a[],int n){
boolean bool = true;
Deque<Integer> deq = new LinkedList<>();
int i=0;
int j=n-1;
int max = n;
int min = 1;
while(i<=j){
if(a[i]== min){
deq.addFirst(a[i]);
i++;min++;
continue;
}
if(a[j]== min){
deq.addLast(a[j]);
j--;
min++;
continue;
}
if(a[i]==max){
deq.addFirst(a[i]);
i++;
max--;
continue;
}
if(a[j]==max){
deq.addLast(a[j]);
j--;
max--;
continue;
}
Deque<Integer> d = new LinkedList<>();
d.add(-1);
return d;
}
return deq;
}
public static class Pair implements Comparable<Pair>{
int val;
int freq = 0;
public Pair(int val,int freq){
this.val = val;
this.freq= freq;
}
public int compareTo(Pair p){
if(p.freq == this.freq)return 0;
if(this.freq > p.freq)return -1;
return 1;
}
}
public static long factorial(long n)
{
// single line to find factorial
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
static long m = 998244353;
// Function to return the GCD of given numbers
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// Recursive function to return (x ^ n) % m
static long modexp(long x, long n)
{
if (n == 0) {
return 1;
}
else if (n % 2 == 0) {
return modexp((x * x) % m, n / 2);
}
else {
return (x * modexp((x * x) % m, (n - 1) / 2) % m);
}
}
// Function to return the fraction modulo mod
static long getFractionModulo(long a, long b)
{
long c = gcd(a, b);
a = a / c;
b = b / c;
// (b ^ m-2) % m
long d = modexp(b, m - 2);
// Final answer
long ans = ((a % m) * (d % m)) % m;
return ans;
}
// public static long bs(long lo,long hi,long fact,long num){
// long help = num/fact;
// long ans = hi;
// while(lo<=hi){
// long mid = (lo+hi)/2;
// if(mid/)
// }
// }
public static boolean isPrime(int n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
public static int countDigit(long n)
{
int count = 0;
while (n != 0) {
n = n / 10;
++count;
}
return count;
}
public static void main(String args[]){
//System.out.println("Hello Java");
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int t1 = 1;t1<=t;t1++){
int n = s.nextInt();
int a = s.nextInt();
int b = s.nextInt();
int lo = 1;
int hi = n;
//int count =0;
if(a+b>n-2 || Math.abs(a-b)>1){
System.out.println(-1);
continue;
}
if(a==b && b==0){
for(int i=1;i<=n;i++){
System.out.print(i+" ");
}
System.out.println();
}
else if(a==b){
boolean help = true;
int counter=0;
while(a!=0){
if(help){
System.out.print(lo+" ");
lo++;
}
else{
System.out.print(hi+" ");
hi--;
a--;
}
counter++;
help=!help;
//System.out.println();
}
while(counter!=n){
counter++;
System.out.print(lo+" ");
lo++;
}
System.out.println();
}
else if(a>=b){
boolean help = true;
int counter=0;
while(a!=0){
if(help){
System.out.print(lo+" ");
lo++;
}
else{
System.out.print(hi+" ");
hi--;
a--;
}
counter++;
help=!help;
}
while(counter!=n){
counter++;
System.out.print(hi+" ");
hi--;
}
System.out.println();
}
else{
boolean help = true;
int counter=0;
while(b!=0){
if(help){
System.out.print(hi+" ");
hi--;
}
else{
System.out.print(lo+" ");
lo++;
b--;
}
counter++;
help=!help;
}
while(counter!=n){
counter++;
System.out.print(lo+" ");
lo++;
}
System.out.println();
}
}
}
//5
// 2 4 6 8 10
}
/*abstractSys
1 3 5 7 9
1 2 3 4 5
5 6 7 8 9
*/ | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | ba662198c57ccb9f63e0d54587fc8a93 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class MergeSort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
sc.nextLine();
while(test-->0){
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
long[] arr = new long[n+1];
for(int i=1;i<=n;i++) arr[i]=i;
if(Math.abs(a-b)>1 || a+b>n-2){
System.out.println(-1);
}else if(a==0 && b==0){
for(int i=1;i<=n;i++){
System.out.print(i+" ");
}
System.out.println();
}else{
if(a>b){
int i = n;
while(a-->0){
swap(i,i-1,arr);
i-=2;
}
for(int j=1;j<=n;j++){
System.out.print(arr[j]+" ");
}
}else if(b>a){
int i = 1;
while(b-->0){
swap(i,i+1,arr);
i+=2;
}
for(int j=1;j<=n;j++){
System.out.print(arr[j]+" ");
}
}else{
long x=a+b;
for(int i=1;i<=x;i+=2)
{
System.out.print(i+1+" "+i+" ");
}
for(long i=x+1;i<=n-2;i++)
{
System.out.print(i+" ");
}
System.out.print(n+" "+(n-1));
}
System.out.println();
}
}
}
private static void swap(int i, int j, long[] arr){
long temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
private static void swap(int i, int j){
int temp = i;
i=j;
j=temp;
}
private static boolean isEven(int a){
return a % 2 == 0;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | be7c82156313ad793770655ff04f5536 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class codeforce {
static boolean multipleTC = true;
final static int Mod = 1000000007;
final static int Mod2 = 998244353;
final double PI = 3.14159265358979323846;
int MAX = 1000000007;
long ans = 0;
void pre() throws Exception {
}
void solve(int t) throws Exception {
int n = ni();
int a = ni();
int b = ni();
int arr[] = new int[n+1];
if((a+b+2) > n || Math.abs(a-b) > 1) {
pn(-1);
return;
}
if(a == b) {
int end = (a+1)*2;
int strt = 1;
int len = end;
for(int i=1;i<=Math.min(len, n);i++) {
if(i%2 != 0) {
arr[i] = strt;
strt++;
}
else {
arr[i] = end;
end--;
}
}
if((len > 1 && len <= n) && arr[len] < arr[len-1]) {
int num = arr[len];
for(int i=len;i<n;i++)
arr[i] = (i+1);
arr[n] = num;
}
else {
for(int i=(len+1);i<=n;i++)
arr[i] = i;
}
}
else {
int end = Math.max(a, b)*2 + 1;
int strt = 1, len = end;
boolean flag = false;
if(a == Math.max(a, b))
flag = true;
for(int i=1;i<=Math.min(len, n);i++) {
if(flag) {
arr[i] = strt;
strt++;
flag = false;
}
else {
arr[i] = end;
end--;
flag = true;
}
}
if((len > 1 && len <= n) && arr[len] < arr[len-1]) {
int num = arr[len];
for(int i=len;i<n;i++)
arr[i] = (i+1);
arr[n] = num;
}
else {
for(int i=(len+1);i<=n;i++)
arr[i] = i;
}
}
StringBuilder ans = new StringBuilder();
for(int i=1;i<=n;i++)
ans.append(arr[i] + " ");
pn(ans);
}
double dist(int x1, int y1, int x2, int y2) {
double a = x1 - x2, b = y1 - y2;
return Math.sqrt((a * a) + (b * b));
}
int[] readArr(int n) throws Exception {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ni();
}
return arr;
}
void sort(int arr[], int left, int right) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = left; i <= right; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = left; i <= right; i++)
arr[i] = list.get(i - left);
}
void sort(int arr[]) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < arr.length; i++)
arr[i] = list.get(i);
}
public long max(long... arr) {
long max = arr[0];
for (long itr : arr)
max = Math.max(max, itr);
return max;
}
public int max(int... arr) {
int max = arr[0];
for (int itr : arr)
max = Math.max(max, itr);
return max;
}
public long min(long... arr) {
long min = arr[0];
for (long itr : arr)
min = Math.min(min, itr);
return min;
}
public int min(int... arr) {
int min = arr[0];
for (int itr : arr)
min = Math.min(min, itr);
return min;
}
public long sum(long... arr) {
long sum = 0;
for (long itr : arr)
sum += itr;
return sum;
}
public long sum(int... arr) {
long sum = 0;
for (int itr : arr)
sum += itr;
return sum;
}
String bin(long n) {
return Long.toBinaryString(n);
}
String bin(int n) {
return Integer.toBinaryString(n);
}
static int bitCount(int x) {
return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
int abs(int a) {
return (a < 0) ? -a : a;
}
long abs(long a) {
return (a < 0) ? -a : a;
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
void pn(int[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
void pn(long[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
char c() throws Exception {
return in.next().charAt(0);
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
public static void main(String[] args) throws Exception {
new codeforce().run();
}
FastReader in;
PrintWriter out;
void run() throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int T = (multipleTC) ? ni() : 1;
pre();
for (int t = 1; t <= T; t++)
solve(t);
out.flush();
out.close();
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 538d4198a4f5f38796167ca8bc5992b3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.*;
import java.util.*;
public class Solution {
static int mod=(int)1e9+7;
static long h[],add[];
public static void main(String[] args) {
Copied io = new Copied(System.in, System.out);
// int k=1;
int t = 1;
t = io.nextInt();
for (int i = 0; i < t; i++) {
// io.print("Case #" + k + ": ");
solve(io);
// k++;
}
io.close();
}
public static void solve(Copied io) {
int n=io.nextInt(),a=io.nextInt(),b=io.nextInt();
if(a+b>n-2 || abs(a-b)>1){
io.println(-1);
return;
}
int ans[]=new int[n];
HashSet<Integer> s=new HashSet<>();
for(int i=1;i<=n;i++){
s.add(i);
}
if(a>b){
int x=n;
for(int i=1,cnt=0;cnt<a;i+=2,cnt++){
ans[i]=x;
s.remove(x);
x--;
}
x=1;
for(int i=2,cnt=0;cnt<b;i+=2,cnt++){
ans[i]=x;
s.remove(x);
x++;
}
List<Integer> arr=new ArrayList<>(s);
int k=arr.size()-1;
for(int i=0;i<n;i++){
if(ans[i]==0){
ans[i]=arr.get(k);
k--;
}
}
}
else if(a<b){
int x=1;
for(int i=1,cnt=0;cnt<b;i+=2,cnt++){
ans[i]=x;
s.remove(x);
x++;
}
x=n;
for(int i=2,cnt=0;cnt<a;i+=2,cnt++){
ans[i]=x;
s.remove(x);
x--;
}
List<Integer> arr=new ArrayList<>(s);
int k=0;
for(int i=0;i<n;i++){
if(ans[i]==0){
ans[i]=arr.get(k);
k++;
}
}
}
else{
int x=n;
for(int i=1,cnt=0;cnt<b;i+=2,cnt++){
// io.println("Here");
ans[i]=x;
s.remove(x);
x--;
}
x=1;
for(int i=2,cnt=0;cnt<a;i+=2,cnt++){
ans[i]=x;
s.remove(x);
x++;
}
// printArr(ans, io);
// io.println(s);
List<Integer> arr=new ArrayList<>(s);
int k=0;
for(int i=0;i<n;i++){
if(ans[i]==0){
ans[i]=arr.get(k);
k++;
}
}
}
printArr(ans,io);
}
static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static void binaryOutput(boolean ans, Copied io){
String a=new String("YES"), b=new String("NO");
if(ans){
io.println(a);
}
else{
io.println(b);
}
}
static int power(int x, int y, int p)
{
int res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void printArr(int[] arr,Copied io) {
for (int x : arr)
io.print(x + " ");
io.println();
}
static void printArr(long[] arr,Copied io) {
for (long x : arr)
io.print(x + " ");
io.println();
}
static int[] listToInt(ArrayList<Integer> a){
int n=a.size();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=a.get(i);
}
return arr;
}
static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
}
// class Pair implements Cloneable, Comparable<Pair>
// {
// int x,y;
// Pair(int a,int b)
// {
// this.x=a;
// this.y=b;
// }
// @Override
// public boolean equals(Object obj)
// {
// if(obj instanceof Pair)
// {
// Pair p=(Pair)obj;
// return p.x==this.x && p.y==this.y;
// }
// return false;
// }
// @Override
// public int hashCode()
// {
// return Math.abs(x)+101*Math.abs(y);
// }
// @Override
// public String toString()
// {
// return "("+x+" "+y+")";
// }
// @Override
// protected Pair clone() throws CloneNotSupportedException {
// return new Pair(this.x,this.y);
// }
// @Override
// public int compareTo(Pair a)
// {
// int t= this.x-a.x;
// if(t!=0)
// return t;
// else
// return this.y-a.y;
// }
// }
// class byY implements Comparator<Pair>{
// // @Override
// public int compare(Pair o1,Pair o2){
// // -1 if want to swap and (1,0) otherwise.
// int t= o1.y-o2.y;
// if(t!=0)
// return t;
// else
// return o1.x-o2.x;
// }
// }
// class byX implements Comparator<Pair>{
// // @Override
// public int compare(Pair o1,Pair o2){
// // -1 if want to swap and (1,0) otherwise.
// int t= o1.x-o2.x;
// if(t!=0)
// return t;
// else
// return o1.y-o2.y;
// }
// }
// class DescendingOrder<T> implements Comparator<T>{
// @Override
// public int compare(Object o1,Object o2){
// // -1 if want to swap and (1,0) otherwise.
// int addingNumber=(Integer) o1,existingNumber=(Integer) o2;
// if(addingNumber>existingNumber) return -1;
// else if(addingNumber<existingNumber) return 1;
// else return 0;
// }
// }
class Copied extends PrintWriter {
public Copied(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Copied(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public String next() {
return nextToken();
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 33cf0da898acb0faff6cf564a300a7b7 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
public class Build_The_Permutation {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(Math.abs(a-b)>1||(a+b)>n-2) {
System.out.println("-1");
continue;
}
int i=1,j=n;
if(a>b) {
while(a-->0) {
System.out.print(i+" "+j+" ");
i++;j--;
}
while(j>=i) {
System.out.print(j+" ");
j--;
}
}else if(a==b) {
while(a-->0) {
System.out.print(i+" "+j+" ");
i++;j--;
}
while(i<=j) {
System.out.print(i+" ");
i++;
}
}else {
while(b-->0) {
System.out.print(j+" "+i+" ");
i++;j--;
}
while(i<=j){
System.out.print(i+" ");
i++;
}
}
System.out.println();
}
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | c7db95275dbec176983eb6baa059d51c | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0){
String[] s=br.readLine().split(" ");
int top=Integer.parseInt(s[0]);
int a=Integer.parseInt(s[1]);
int b=Integer.parseInt(s[2]);
String out="";
LinkedList<Integer> ls=new LinkedList<>();
for (int i = 1; i <= top; i++)
ls.addLast(i);
if (a>b)
out=methodag(ls,a,b);
if (b>a)
out=methodbg(ls,a,b);
if (a==b)
out=methodequal(ls,a,b);
System.out.println(out.substring(1));
}
//System.out.println(methodequal(11,3,3));
}
public static String methodag(LinkedList<Integer> ls,int a,int b){
if (Math.abs(a-b)>1)
return " -1";
boolean flagtop=false;
int down=1;
StringBuilder out=new StringBuilder();
while(!ls.isEmpty()&&a>0){
if (flagtop){
out.append(" "+ls.removeLast());
if (!ls.isEmpty())
a--;
}
else
out.append(" "+ls.removeFirst());
flagtop=!flagtop;
}
if (a!=0)
return " -1";
while(!ls.isEmpty())
if (flagtop)
out.append(" "+ls.removeFirst());
else
out.append(" "+ls.removeLast());
return out.toString();
}
public static String methodbg(LinkedList<Integer> ls,int a,int b){
if (Math.abs(a-b)>1)
return " -1";
boolean flagdown=false;
StringBuilder out=new StringBuilder();
while(!ls.isEmpty()&&b>0){
//System.out.println(ls);
if (flagdown) {
out.append(" " + ls.removeFirst());
if (!ls.isEmpty())
b--;
}
else
out.append(" "+ls.removeLast());
flagdown=!flagdown;
// System.out.println(out);
}
if (b!=0)
return " -1";
while(!ls.isEmpty())
if (!flagdown)
out.append(" "+ls.removeFirst());
else
out.append(" "+ls.removeLast());
return out.toString();
}
public static String methodequal(LinkedList<Integer> ls,int a,int b){
if (Math.abs(a-b)>1)
return " -1";
boolean flagtop=false;
StringBuilder out=new StringBuilder();
b++;
while(!(a==0&&b==0)&&!ls.isEmpty()){
if (flagtop) {
out.append(" " + ls.removeLast());
if (!ls.isEmpty())
a--;
}
else {
out.append(" " + ls.removeFirst());
if (!ls.isEmpty())
b--;
}
flagtop=!flagtop;
}
if (!(a==0&&b==0))
return " -1";
while(!ls.isEmpty())
if (flagtop)
out.append(" "+ls.removeFirst());
else
out.append(" "+ls.removeLast());
return out.toString();
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 2ca59d83435b51bd1072744cf724713f | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0){
solve(sc);
}
}
public static void solve(FastReader sc){
int n = sc.nextInt();
int a = sc.nextInt();int b = sc.nextInt();
if(a+b+2>n || Math.abs(a-b)>1 || (n%2==0&&Math.max(a, b)>n/2 - 1) || (n%2!=0&&Math.max(a, b)>n/2 )){
out.println(-1);out.flush();return;
}
if(a>b){
out.print(1+ " ");
int i = 2;
while(b-->0){
out.print((i+1) + " " + i + " ");
i+=2;
}
while(i!=n-1){
out.print(i+ " ");
i++;
}
out.println(n + " " + i);
}else if(a==b){
out.print(1+ " ");
int i = 2;
while(b-->0){
out.print((i+1) + " " + i + " ");
i+=2;
}
while(i!=n+1){
out.print(i+ " ");
i++;
}
out.println();
}else{
int i = 1;
while(b-->0){
out.print((i+1) + " " + i + " ");
i+=2;
}
while(i!=n+1){
out.print(i+ " ");
i++;
}
out.println();
}
//out.println(ans);
out.flush();
}
/*
int [] arr = new int[n];
for(int i = 0;i<n;++i){
arr[i] = sc.nextInt();
}
*/
static void mysort(int[] arr) {
for(int i=0;i<arr.length;i++) {
int rand = (int) (Math.random() * arr.length);
int loc = arr[rand];
arr[rand] = arr[i];
arr[i] = loc;
}
Arrays.sort(arr);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 479a349b624c6801a20a5c88ca516d4e | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Solution{
static long mod=(long)1e9+7;
static FastScanner sc = new FastScanner();
public static void solve(){
int n=sc.nextInt();
int max=sc.nextInt(),min=sc.nextInt();
if (min+max>n-2 || abs(min-max)>1) {
System.out.println("-1");
return;
}
if (n==2 && (min>0 || max>0)) {
System.out.println("-1");
return;
}
if (n==3 && (min+max>=2)) {
System.out.println("-1");
return;
}
int[] ans=new int[n];
if (max==min) {
int l=1;
int ind=min+max;
if (ind>=n) {
System.out.println("-1");
return;
}
while(ind>=0){
ans[ind]=l;
l++;
ind-=2;
}
if (l!=min+2) {
System.out.println("-1");
return;
}
int r=n;
ind=min+max-1;
while(ind>=0){
ans[ind]=r;
r--;
ind-=2;
}
if (r!=n-max) {
System.out.println("-1");
return;
}
for (int i=min+max+1;i<n;i++) {
ans[i]=l;
l++;
}
}else if(max==min+1){
int l=1;
int ind=min+max;
if (ind>=n) {
System.out.println("-1");
return;
}
int r=n;
while(ind>=0){
ans[ind]=r;
r--;
ind-=2;
}
if (r!=n-max) {
System.out.println("-1");
return;
}
ind=min+max-1;
while(ind>=0){
ans[ind]=l;
l++;
ind-=2;
}
if (l!=min+2) {
System.out.println("-1");
return;
}
for (int i=min+max+1;i<n;i++) {
ans[i]=r;
r--;
}
}else if(max+1==min){
int l=1;
int ind=min+max;
if (ind>=n) {
System.out.println("-1");
return;
}
while(ind>=0){
ans[ind]=l;
l++;
ind-=2;
}
if (l!=min+1) {
System.out.println("-1");
return;
}
int r=n;
ind=min+max-1;
while(ind>=0){
ans[ind]=r;
r--;
ind-=2;
}
if (r!=n-max-1) {
System.out.println("-1");
return;
}
for (int i=min+max+1;i<n;i++) {
ans[i]=l;
l++;
}
}
else{
System.out.println("-1");
return;
}
for (int i:ans) {
System.out.print(i+" ");
}
System.out.println("");
}
public static void main(String[] args) {
int t = sc.nextInt();
// int t=1;
outer: for (int tt = 0; tt < t; tt++) {
solve();
}
}
static boolean isSubSequence(String str1, String str2,
int m, int n)
{
int j = 0;
for (int i = 0; i < n && j < m; i++)
if (str1.charAt(j) == str2.charAt(i))
j++;
return (j == m);
}
static long log2(long n){
return (long)((double)Math.log((double)n)/Math.log((double)2));
}
static boolean isPrime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static int[] LPS(String s){
int[] lps=new int[s.length()];
int i=0,j=1;
while (j<s.length()) {
if(s.charAt(i)==s.charAt(j)){
lps[j]=i+1;
i++;
j++;
continue;
}else{
if (i==0) {
j++;
continue;
}
i=lps[i-1];
while(s.charAt(i)!=s.charAt(j) && i!=0) {
i=lps[i-1];
}
if(s.charAt(i)==s.charAt(j)){
lps[j]=i+1;
i++;
}
j++;
}
}
return lps;
}
static long getPairsCount(int n, double sum,int[] arr)
{
HashMap<Double, Integer> hm = new HashMap<>();
for (int i = 0; i < n; i++) {
if (!hm.containsKey((double)arr[i]))
hm.put((double)arr[i], 0);
hm.put((double)arr[i], hm.get((double)arr[i]) + 1);
}
long twice_count = 0;
for (int i = 0; i < n; i++) {
if (hm.get(sum - arr[i]) != null)
twice_count += hm.get(sum - arr[i]);
if (sum - (double)arr[i] == (double)arr[i])
twice_count--;
}
return twice_count / 2l;
}
static boolean[] sieveOfEratosthenes(int n)
{
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
prime[1]=false;
return prime;
}
static long power(long x, long y, long p)
{
long res = 1l;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if ((y & 1) != 0)
res = (res * x) % p;
y>>=1;
x = (x * x) % p;
}
return res;
}
public static int log2(int N)
{
int result = (int)(Math.log(N) / Math.log(2));
return result;
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////DO NOT READ AFTER THIS LINE //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
static long modFact(int n,
int p)
{
if (n >= p)
return 0;
long result = 1l;
for (int i = 3; i <= n; i++)
result = (result * i) % p;
return result;
}
static boolean isPalindrom(char[] arr, int i, int j) {
boolean ok = true;
while (i <= j) {
if (arr[i] != arr[j]) {
ok = false;
break;
}
i++;
j--;
}
return ok;
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(long a, long b) {
return Math.max(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void swap(long arr[], int i, int j) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static void swap(int arr[], int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int maxArr(int arr[]) {
int maxi = Integer.MIN_VALUE;
for (int x : arr)
maxi = max(maxi, x);
return maxi;
}
static int minArr(int arr[]) {
int mini = Integer.MAX_VALUE;
for (int x : arr)
mini = min(mini, x);
return mini;
}
static long maxArr(long arr[]) {
long maxi = Long.MIN_VALUE;
for (long x : arr)
maxi = max(maxi, x);
return maxi;
}
static long minArr(long arr[]) {
long mini = Long.MAX_VALUE;
for (long x : arr)
mini = min(mini, x);
return mini;
}
static int lcm(int a,int b){
return (int)(((long)a*b)/(long)gcd(a,b));
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static void ruffleSort(int[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
int temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
public static int binarySearch(int a[], int target) {
int left = 0;
int right = a.length - 1;
int mid = (left + right) / 2;
int i = 0;
while (left <= right) {
if (a[mid] <= target) {
i = mid + 1;
left = mid + 1;
} else {
right = mid - 1;
}
mid = (left + right) / 2;
}
return i-1;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[][] read2dArray(int n, int m) {
int arr[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = nextInt();
}
}
return arr;
}
ArrayList<Integer> readArrayList(int n) {
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int a = nextInt();
arr.add(a);
}
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Pair {
int val, ind;
Pair(int fr, int sc) {
this.val = fr;
this.ind = sc;
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 9b22238651cfe41abfb4d0adff6f0011 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
/**
__ __
( _) ( _)
/ / \\ / /\_\_
/ / \\ / / | \ \
/ / \\ / / |\ \ \
/ / , \ , / / /| \ \
/ / |\_ /| / / / \ \_\
/ / |\/ _ '_| \ / / / \ \\
| / |/ 0 \0\ / | | \ \\
| |\| \_\_ / / | \ \\
| | |/ \.\ o\o) / \ | \\
\ | /\\`v-v / | | \\
| \/ /_| \\_| / | | \ \\
| | /__/_ `-` / _____ | | \ \\
\| [__] \_/ |_________ \ | \ ()
/ [___] ( \ \ |\ | | //
| [___] |\| \| / |/
/| [____] \ |/\ / / ||
( \ [____ / ) _\ \ \ \| | ||
\ \ [_____| / / __/ \ / / //
| \ [_____/ / / \ | \/ //
| / '----| /=\____ _/ | / //
__ / / | / ___/ _/\ \ | ||
(/-(/-\) / \ (/\/\)/ | / | /
(/\/\) / / //
_________/ / /
\____________/ (
*/
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-- >0) {
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
if(a==0 && b==0) {
for(int i=1;i<=n;i++) {
System.out.print(i+" ");
}
System.out.println();
}
else if((a+b)>n-2) {
System.out.println(-1);
}
else if(Math.abs(a-b)>1) {
System.out.println(-1);
}
else {
if(a>b) {
int x=a+b+1;
for(int i=1;i<=n-x;i++) {
System.out.print(i+" ");
}
for(int i=n-x+1;i<=n;i+=2) {
System.out.print((i+1)+" "+i+" ");
}
System.out.println();
}
else if(b>a) {
int x=a+b+1;
for(int i=1;i<=x;i+=2) {
System.out.print((i+1)+" "+i+" ");
}
for(int i=x+1;i<=n;i++) {
System.out.print(i+" ");
}
System.out.println();
}
else {
int x=a+b;
for(int i=1;i<=x;i+=2) {
System.out.print((i+1)+" "+i+" ");
}
for(int i=x+1;i<=n-2;i++) {
System.out.print(i+" ");
}
System.out.print(n+" "+(n-1));
System.out.println();
}
}
}
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | d590592442892411645b097f531129c1 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
// For fast input output
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{ try {br = new BufferedReader(
new FileReader("input.txt"));
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);}
catch(Exception e) { br = new BufferedReader(new InputStreamReader(System.in));}
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {st = new StringTokenizer(br.readLine());}
catch (IOException e) {
e.printStackTrace();}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() {return Double.parseDouble(next()); }
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
// end of fast i/o code
public static void main(String[] args) {
FastReader reader = new FastReader();
StringBuilder sb = new StringBuilder("");
int t = reader.nextInt();
while(t-->0){
int n = reader.nextInt();
int a = reader.nextInt();
int b = reader.nextInt();
int arr[] = new int[n];
Arrays.fill(arr, -1);
int temp_a=a, temp_b = b;
if(a==0 && b==0){
for(int i=0; i<n; i++){
arr[i] = i+1;
}
for(int start = 0; start<n; start++){
sb.append(arr[start]+" ");
}
sb.append("\n");
continue;
}
if((int)(Math.abs(a-b))>1 || a+b>n-2){
sb.append("-1\n");
continue;
}
if(b>=a){
// filling all b
int num = 1;
int start = 1;
while(b-- > 0){
arr[start] = num++;
start += 2;
}
// filling all a
start = 2;
num = n;
while(a-- > 0){
arr[start] = num--;
start += 2;
}
if(temp_b>temp_a){
num = temp_b + 1;
for(start = 0; start<n; start++){
if(arr[start]==-1){
arr[start] = num++;
}
}
}else{
num = temp_b + 1;
arr[0] = temp_b + 1;
num = n - temp_a;
for(start=1+temp_a+temp_b; start<n; start++){
arr[start] = num--;
}
}
}else{
// filling all a
int num = n;
int start = 1;
while(a-- > 0){
arr[start] = num--;
start += 2;
}
// filling all b
start = 2;
num = 1;
while(b-- > 0){
arr[start] = num++;
start += 2;
}
num = temp_b + 1;
arr[0] = temp_b + 1;
num = n - temp_a;
for(start=1+temp_a+temp_b; start<n; start++){
arr[start] = num--;
}
}
for(int start = 0; start<n; start++){
sb.append(arr[start]+" ");
}
sb.append("\n");
}
System.out.println(sb);
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 1786e992c78f7e8c73ab8a699cc0dab0 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class Main {
// Graph
// prefix sums
//inputs
public static void main(String args[])throws Exception{
Input sc=new Input();
precalculates p=new precalculates();
StringBuilder sb=new StringBuilder();
int t=sc.readInt();
for(int f=0;f<t;f++){
int d[]=sc.readArray();
int n=d[0],a=d[1],b=d[2];
int arr[]=new int[n];
if(Math.abs(a-b)>1 || (a+b)+2>n){
sb.append("-1\n");
continue;
}
if(a>b){
for(int i=0;i<n;i++){
arr[i]=n-i;
}
for(int i=1;i<n-1 && a>0;i+=2){
int temp=arr[i-1];
arr[i-1]=arr[i];
arr[i]=temp;
a--;
}
}else if(a<b){
for(int i=0;i<n;i++){
arr[i]=i+1;
}
for(int i=1;i<n-1 && b>0;i+=2){
int temp=arr[i-1];
arr[i-1]=arr[i];
arr[i]=temp;
b--;
}
}else{
for(int i=0;i<n;i++){
arr[i]=i+1;
}
for(int i=1;i<n-1 && a>0;i+=2){
int temp=arr[i+1];
arr[i+1]=arr[i];
arr[i]=temp;
a--;
}
}
for(int i=0;i<n;i++){
sb.append(arr[i]+" ");
}
sb.append("\n");
}
System.out.print(sb);
}
/*
2 1 3 4 5 6
1 3
*/
}
class Input{
BufferedReader br;
StringTokenizer st;
Input(){
br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
}
public int[] readArray() throws Exception{
st=new StringTokenizer(br.readLine());
int a[]=new int[st.countTokens()];
for(int i=0;i<a.length;i++){
a[i]=Integer.parseInt(st.nextToken());
}
return a;
}
public long[] readArrayLong() throws Exception{
st=new StringTokenizer(br.readLine());
long a[]=new long[st.countTokens()];
for(int i=0;i<a.length;i++){
a[i]=Long.parseLong(st.nextToken());
}
return a;
}
public int readInt() throws Exception{
st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());
}
public long readLong() throws Exception{
st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());
}
public String readString() throws Exception{
return br.readLine();
}
public int[][] read2dArray(int n,int m)throws Exception{
int a[][]=new int[n][m];
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
for(int j=0;j<m;j++){
a[i][j]=Integer.parseInt(st.nextToken());
}
}
return a;
}
}
class precalculates{
public int[] prefixSumOneDimentional(int a[]){
int n=a.length;
int dp[]=new int[n];
for(int i=0;i<n;i++){
if(i==0)
dp[i]=a[i];
else
dp[i]=dp[i-1]+a[i];
}
return dp;
}
public int[] postSumOneDimentional(int a[]) {
int n = a.length;
int dp[] = new int[n];
for (int i = n - 1; i >= 0; i--) {
if (i == n - 1)
dp[i] = a[i];
else
dp[i] = dp[i + 1] + a[i];
}
return dp;
}
public int[][] prefixSum2d(int a[][]){
int n=a.length;int m=a[0].length;
int dp[][]=new int[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
}
}
return dp;
}
public long pow(long a,long b){
long mod=1000000007;
long ans=0;
if(b<=0)
return 1;
if(b%2==0){
ans=pow(a,b/2)%mod;
return ((ans%mod)*(ans%mod))%mod;
}else{
return ((a%mod)*(ans%mod))%mod;
}
}
}
class GraphInteger{
HashMap<Integer,vertex> vtces;
class vertex{
HashMap<Integer,Integer> children;
public vertex(){
children=new HashMap<>();
}
}
public GraphInteger(){
vtces=new HashMap<>();
}
public void addVertex(int a){
vtces.put(a,new vertex());
}
public void addEdge(int a,int b,int cost){
if(!vtces.containsKey(a)){
vtces.put(a,new vertex());
}
if(!vtces.containsKey(b)){
vtces.put(b,new vertex());
}
vtces.get(a).children.put(b,cost);
// vtces.get(b).children.put(a,cost);
}
public boolean isCyclicDirected(){
boolean isdone[]=new boolean[vtces.size()+1];
boolean check[]=new boolean[vtces.size()+1];
for(int i=1;i<=vtces.size();i++) {
if (!isdone[i] && isCyclicDirected(i,isdone, check)) {
return true;
}
}
return false;
}
private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){
if(check[i])
return true;
if(isdone[i])
return false;
check[i]=true;
isdone[i]=true;
Set<Integer> set=vtces.get(i).children.keySet();
for(Integer ii:set){
if(isCyclicDirected(ii,isdone,check))
return true;
}
check[i]=false;
return false;
}
}
class union_find {
int n;
int[] sz;
int[] par;
union_find(int nval) {
n = nval;
sz = new int[n + 1];
par = new int[n + 1];
for (int i = 0; i <= n; i++) {
par[i] = i;
sz[i] = 1;
}
}
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
boolean find(int a, int b) {
return root(a) == root(b);
}
int union(int a, int b) {
int ra = root(a);
int rb = root(b);
if (ra == rb)
return 0;
if(a==b)
return 0;
if (sz[a] > sz[b]) {
int temp = ra;
ra = rb;
rb = temp;
}
par[ra] = rb;
sz[rb] += sz[ra];
return 1;
}
}
| Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output | |
PASSED | 04f9a97a9e74eeb8a3fc245ca62dd4f3 | train_109.jsonl | 1639217100 | You are given three integers $$$n, a, b$$$. Determine if there exists a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that:There are exactly $$$a$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} < p_i > p_{i+1}$$$ (in other words, there are exactly $$$a$$$ local maximums).There are exactly $$$b$$$ integers $$$i$$$ with $$$2 \le i \le n-1$$$ such that $$$p_{i-1} > p_i < p_{i+1}$$$ (in other words, there are exactly $$$b$$$ local minimums).If such permutations exist, find any such permutation. | 256 megabytes | import java.util.*;
import java.io.*;
public class B {
static PrintWriter pw;
void solve(int n, int a, int b) {
if (a + b > n - 2 || Math.abs(a - b) > 1) {
pr(-1);
return;
}
List<Integer> t = new ArrayList<>();
if (a == b) {
for (int i = 0; i < a; i++) {
t.add(i + 1);
t.add(n - i);
}
for (int i = 0; i < n - 2 * a; i++) t.add(a + 1 + i);
} else if (a - b == 1) {
for (int i = 0; i < a; i++) {
t.add(i + 1);
t.add(n - i);
}
for (int i = 0; i < n - 2 * a; i++) t.add(n - a - i);
} else if (b - a == 1) {
for (int i = 0; i <= a; i++) {
t.add(n - i);
t.add(i + 1);
}
for (int i = 0; i < n - (2 * a + 2); i++) t.add(a + 2 + i);
}
outputL(t);
}
void outputL(List<Integer> l) {
for (int e : l) pw.print(e + " ");
pr("");
}
private void run() {
read_write_file(); // comment this before submission
FastScanner fs = new FastScanner();
int t = fs.nextInt();
while (t-- > 0) {
int[] a = fs.readArray(3);
solve(a[0], a[1], a[2]);
}
}
private final String INPUT = "input.txt";
private final String OUTPUT = "output.txt";
void read_write_file() {
FileInputStream instream = null;
PrintStream outstream = null;
try {
instream = new FileInputStream(INPUT);
outstream = new PrintStream(new FileOutputStream(OUTPUT));
System.setIn(instream);
System.setOut(outstream);
} catch (Exception e) {
}
}
public static void main(String[] args) {
pw = new PrintWriter(System.out);
new B().run();
pw.close();
}
void pr(int num) {
pw.println(num);
}
void pr(long num) {
pw.println(num);
}
void pr(double num) {
pw.println(num);
}
void pr(String s) {
pw.println(s);
}
void pr(char c) {
pw.println(c);
}
class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
void tr(Object... o) {
pw.println(Arrays.deepToString(o));
}
} | Java | ["3\n4 1 1\n6 1 2\n6 4 0"] | 1 second | ["1 3 2 4\n4 2 3 1 5 6\n-1"] | NoteIn the first test case, one example of such permutations is $$$[1, 3, 2, 4]$$$. In it $$$p_1 < p_2 > p_3$$$, and $$$2$$$ is the only such index, and $$$p_2> p_3 < p_4$$$, and $$$3$$$ the only such index.One can show that there is no such permutation for the third test case. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 2fdbf033e83d7c17841f640fe1fc0e55 | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq a,b \leq n$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$. | 1,200 | For each test case, if there is no permutation with the requested properties, output $$$-1$$$. Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.