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
fef51502f4c1ff58d128291bd18ae2cc
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
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[] d=new int[n]; int[] a=new int[n]; for(int i=0;i<n;i++){ ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
1d4e4957b23d516d6d15a63da1ae504d
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); boolean oneVariant = true; int[] result = new int[n]; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
157a0aeab75ac7c294c807a3efc9ed5f
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; /** * For an array of non-negative integers a of size n, we construct another array d as follows: d1=a1, di=|ai−ai−1| for 2≤i≤n. * * Your task is to restore the array a from a given array ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b014efcd1671dedb6ce2ca0b1b47201a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Pset42 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] d = new int[n]; for (int i = 0; i < n; i++) { d[i] = sc.nextInt(); } int[] a = new int[n]...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
c54bac2123029f2674511a4f237ebb9a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class Main { static long mod = (long) 1e9 + 7; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); long...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
df73ef159ca8dee1dbfff2f28bafcf0d
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import jdk.jshell.execution.JdiInitiator; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces_Template { static FastReader scan =new FastReader(); static final Random random=new Random(); static long mod=1000000...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
f21726b927a1e2ac9bb762d74599d156
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Main { public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } private static final int modulo = 1000000007; private static int evenCount = 0; pri...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
92bb86f4e49dfaddfb78a32630612604
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
/** * Surly * 21.10.2022 **/ import java.util.*; import java.math.*; import java.io.*; public class Main { static Scanner sc = new Scanner(System.in); static PrintWriter pr = new PrintWriter(System.out); public static void main (String[] args) throws IOException{ double starttime = System.curr...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b5d04e2c6abcfce2dae061ac87de0e31
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; 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 [] d = new int[n]; int [] a = new int[n]; for(int i=0;i<n;i++) d[i...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
0eaeb1c804231be36614d38bdf4a399d
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
// Source: https://usaco.guide/general/io import java.io.*; import java.util.*; public class Main { 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[] d = new in...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
f5cfbcc11632d5d011ec49ac2b083671
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class P1739B { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testcases = scanner.nextInt(); String[] out = new String[testcases]; for (int i = 0; i < testcases; i++) { int[] d = new int[scanner.nextInt()]; int[] a...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
51b351847a4e1bdfbfa7484ede3402bb
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
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.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class Main{ static class FastReader{ BufferedRe...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
c69cacf35f39bd5b71716a3b0e58b876
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class Array_Recovery { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextInt(); long arr[] = new long[(int) n]; for (long i = 0; i ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b80b7b4866ce7f56975534a7d73067d0
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-- > 0){ int n = Integer.parseInt(...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
3a331ad720cd3edc46dc14962ef18a43
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Codechef { public static void main(String[]args){ Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0) { //System.out.println(solve(sc)); solve(sc); } sc.close(); } public static void solve(Scanner s...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
da8b1acbad3ec0dca2b4bd5329fac08e
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; import java.security.*; public class solution { public static void main(String[] args) throws Exception { Scanner input; try { File file = new File("/home/harsh/Documents/Codes/input.txt"); FileInputStream fis = new FileInputStr...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
0957c245536b3b077f8eecb1f8c2ac5b
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[]args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-->0) { int n = in.nextInt(); int[] d = new int[n]; int[] a = new int[n]; boolean pos = true; for (int i=0; i<n; i++) { d[i] ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
7246a673ddfa802a991428421afe8d3c
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static int[] array(BufferedReader br,int n) throws IOException{ String [] values = br.readLine().split(" "); int [] arr = new int[n]; for(int i =0; i<n; i++){ arr[i] = Integer.parseInt(values[i]); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
e1be1ee02bb298f9ca1e2a457d81253f
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.lang.System.*; public class Main implements Runnable { @SuppressWarnings("unchecked") private final void process() throws IOException { // InputReader input = new InputReader(new FileReader(System.getenv("I...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
a2846611abf9b60beb6cf9356bd3475d
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class 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 arr[] = new int[n]; arr[0] = sc.nextInt(); boolean ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
7ff557a6f0f8930a00a433a509c707dc
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class ArrayRecovery { public static void main(String[] args) { Scanner pratiksc = new Scanner(System.in); int t = pratiksc.nextInt(); while (t-- > 0) { int n = pratiksc.nextInt(); int d[] = new int[n]; for (int i = 0; i...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
1a7117123e2d4cec78124f2890deb4db
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; public class Solution extends Helper { private static SuperFastReader sc = new SuperFastReader(); // private static final FastReader sc = new FastReader(); // private static final Scanner sc = new Scanner(System.in); private static PrintWriter out = new PrintWriter...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
e8d48eb130529ee26dc8230dbaa6e62e
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
//https://codeforces.com/contest/1739/problem/B import java.util.*; public class Array_Recovery_1739B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int d[] = new i...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
dc6c14b77f914520819aac6b8c6bdd86
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class MyClass { static class Pair implements Comparable<Pair> { int v, i; Pair(int v, int i) { this.v = v; this.i = i; } public int compareTo(Pair p) { if (p.v == v) return i - p.i; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
fae197ea3b412f794132e9eb2e73a059
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); for(int t = 0; t < test; ++t){ int n = sc.nextInt(); long[] arr = new long[n]; for(int i = 0; i<n; ++i){...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
8f4f9faffbb9b803100f0389c95767e9
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class ArrRecOBSERVATION { static int[] Solve(int[] d,int n) { int a[] = new int[n]; a[0] = d[0]; for(int i=1;i<n;i++) { int forwardDiff = a[i-1] + d[i]; int backwardDiff = a[i-1] - d[i]; if(backwar...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
5ad380468899a21bbcd89c618dea4a97
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
// package com.adhok; 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 arr[]=new int[n]; for(int i=0;i<n;...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
4247e40f2c0ccc700218b79a15f43ba3
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
69feac1ef4d79ce77bd472aba08ac962
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import static java.lang.Integer.*; public class codeforces { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int d[] = new int[n]; for(int i...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
234f397096736d30469fd7cee9bdf4a8
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class ArrayRecovery { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int n; boolean moreThanOne; int[] d = new int[107]; while (t > 0) { moreThanOne = false; n = sc.nextInt(); for (int j=0; j<n; j++) d...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
0114d37e68872a2a81f4e44dfae13739
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Solution { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t--!=0) { int n=in.nextInt(); int[]arr=new int[n]; int f=0; for(int i=0;i<...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
df88d45678a3819aff435c07d3d27fab
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; // Import the Scanner class import java.util.Arrays; public class solve { private static Scanner sc = new Scanner(System.in); public static void solve1(){ int n = sc.nextInt(); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
28e6a1eb8cb1b36254d983ccc49bf634
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class CF_1736B_ArrayRecovery { public static void f(int n, int[] d) { int[] a = new int[n]; a[0] = d[0]; for (int i = 1; i < n; i++) { if (d[i] == 0 || a[i - 1] - d[i] < 0) { a[i] = a[i - 1] + d[i]; } else { System.out.println(-1); return; } ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
68573d81871acd38edcc80acec75b3a1
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException{ new Main().run(); } void run()throws IOException{ new Solve().setIO(System.in,System.out).run(); } public class Solve extends IOTask{ ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
785a303dbef1b6e05e5e1e469bf6d97a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class CodeCodechef { static BufferedWriter put = new BufferedWriter(new OutputStreamWriter(System.out)); public...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
ef195be9f6d89feee4b085f1ae874db4
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Arrays; import java.util.Scanner; import java.util.stream.Collectors; 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[] d = new int...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
d3eed30aef7fd8aab5918a936b2da459
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class problemB { public static void main(String[] args) { Scanner sh = new Scanner(System.in); int t = sh.nextInt(); while(t>0){ int n = sh.nextInt(); int d[] = new int[n]; boolean x = true; for(int i = 0 ; i<n; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
753dfaf94c8957f219e4c411496639a5
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class arrayRecovery { public static void main(String[] args) throws IOException { Reader r = new Reader(); int t = r.nextInt(); List<Integer[]> answers = new ArrayList<>();...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b4a32db5fc91716a91d638d7da50433e
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.util.*; public class A { static int mod = (int) (1e9 + 7); public static void main(String[] args) throws IOException { // Scanner sc = new Scanner(new File("second_hands_input.txt")); // PrintWriter pw = new PrintWriter("seco...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
0d64a8764e264be054a8d212eddb9f01
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. ***********************************************...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
710422c899e8ca67ef3d1b34feb9e26a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; import java.util.ArrayList; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int e=0; e<t; e++) { int n=sc.nextInt(); boolean nice=true; // |arr1[x]-arr1[x-1]|=arr[x] ==> arr1[x]=arr1[x-1]-arr[x]...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
0e7b42ffa504acba455ddc82439fbea8
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Arrays; import java.util.Scanner; import java.util.stream.Collectors; 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[] d = new int[n]; fo...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
d50bf8e0f5812a663b9ab2ab4ed593b2
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Main { public static void main(String[] str) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while (t-- != 0) { int n = scan.nextInt(); int[] d = new int[n]; boolean flg = false; for ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
e08468b50bbdb5051209e673bb0518e2
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; public class B_Array_Recovery { final int mod = 1000000007; static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
1a50beb028caa22c20c829b5bfd73b7c
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
/**/ import java.io.*; import java.util.*; import java.lang.*; public class ArrayRecovery { public static void main(String[] args) throws IOException{ FastReader s = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = s.nextInt(); while(t-->0){ int ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
e2dc0ceb430537e3d9dcce9c65e4341f
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.util.function.*; import java.io.*; // you can compare with output.txt and expected out public class RoundEdu136B { MyPrintWriter out; MyScanner in; // final static long FIXED_RANDOM; // static { // FIXED_RANDOM = System.currentTimeMillis(); // } final static String I...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
7b3545876e74f5dd77b7717512fc754f
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class codeForces { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
2e1a6c4a0bbfadfd906005781e66871c
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class forces { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t; t=sc.nextInt(); while(t-->0) { int N; N=sc.nextInt(); int i; int A[]=new int[N]; int a[]=new int[N]; A[0]=sc.nextInt(); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
dd409169ffb68282720f1cd752e3dc1c
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class ede { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for (int i = 0; i < n; i++) { int size = scanner.nextInt(); int[] arrr = new int[size]; int[] che...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
fd431fee492347fa66513588d14ec27d
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int arr[]=new int[1000]; public static void main(String[] args) { Scanner s=new Scanner(System.in); long ts=s.nextLong(); while(ts-->0){ ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
96da296246bf5379e29fb72f13e0438f
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =new Scanner(System.in); int x = Integer.parseInt(input.next()); for (int i = 0; i < x; i++) { int n = input.nextInt(); int[] b = new int[n]; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
151833dbc7f1b6ae14ec6cfde6486749
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); int d[]=new int[n]; int a[]=new int[n]; for(int i=0;i<n;i++) { ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
4827133618bb770ea6c9aea3a13bc2c2
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { // Use the Scanner class Scanner sc = new Scanner(System.in); int t = sc.nextInt(); //System.out.println("t:"+t); int i=0; while(i<t) { int n = sc.nextInt(); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
f21dd732f23558be1d663f3dfd9fe09b
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class test { 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 = new int[n]; bool...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
6afd025992d78f84b637db798d553781
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class A1{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st; static final long mod=1000000007; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b5013eecadd15849cc14b0aa63358512
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class cf_arrayrecov{ public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ int n=sc.nextInt(); int[] d=new int[n]; int[] a=new int[n]; for(int j=...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b6368fe6b84f59f8afb20651c2d8f939
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class A { static InputReader in; static OutputWriter out; public static void main(String[] args) { in = new InputReader(System.in); out = new OutputWriter(System.out); if (System.getProperty("ONLINE_JUDGE") == null) { ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
30b89d10bc612af230688ef010548132
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Cont1{ public static void main(String[] args) { Scanner sc = new Scanner (System.in); int t= sc.nextInt(); for(int z=0;z<t;z++){ int n=sc.nextInt(); int [] d = new int [n]; for(int i=0;i<n;i++){ d[i...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
5424c7dbe0faa62826de70b16b68d851
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
//https://codeforces.com/contest/1739/problem/B import java.util.*; public class Array_Recovery_1739B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int drr[] = new...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
f9098385a9879f4ab783e453904d03ac
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
//My code is my Identity import java.util.Arrays; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; public class prog4 { /** * @param args */ public static void main(String...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
798b79312b43cb00a213f79701e43526
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class problem { 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 = new int[n]; int [] d = new int[n]; for ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
be1e1f9ccd220e005b9a424d5e3de252
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; import static java.lang.System.*; import static java.lang.System.out; import static java.lang.Ma...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
ee1be6b8062969e60d3f94eeffa95ac7
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Test1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] drr = new int[n]; for(int i=0;i<n;i++) drr[i] = sc.nextInt(); int[] arr = new int[n]...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
1ccaf1d2adbc45fef53ffe4fc5e15955
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class CF_1736B_ArrayRecovery { public static void f(int n,int[] d) { int[] a=new int[n]; a[0]=d[0]; for(int i=1;i<n;i++) { if(d[i]==0||a[i-1]-d[i]<0) { a[i]=a[i-1]+d[i]; }else { System.out.println(-1); return; } } for(int i=0;i<n;i++) { ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
6c974f6b22fb012317e3d8627976a395
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class B { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int t = scanner.nextInt(); while(t-- > 0) { solve(); } } static void solve() { int n = scanner.nextInt(); in...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
af0897e1bde9fb6c3abbc3f2887db16b
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class MAIN { static void print(int[] arr) { int[] lst = new int[arr.length]; int sum = arr[0]; lst[0] = sum; for (int i = 1; i < arr.length; i++) { if (arr[i] > 0 && sum >= arr[i]) { System.out.println(-...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
3e61eaa22976658d6048bfde783b532a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import static java.lang.Math.*; public class Solution { static FastReader fastReader = new FastReader(); public static void main(String[] args) { int t = fastReader.nextInt();...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
cc29ae5bb0d95eed166cbf9efec1e973
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class B { final static boolean multipleTests = true; Input in; PrintWriter out; public B() { in = new Input(System.in); out = new PrintWriter(System.out); } public static void main(String[] args) { B solution =...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
c045bba9b0f7eee0725fe1f40ea84130
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solution { public static class CFScanner { BufferedReader br; StringTokenizer st; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
d1c2cb1c7c019013450e1b25d9339a3a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
/** * @author vivek * <> */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class B { private static void solveTC(int __) { /* For Google */ // ans.append("Case #").append(__).append(": "); //code start...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 17
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
74e98c32f66f4e854e6a238e77b28c92
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class cf { public static void main(String[] args) { Scanner css = new Scanner(System.in); int t = css.nextInt(); for (int i = 0; i < t; i++){ int n = css.nextInt(); int[] arr = new int[n]; int[] new_arr1 = new int[n...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
c1ae035d27859b81fd675f9d25d07328
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; @SuppressWarnings("unused") public class B_Array_Recovery { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); out: while (t-- > 0) { int n = sc.nextInt()...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
e6bf93a862b3d0bb80325bb8712e7c11
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class ArrayRecovery{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ t--; int n = sc.nextInt(); int[] d = new int[n]; // int sum=0; // boolean allSame=true; for(int i=0; i<n; i++){ d[i] = sc.next...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
e3f7be7060db7a3ca0941f259af517d5
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String[] args) throws IOException{ FastScanner fs=new FastScanner(); Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStream...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
675798a04ec9d1c46a1c3276a706f8fc
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.text.DecimalFormat; import java.util.*; public class Solution { static BufferedReader bf; static PrintWriter out; static Scanner sc; static StringTokenizer st; static long mod = (long)(1e9+7); static long mod2 = 998244353; static long fact[] ; static long inverse[]; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
d607977127fb1467b879ef48a2745adb
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; public class solve{ public static void main (String[] args) { int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); int d[]=sc.Array(n); if(n>=2) { int flag=0; List<Integer> ls=new ArrayList<>(); ls.add(d[0]); for(int i=1;i<n;i++) { if(...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
afec06e9b1186018629d43806a3bf678
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; public class Balabizo { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-->0) { int n = sc.nextInt()...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
3c53659e9b20792bc4714cf5e04a327e
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.io.*; public class Balabizo { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-->0) { int n = sc.nextInt()...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
d6ed653bb018c1b946166ed9639af185
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class 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 d[] = new int[n]; int a[] = new int[n]; for(int i = 0; i < n; i++) { d[i] = sc.nextI...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
20923051b9dc95c5752731b763bf53c0
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class 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 d[] = new int[n]; int a[] = new int[n]; for(int i = 0; i < n; i++) { d[i] = sc.nextI...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
9cbeb96ac86ca3e38179d9aa53aae865
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class EDR136{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++){ int n = sc.nextInt(); int[] a = new int[n]; int[] d = new int[n]; int result = 0, count = 0; for(int j = 0; j < n;...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
8d5d63941334c49de9ab8299b3915430
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public final class B_Array_Recovery { //int 2e9 - long 9e18 int test=12344; static PrintWriter out = new PrintWriter(System.out); static FastReader fs ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
305ae4f5527b337147efb3a48d415a2a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.*; public class B { public static void main(String[] args){ FastReader fs=new FastReader(); PrintWriter out=new P...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
fd2c5620b9cb06d458f68738620f51fd
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class _136B { 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 d[] = new int[n]; boolean flag = false; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
b18221f09f7ee34d46e2d6d738db3045
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class test { static PrintWriter pw; public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); pw = new PrintWriter(System.out); int t =sc.nextInt(); while(t-->0) { int n = sc.ne...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
aa2ca575cd8037e72027073b4b2b27ca
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Main{ static int T,N; static int[] nums=new int[110],res=new int[110]; public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(S...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
7e409f15f014e790576fe7ec021c2d8b
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
//import com.aspose.words.Document; //import com.aspose.words.FontSettings; import java.util.Arrays; import java.util.Scanner; /** * Hello world! * */ public class App { public static void main( String[] args ) throws Exception { // Document doc = new Document("C:\\Users\\obenchennou...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
69887c602b86071129ce30ce2a361b40
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.*; import java.util.*; public class B_Array_Recovery { public static void solve(int[] A){ int t = 0; StringBuffer sb = new StringBuffer(); for(int i = 0; i < A.length; i++){ if(i>0 && A[i] != 0 && (t+A[i] >= 0) && (t-A[i] >=0)){ Syst...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
505d4f167fd33f1943169918190fe7d0
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class ArrayRecovery { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int testCases= sc.nextInt(); for (int i = 0; i < testCases; i++) { int n= sc.nextInt(); int array[] = new in...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
83b2001138bab5612bea0a2b0fcc0973
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
// OM NAMAH SHIVAY // 32 days remaining(2609) import java.math.BigInteger; import java.util.*; import java.io.*; public class V { static long bit[]; static boolean prime[]; static class Pair { int a; int b; Pair(int a, int b ) { this.a = a; ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
33d766a61de614fadf5b694d28244cac
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
// "static void main" must be defined in a public class. import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int T = fs.nextInt(); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
9a9341e0895fa8ac5dc2b160adc2511f
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextInt(); while (n-- > 0) { int m = in.nextInt(); int[] temp = new int[m]; for (int i = 0; i < m; i++) { ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
23530d90c84a993f86083e3f8927cce6
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static class Pair { int key, value; public Pair(int key, int value) { this.key = key; this.value = value; } }...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
8095ccfd4cbf3cb8690e0507d7ed116a
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.awt.*; import java.util.*; import java.io.*; // You have that in you, you can do it........ public class Codeforces { static FScanner sc = new FScanner(); static PrintWriter out = new PrintWriter(System.out); static final Random random = new Random(); static long mod = 1000000007L;...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
7ce9caf2e2e78ba90c9cbdc19264f777
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Scanner; public class arrayGeneration { public static void main(String[]args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i<t ; i++) { boolean flag= true; int n= sc.nextInt(); int[]a= new int [n]; int[]b= new int [n]; for(int j=0; j<n;j++)...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
a0300096981957e985cb2800ea77b4a2
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
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(); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
af4be5fa9a9606ca60ede5f136077769
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t= sc.nextInt(); for(int i=0;i<t;i++){ int n=sc.nextInt(); int [] arr= new int[n]; for(int ii=0;ii<n;ii++){ ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
cbe410af7a877153aaddef00d40a3f61
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
/* This code is written by KESHAV DAGA @keshavkeshu */ import java.util.*; import java.io.*; public class Main { static FastReader sc=new FastReader(); static final Random random=new Random(); static int mod=1000000007; static int inf=Integer.MAX_VALUE; static int ninf=Inte...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
88149b136adf496000b6fec57db1d304
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class main //class contest { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); ...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output
PASSED
fbd4fb500ddb1da29d43f8eda96f2ec9
train_109.jsonl
1664462100
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class arrayRes{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int[] d = new int[n]; for (int i = 0; i < d.l...
Java
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
Java 8
standard input
[ "constructive algorithms", "greedy", "math" ]
f4b790bef9a6cbcd5d1f9235bcff7c8f
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
1,100
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
standard output