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 | 276aee6510c03bd05321bcfab6cb4201 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.util.*;
public class MinimumExtraction {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
Integer arr[]=new Integer[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
}
Arrays.parallelSort(arr);
int max=arr[0];
for(int i=1;i<n;i++) {
max=Math.max(max,arr[i]-arr[i-1]);
}
System.out.println(max);
}
}
}
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileReader;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.Arrays;
//import java.util.StringTokenizer;
//
//public class Solution {
//static PrintWriter pw;
//static FastScanner s;
//
//
//public static void main(String[] args) throws Exception {
// pw=new PrintWriter(System.out);
// s=new FastScanner(System.in);
// int t=s.nextInt();
// while(t-->0) {
// int n=s.nextInt();
// int a[]=new int[n];
// for(int i=0;i<n;i++)
// a[i]=s.nextInt();
//
// Arrays.parallelSort(a);
// int ans=a[0];
// for(int i=1;i<n;i++) {
// ans=Math.max(a[i]-a[i-1], ans);
// }
// pw.println(ans);
//
//
// }
//
//pw.flush();
//}
//
//}
//class FastScanner{
// BufferedReader br;
// StringTokenizer st;
// public FastScanner(InputStream s) {
// br = new BufferedReader(new InputStreamReader(s));
// }
//
// public FastScanner(String s) throws Exception {
// br = new BufferedReader(new FileReader(new File(s)));
// }
//
// public String next() throws Exception {
// while (st == null || !st.hasMoreTokens())
// st = new StringTokenizer(br.readLine());
// return st.nextToken();
// }
//
// public int nextInt() throws Exception {
// return Integer.parseInt(next());
// }
//
// public long nextLong() throws Exception {
// return Long.parseLong(next());
// }
//}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 5786274cb8c811f2af5b06cb2813a333 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class C_Minimum_Extraction {
public static void main(String[] arg) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
Long[] arr = new Long[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextLong();
}
Arrays.sort(arr);
long max = arr[0];
for (int i = 1; i < n; i++) {
max = Math.max(max, arr[i] - arr[i - 1]);
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a400c2bdadac40ced42b246d0c1f8819 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class C_Minimum_Extraction {
public static void main(String[] arg) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
Long a[] = new Long[n];
for (int i = 0; i < n; i++) {
a[i] = s.nextLong();
}
Arrays.sort(a);
long res = a[0];
for (int i = 0; i < n - 1; i++) {
res = Math.max(res, a[i + 1] - a[i]);
}
System.out.println(res);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | b16766d842fdc280379752538f341088 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.util.Scanner;
public class MinimumExtract{
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
Integer ar[]= new Integer[n];
for (int i =0;i<n;i++){
ar[i]= sc.nextInt();
}
Arrays.sort(ar);
int min = ar[0];
int minS = ar[0];
for (int i=1;i<n;i++){
ar[i]-=minS;
minS+=ar[i];
if (ar[i]>min) min = ar[i];
}
System.out.println (min);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 480cd00326a33a1894f524e40c0f95fc | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.util.Scanner;
public class MinimumExtrat{
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
Integer ar[]= new Integer[n];
for (int i =0;i<n;i++){
ar[i]= sc.nextInt();
}
Arrays.parallelSort(ar);
int min = ar[0];
for (int i=1;i<n;i++){
min = Math.max (min,ar[i]-ar[i-1]);
}
System.out.println (min);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 2acf2b5372f268a400cda0069cc6964d | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.util.Scanner;
public class MinimumExtract{
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
Integer ar[]= new Integer[n];
for (int i =0;i<n;i++){
ar[i]= sc.nextInt();
}
Arrays.parallelSort(ar);
int min = ar[0];
for (int i=1;i<n;i++){
min = Math.max (min,ar[i]-ar[i-1]);
}
System.out.println (min);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 7218dd6750f8d74b2bdd89e7f9303c65 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class MinimumExtraction {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
Integer arr[]=new Integer[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
}
Arrays.parallelSort(arr);
int max=arr[0];
for(int i=1;i<n;i++) {
max=Math.max(max,arr[i]-arr[i-1]);
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | cd3de5535861251bdab09e5c59fe6432 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class MinimumExtraction {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
for (int i = 1; i <= t; i++) {
int n = in.nextInt();
ArrayList<Long> a = new ArrayList<>();
for (int j = 0; j < n; j++) {
a.add(in.nextLong());
}
Collections.sort(a);
if (n == 1) {
out.println(a.get(0));
}
else {
long biggestGap = a.get(0);
for (int j = 1; j < n; j++) {
long gap = a.get(j) - a.get(j - 1);
if (gap > biggestGap) {
biggestGap = gap;
}
}
out.println(biggestGap);
}
}
out.close();
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// noop
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | c18e429e2f0edb36206d51522ae85723 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
*
* @author Acer
*/
public class MaximumExtraction_c {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-- > 0){
int n = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
arr.add(sc.nextInt());
}
if(n == 1){
System.out.println(arr.get(0));
continue;
}
Collections.sort(arr);
long prev = arr.get(0);
long max = arr.get(0);
long ans = 0;
for (int i = 1; i < n; i++) {
ans = arr.get(i)-prev;
prev = prev+ans;
max = Math.max(max, ans);
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 9f1336bcfd8ab7b39263c26a05d0dac9 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
*
* @author Acer
*/
public class MaximumExtraction_2c {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-- > 0){
int n = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
arr.add(sc.nextInt());
}
if(n == 1){
System.out.println(arr.get(0));
continue;
}
Collections.sort(arr);
long max = arr.get(0);
for (int i = 1; i < n; i++) {
long x = arr.get(i) - arr.get(i-1);
max = Math.max(max, x);
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 16273418087808bb8c340a93f8b8e7ea | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /*Author: Jatin Yadav*/
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.*;
import static java.lang.Math.max;
public class practice {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[1000001]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
//GCD CALCULATION
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
//BINARY EXPONENTIATION
public static long binpow(long a, long b) {
long res = 1;
while (b > 0) {
if ((b & 1) == 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
// Returns factorial of n
static int fact(int n) {
if (n == 0)
return 1;
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
public static void main(String args[]) throws IOException {
Reader s = new Reader();
int t = s.nextInt();
//int t = 1;
while (t-- > 0) {
int n =s.nextInt();
Long a[] = new Long[n];
for(int i=0; i<n; i++){
a[i] = s.nextLong();
}
Arrays.sort(a);
for(int i=n-1; i>0; i--){
a[i] = a[i]-a[i-1];
}
long max = Integer.MIN_VALUE;
for(int i=0; i<n; i++){
max = Math.max(max,a[i]);
}
if(n==1){
System.out.println(a[0]);
}else{
System.out.println(max);
}
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 5f82c3ff3410850cf22a0132af119dbe | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /*Author: Jatin Yadav*/
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.*;
import static java.lang.Math.max;
public class practice {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[1000001]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
public static void main(String args[]) throws IOException {
Reader s = new Reader();
int t = s.nextInt();
//int t = 1;
while (t-- > 0) {
int n =s.nextInt();
Long a[] = new Long[n];
for(int i=0; i<n; i++){
a[i] = s.nextLong();
}
Arrays.sort(a);
long ans = a[0];
long d = -a[0];
for (int i = 1; i < n; i++) {
a[i] += d;
ans = Math.max(ans, a[i]);
d -= a[i];
}
System.out.println(ans);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 6b37ffaf97da8d66dec2cbcca948ebb0 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
while (n-- > 0) {
int a = in.nextInt();
int[] arr = new int[a];
PriorityQueue<Integer> qu = new PriorityQueue<>();
for (int i = 0; i < a; i++) {
arr[i] = in.nextInt();
qu.add(arr[i]);
}
if (a == 1) System.out.println(arr[0]);
else {
int max = qu.peek();
int t1;
int t2 = 0;
for (int i = 0; i < a; i++) {
t1 = qu.poll();
max = Math.max(max, t1 - t2);
t2 = t1;
}
System.out.println(max);
}
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 6584776b019c44d385663c6345dc67fe | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class MinExtraction {
public static void main(String[] args) {
int testCases=0;
Scanner sc=new Scanner(System.in);
testCases=sc.nextInt();
sc.nextLine();
for(int i=1;i<=testCases;i++){
int len=sc.nextInt();
Integer arr[]=new Integer[len];
sc.nextLine();
for(int j=0;j<len;j++){
arr[j]= sc.nextInt();
}
if(len==1)
System.out.println(arr[0]);
else{
int max=0;
Arrays.sort(arr);
max=arr[0];
for(int k=1;k<len;k++){
int currDiff=arr[k]-arr[k-1];
max=max>currDiff?max:currDiff;
}
System.out.println(max);
}
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 7ee2841044da40889f4c151e1d91a599 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt() ;
while (n -- != 0){
int length = sc.nextInt() ;
List<Integer> list = new ArrayList<>() ;
for(int i = 0 ; i < length ; i ++){
list.add(sc.nextInt() ) ;
}
Collections.sort(list);
int max = list.get(0) ;
for(int i = 1 ; i < list.size() ; i ++){
max = Math.max(max , list.get(i) - list.get(i - 1)) ;
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 867ca52e859112d7340dc6976917d6f3 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | //package div3_753;
import java.util.*;
public class MinExtract_C {
private static int getMinExtract(List<Integer>list,int len) {
Collections.sort(list);
int Min=list.get(0);
for(int i=0;i<len-1;i++)
Min=Math.max(Min, list.get(i+1)-list.get(i));
return Min;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int test_case=in.nextInt();
while(test_case-->0) {
int len=in.nextInt();
List<Integer>list=new ArrayList<>();
for(int i=0;i<len;i++)
list.add(in.nextInt());
int res=getMinExtract(list,len);
System.out.println(res);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 48072ccd066aa2fa73b26ce643e733fe | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class Soltion{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
long t = sc.nextLong();
while(t-->0){
int n = sc.nextInt();
Integer[] arr = new Integer[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
long min = arr[0];
for(int i=0;i<n-1;i++){
min = Math.max(min, arr[i+1]-arr[i]);
}
System.out.println(min);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 06ebe04a93b746fea7db828effa7bccb | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
long t=sc.nextLong();
while(t-->0)
{
int n=sc.nextInt();
Integer arr[]=new Integer[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
long ans=arr[0];
for(int i=0;i<n-1;i++)
{
ans=Math.max(arr[i+1]-arr[i],ans);
}
System.out.println(ans);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 17b011c0fc2140398a7569503e7c8446 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int t = in.nextInt(); t > 0; t--) {
int n = in.nextInt();
SortedSet<Integer> sortedSet = new TreeSet<>();
for (int i = 0; i < n; i++) sortedSet.add(in.nextInt());
long maxMin = sortedSet.first(), pre = sortedSet.first();
for (int e: sortedSet) {
maxMin = Math.max(maxMin, e - pre);
pre = e;
}
if (n == 1) maxMin = sortedSet.first();
if (n > sortedSet.size() && maxMin < 0) maxMin = 0;
System.out.println(maxMin);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 9bde713303a761144ba2378f36e7acff | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class MinumumExtraction {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
Integer a[]=new Integer[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
}
Arrays.parallelSort(a);
long max=a[0];
for(int i=1;i<n;i++) {
max=Math.max(max,a[i]-a[i-1] );
}
System.out.println(max);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a6407e2ca990ab81a149c42655218862 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class MinimumExtraction
{
public static void shuffleArray(int[] arr){
int n = arr.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
int tmp = arr[i];
int randomPos = i + rnd.nextInt(n-i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-- > 0)
{
int n = scan.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++)
a[i] = scan.nextInt();
int res = -1000000001;
shuffleArray(a);
Arrays.sort(a);
int i=0;
int total = 0;
while(i<n)
{
int minVal = a[i++];
res = Math.max(res, minVal);
total+=minVal;
if(i<n)
a[i]-=total;
}
System.out.println(res);
}
scan.close();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | f4290449bc2fbd914d0fdb23dce68718 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class MinimumExtraction
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-- > 0)
{
int n = scan.nextInt();
Long a[] = new Long[n];
for(int i=0;i<n;i++)
a[i] = scan.nextLong();
long res = -1000000001;
Arrays.sort(a);
int i=0;
long total = 0;
while(i<n)
{
long minVal = a[i++];
res = Math.max(res, minVal);
total+=minVal;
if(i<n)
a[i]-=total;
}
System.out.println(res);
}
scan.close();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | c80c16ce140e0efe2ebecb9c98e8ac20 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
static FastReader in;
static PrintWriter out;
static int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
static void p(Object o) {
out.print(o);
}
static void pn(Object o) {
out.println(o);
}
static void pni(Object o) {
out.println(o);
out.flush();
}
static String n() throws Exception {
return in.next();
}
static String nln() throws Exception {
return in.nextLine();
}
static int ni() throws Exception {
return Integer.parseInt(in.next());
}
static long nl() throws Exception {
return Long.parseLong(in.next());
}
static double nd() throws Exception {
return Double.parseDouble(in.next());
}
static class FastReader {
static BufferedReader br;
static StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
static long power(long a, long b) {
if (b == 0)
return 1;
long val = power(a, b / 2);
val = val * val;
if ((b % 2) != 0)
val = val * a;
return val;
}
static ArrayList<Long> prime_factors(long n) {
ArrayList<Long> ans = new ArrayList<Long>();
while (n % 2 == 0) {
ans.add(2L);
n /= 2;
}
for (long i = 3; i <= Math.sqrt(n); i++) {
while (n % i == 0) {
ans.add(i);
n /= i;
}
}
if (n > 2)
ans.add(n);
return ans;
}
static void sort(long[] a) {
Arrays.sort(a);
}
static void reverse_sort(long[] a) {
Arrays.sort(a);
for (int i = 0; i < a.length; i++) {
long temp = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = temp;
}
}
static void sort(ArrayList<Long> a) {
Collections.sort(a);
}
static void reverse_sort(ArrayList<Long> a) {
Collections.sort(a, Collections.reverseOrder());
}
static void temp(long[] a, int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static void temp(List<Long> a, int i, int j) {
long temp = a.get(i);
a.set(j, a.get(i));
a.set(j, temp);
}
static void sieve(boolean[] prime) {
int n = prime.length - 1;
Arrays.fill(prime, true);
for (int i = 2; i * i <= n; i++) {
if (prime[i]) {
for (int j = 2 * i; j <= n; j += i) {
prime[j] = false;
}
}
}
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long mod = 1000000007;
static class pair implements Comparable<pair> {
long x, y;
public pair(long x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(pair p) {
return this.y * (p.x - 1L) > p.y * (this.x - 1L) ? 1 : -1;
}
}
public static void main(String[] args) throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int t = ni();
while (t-- > 0) {
int n = ni();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nl();
}
merge_sort(arr,0,n-1);
if (n == 1) {
pn(arr[0]);
continue;
}
long[] a = new long[n - 1];
for (int i = 1; i < n; i++) {
a[i - 1] = arr[i] - arr[0];
}
merge_sort(a,0,a.length-1);
long ans = Math.max(a[0],arr[0]);
long diff = a[0];
for (int i = 0; i < a.length; i++) {
ans = Math.max(ans, a[i] - diff);
if (i != 0)
diff += a[i] - a[i - 1];
}
pn(ans);
}
out.flush();
out.close();
}
public static void merge_sort(long[] arr, int l, int r){
if(l>=r)return ;
int mid=(l+r)/2;
merge_sort(arr, l, mid);
merge_sort(arr, mid+1, r);
merge(arr,l,mid,r);
}
static void merge(long[] arr, int l, int mid, int r){
long[] left=new long[mid-l+1];
long[] right=new long[r-mid];
for(int i=l;i<=mid;i++){
left[i-l]=arr[i];
}
for(int i=mid+1;i<=r;i++){
right[i-(mid+1)]=arr[i];
}
int left_start=0;
int right_start=0;
int left_length=mid-l+1;
int right_length=r-mid;
int temp=l;
while(left_start<left_length && right_start<right_length){
if(left[left_start]<right[right_start]){
arr[temp]=left[left_start++];
}else{
arr[temp]=right[right_start++];
}
temp++;
}
while(left_start<left_length){
arr[temp++]=left[left_start++];
}
while(right_start<right_length){
arr[temp++]=right[right_start++];
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | b01c045c22f8d89cedb3c5916d6fb501 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.awt.image.AreaAveragingScaleFilter;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while (t>0) {
t--;
int n = sc.nextInt();
ArrayList<Integer>arr = new ArrayList<>();
for (int i = 0 ; i < n ; i++){
int x =sc.nextInt();
arr.add(x);
}
if(n==1) {
System.out.println(arr.get(0));continue;
}
Collections.sort(arr);
ArrayList<Integer>ans = new ArrayList<>();
ans.add(arr.get(0));
for (int i = 1 ; i < arr.size();i++){
ans.add(arr.get(i)-arr.get(i-1));
}
System.out.println(Collections.max(ans));
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 77487bd0cd5f59ffec55d6965c9862e5 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
//import javafx.util.*;
public class Main
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
//static ArrayList<ArrayList<TASK>> t;
static long mod=(long)(1e9+7);
static boolean set[],post[][];
static int prime[],c[];
static int par[];
// static int dp[][];
static HashMap<String,Long> mp;
static long max=1;
static boolean temp[][];
static int K=0;
static int size[],dp[][],iv_A[],iv_B[];
static long modulo = 998244353;
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
int t=i();
while(t-->0){
int n=i();
Long[] a=new Long[n];
for(int i=0;i<n;i++){
a[i]=in.nextLong();
}
Arrays.sort(a);
long M=a[0];
for(int i=0;i<n-1;i++){
if(a[i+1]-a[i]>M)M=a[i+1]-a[i];
}
System.out.println(M);
}
}
static boolean check_cycle(int[] arr, int x, int y, int z){
boolean ans = true;
boolean x_check = false;
boolean y_check = false;
boolean z_check = false;
int n = arr.length;
for(int i = 0;i < n;i++){
if(arr[i] == x){
x_check = true;
if(y_check){
ans = false;
break;
}
if(z_check){
ans = false;
break;
}
}
if(arr[i] == y){
y_check = true;
if(!x_check){
ans = false;
break;
}
if(z_check){
ans = false;
break;
}
}
if(arr[i] == z){
z_check = true;
if(!x_check){
ans = false;
break;
}
if(y_check){
ans = false;
break;
}
}
}
return ans;
}
static int MinimumFlips(String s, int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = (s.charAt(i) == '1' ? 1 : 0);
}
// Initialize prefix arrays to store
// number of changes required to put
// 1s at either even or odd position
int[] oddone = new int[n + 1];
int[] evenone = new int[n + 1];
oddone[0] = 0;
evenone[0] = 0;
for (int i = 0; i < n; i++) {
// If i is odd
if (i % 2 != 0) {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 1 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 0 ? 1 : 0);
}
// Else i is even
else {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 0 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 1 ? 1 : 0);
}
}
// Initialize minimum flips
return Math.min(evenone[n],oddone[n]);
}
static int nextPowerOf2(int n)
{
int count = 0;
// First n in the below
// condition is for the
// case where n is 0
if (n > 0 && (n & (n - 1)) == 0){
while(n != 1)
{
n >>= 1;
count += 1;
}
return count;
}else{
while(n != 0)
{
n >>= 1;
count += 1;
}
return count;
}
}
static int length(int n){
int count = 0;
while(n > 0){
n = n/10;
count++;
}
return count;
}
static boolean isPrimeInt(int N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
public static int lcs(int[] nums) {
int[] tails = new int[nums.length];
int size = 0;
for (int x : nums) {
int i = 0, j = size;
while (i != j) {
int m = (i + j) / 2;
if (tails[m] <= x)
i = m + 1;
else
j = m;
}
tails[i] = x;
if (i == size) ++size;
}
return size;
}
static int CeilIndex(int A[], int l, int r, int key)
{
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key)
r = m;
else
l = m;
}
return r;
}
static int f(int A[], int size)
{
// Add boundary case, when array size is one
int[] tailTable = new int[size];
int len; // always points empty slot
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0])
// new smallest value
tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1])
// A[i] wants to extend largest subsequence
tailTable[len++] = A[i];
else
// A[i] wants to be current end candidate of an existing
// subsequence. It will replace ceil value in tailTable
tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}
static int containsBoth(char X[],int N)
{
for(int i=1; i<N; i++)if(X[i]!=X[i-1])return i-1;
return -1;
}
static void f(char X[],int N,int A[])
{
int c=0;
for(int i=N-1; i>=0; i--)
{
if(X[i]=='1')
{
A[i]=c;
}
else c++;
A[i]+=A[i+1];
}
}
static int f(int i,int j,char X[],char Y[],int zero)
{
if(i==X.length && j==Y.length)return 0;
if(i==X.length)return iv_B[j]; //return inversion count here
if(j==Y.length)return iv_A[i];
if(dp[i][j]==-1)
{
int cost_x=0,cost_y=0;
if(X[i]=='1')
{
cost_x=zero+f(i+1,j,X,Y,zero);
}
else cost_x=f(i+1,j,X,Y,zero-1);
if(Y[j]=='1')
{
cost_y=zero+f(i,j+1,X,Y,zero);
}
else cost_y=f(i,j+1,X,Y,zero-1);
dp[i][j]=Math.min(cost_x, cost_y);
}
return dp[i][j];
}
static boolean f(long last,long next,long l,long r,long A,long B)
{
while(l<=r)
{
long m=(l+r)/2;
long s=((m)*(m-1))/2;
long l1=(A*m)+s,r1=(m*B)-s;
if(Math.min(next, r1)<Math.max(last, l1))
{
if(l1>last)r=m-1;
else l=m+1;
}
else return true;
}
return false;
}
static boolean isVowel(char x)
{
if(x=='a' || x=='e' || x=='i' ||x=='u' || x=='o')return true;
return false;
}
static boolean f(int i,int j)
{
//i is no of one
//j is no of ai>1
if(i==0 && j==0)return true; //this player has no pile to pick --> last move iska rha hoga
if(dp[i][j]==-1)
{
boolean f=false;
if(i>0)
{
if(!f(i-1,j))f=true;
}
if(j>0)
{
if(!f(i,j-1) && !f(i+1,j-1))f=true;
}
if(f)dp[i][j]=1;
else dp[i][j]=0;
}
return dp[i][j]==1;
}
static int last=-1;
static void dfs(int n,int p)
{
last=n;
System.out.println("n--> "+n+" p--> "+p);
for(int c:g[n])
{
if(c!=p)dfs(c,n);
}
}
static long abs(long a,long b)
{
return Math.abs(a-b);
}
static int lower(long A[],long x)
{
int l=0,r=A.length;
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<=x)l=m;
else r=m;
}
return l;
}
static int f(int i,int s,int j,int N,int A[],HashMap<Integer,Integer> mp)
{
if(i==N)
{
return s;
}
if(dp[i][j]==-1)
{
if(mp.containsKey(A[i]))
{
int f=mp.get(A[i]);
int c=0;
if(f==1)c++;
mp.put(A[i], f+1);
HashMap<Integer,Integer> temp=new HashMap<>();
temp.put(A[i],1);
return dp[i][j]=Math.min(f(i+1,s+1+c,j,N,A,mp), s+K+f(i+1,0,i,N,A,temp));
}
else
{
mp.put(A[i],1);
return dp[i][j]=f(i+1,s,j,N,A,mp);
}
}
return dp[i][j];
}
static boolean inRange(int a,int l,int r)
{
if(l<=a && r>=a)return true;
return false;
}
static long f(long a,long b)
{
if(a%b==0)return a/b;
else return (a/b)+f(b,a%b);
}
static void f(int index,long A[],int i,long xor)
{
if(index+1==A.length)
{
if(valid(xor^A[index],i))
{
xor=xor^A[index];
max=Math.max(max, i);
}
return;
}
if(dp[index][i]==0)
{
dp[index][i]=1;
if(valid(xor^A[index],i))
{
f(index+1,A,i+1,0);
f(index+1,A,i,xor^A[index]);
}
else
{
f(index+1,A,i,xor^A[index]);
}
}
}
static boolean valid(long xor,int i)
{
if(xor==0)return true;
while(xor%2==0 )
{
xor/=2;
i--;
}
return i<=0;
}
static int next(int i,long pre[],long S)
{
int l=i,r=pre.length;
while(r-l>1)
{
int m=(l+r)/2;
if(pre[m]-pre[i-1]>S)r=m;
else l=m;
}
return r;
}
static boolean lexo(long A[],long B[])
{
for(int i=0; i<A.length; i++)
{
if(B[i]>A[i])return true;
if(A[i]>B[i])return false;
}
return false;
}
static long [] f(long A[],long B[],int j)
{
int N=A.length;
long X[]=new long[N];
for(int i=0; i<N; i++)
{
X[i]=(B[j]+A[i])%N;
j++;
j%=N;
}
return X;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
b=find(b);
a=find(a);
if(a!=b)
{
par[b]=a;
}
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static long lower_Bound(long A[],int low,int high, long x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void setGraph(int N)
{
size=new int[N+1];
// D=new int[N+1];
g=new ArrayList[N+1];
for(int i=0; i<=N; i++)
{
g[i]=new ArrayList<>();
}
}
static long pow(long a,long b)
{
long pow=1L;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}
static long toggleBits(int x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;
return ((1<<n)-1)^x;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static long GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
}
class Pair{
int x;
int y;
Pair(int x,int y){
this.x = x;
this.y = y;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | c510dfa89b62ea39a83c85ccacef294b | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
//import javafx.util.*;
public class Main
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
//static ArrayList<ArrayList<TASK>> t;
static long mod=(long)(1e9+7);
static boolean set[],post[][];
static int prime[],c[];
static int par[];
// static int dp[][];
static HashMap<String,Long> mp;
static long max=1;
static boolean temp[][];
static int K=0;
static int size[],dp[][],iv_A[],iv_B[];
static long modulo = 998244353;
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
Long[] a=new Long[n];
for(int i=0;i<n;i++){a[i]=sc.nextLong();}
Arrays.sort(a);
long M=a[0];
for(int i=0;i<n-1;i++){
if(a[i+1]-a[i]>M)M=a[i+1]-a[i];
}
System.out.println(M);
}
sc.close();
}
static boolean check_cycle(int[] arr, int x, int y, int z){
boolean ans = true;
boolean x_check = false;
boolean y_check = false;
boolean z_check = false;
int n = arr.length;
for(int i = 0;i < n;i++){
if(arr[i] == x){
x_check = true;
if(y_check){
ans = false;
break;
}
if(z_check){
ans = false;
break;
}
}
if(arr[i] == y){
y_check = true;
if(!x_check){
ans = false;
break;
}
if(z_check){
ans = false;
break;
}
}
if(arr[i] == z){
z_check = true;
if(!x_check){
ans = false;
break;
}
if(y_check){
ans = false;
break;
}
}
}
return ans;
}
static int MinimumFlips(String s, int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = (s.charAt(i) == '1' ? 1 : 0);
}
// Initialize prefix arrays to store
// number of changes required to put
// 1s at either even or odd position
int[] oddone = new int[n + 1];
int[] evenone = new int[n + 1];
oddone[0] = 0;
evenone[0] = 0;
for (int i = 0; i < n; i++) {
// If i is odd
if (i % 2 != 0) {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 1 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 0 ? 1 : 0);
}
// Else i is even
else {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 0 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 1 ? 1 : 0);
}
}
// Initialize minimum flips
return Math.min(evenone[n],oddone[n]);
}
static int nextPowerOf2(int n)
{
int count = 0;
// First n in the below
// condition is for the
// case where n is 0
if (n > 0 && (n & (n - 1)) == 0){
while(n != 1)
{
n >>= 1;
count += 1;
}
return count;
}else{
while(n != 0)
{
n >>= 1;
count += 1;
}
return count;
}
}
static int length(int n){
int count = 0;
while(n > 0){
n = n/10;
count++;
}
return count;
}
static boolean isPrimeInt(int N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
public static int lcs(int[] nums) {
int[] tails = new int[nums.length];
int size = 0;
for (int x : nums) {
int i = 0, j = size;
while (i != j) {
int m = (i + j) / 2;
if (tails[m] <= x)
i = m + 1;
else
j = m;
}
tails[i] = x;
if (i == size) ++size;
}
return size;
}
static int CeilIndex(int A[], int l, int r, int key)
{
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key)
r = m;
else
l = m;
}
return r;
}
static int f(int A[], int size)
{
// Add boundary case, when array size is one
int[] tailTable = new int[size];
int len; // always points empty slot
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0])
// new smallest value
tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1])
// A[i] wants to extend largest subsequence
tailTable[len++] = A[i];
else
// A[i] wants to be current end candidate of an existing
// subsequence. It will replace ceil value in tailTable
tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}
static int containsBoth(char X[],int N)
{
for(int i=1; i<N; i++)if(X[i]!=X[i-1])return i-1;
return -1;
}
static void f(char X[],int N,int A[])
{
int c=0;
for(int i=N-1; i>=0; i--)
{
if(X[i]=='1')
{
A[i]=c;
}
else c++;
A[i]+=A[i+1];
}
}
static int f(int i,int j,char X[],char Y[],int zero)
{
if(i==X.length && j==Y.length)return 0;
if(i==X.length)return iv_B[j]; //return inversion count here
if(j==Y.length)return iv_A[i];
if(dp[i][j]==-1)
{
int cost_x=0,cost_y=0;
if(X[i]=='1')
{
cost_x=zero+f(i+1,j,X,Y,zero);
}
else cost_x=f(i+1,j,X,Y,zero-1);
if(Y[j]=='1')
{
cost_y=zero+f(i,j+1,X,Y,zero);
}
else cost_y=f(i,j+1,X,Y,zero-1);
dp[i][j]=Math.min(cost_x, cost_y);
}
return dp[i][j];
}
static boolean f(long last,long next,long l,long r,long A,long B)
{
while(l<=r)
{
long m=(l+r)/2;
long s=((m)*(m-1))/2;
long l1=(A*m)+s,r1=(m*B)-s;
if(Math.min(next, r1)<Math.max(last, l1))
{
if(l1>last)r=m-1;
else l=m+1;
}
else return true;
}
return false;
}
static boolean isVowel(char x)
{
if(x=='a' || x=='e' || x=='i' ||x=='u' || x=='o')return true;
return false;
}
static boolean f(int i,int j)
{
//i is no of one
//j is no of ai>1
if(i==0 && j==0)return true; //this player has no pile to pick --> last move iska rha hoga
if(dp[i][j]==-1)
{
boolean f=false;
if(i>0)
{
if(!f(i-1,j))f=true;
}
if(j>0)
{
if(!f(i,j-1) && !f(i+1,j-1))f=true;
}
if(f)dp[i][j]=1;
else dp[i][j]=0;
}
return dp[i][j]==1;
}
static int last=-1;
static void dfs(int n,int p)
{
last=n;
System.out.println("n--> "+n+" p--> "+p);
for(int c:g[n])
{
if(c!=p)dfs(c,n);
}
}
static long abs(long a,long b)
{
return Math.abs(a-b);
}
static int lower(long A[],long x)
{
int l=0,r=A.length;
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<=x)l=m;
else r=m;
}
return l;
}
static int f(int i,int s,int j,int N,int A[],HashMap<Integer,Integer> mp)
{
if(i==N)
{
return s;
}
if(dp[i][j]==-1)
{
if(mp.containsKey(A[i]))
{
int f=mp.get(A[i]);
int c=0;
if(f==1)c++;
mp.put(A[i], f+1);
HashMap<Integer,Integer> temp=new HashMap<>();
temp.put(A[i],1);
return dp[i][j]=Math.min(f(i+1,s+1+c,j,N,A,mp), s+K+f(i+1,0,i,N,A,temp));
}
else
{
mp.put(A[i],1);
return dp[i][j]=f(i+1,s,j,N,A,mp);
}
}
return dp[i][j];
}
static boolean inRange(int a,int l,int r)
{
if(l<=a && r>=a)return true;
return false;
}
static long f(long a,long b)
{
if(a%b==0)return a/b;
else return (a/b)+f(b,a%b);
}
static void f(int index,long A[],int i,long xor)
{
if(index+1==A.length)
{
if(valid(xor^A[index],i))
{
xor=xor^A[index];
max=Math.max(max, i);
}
return;
}
if(dp[index][i]==0)
{
dp[index][i]=1;
if(valid(xor^A[index],i))
{
f(index+1,A,i+1,0);
f(index+1,A,i,xor^A[index]);
}
else
{
f(index+1,A,i,xor^A[index]);
}
}
}
static boolean valid(long xor,int i)
{
if(xor==0)return true;
while(xor%2==0 )
{
xor/=2;
i--;
}
return i<=0;
}
static int next(int i,long pre[],long S)
{
int l=i,r=pre.length;
while(r-l>1)
{
int m=(l+r)/2;
if(pre[m]-pre[i-1]>S)r=m;
else l=m;
}
return r;
}
static boolean lexo(long A[],long B[])
{
for(int i=0; i<A.length; i++)
{
if(B[i]>A[i])return true;
if(A[i]>B[i])return false;
}
return false;
}
static long [] f(long A[],long B[],int j)
{
int N=A.length;
long X[]=new long[N];
for(int i=0; i<N; i++)
{
X[i]=(B[j]+A[i])%N;
j++;
j%=N;
}
return X;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
b=find(b);
a=find(a);
if(a!=b)
{
par[b]=a;
}
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static long lower_Bound(long A[],int low,int high, long x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void setGraph(int N)
{
size=new int[N+1];
// D=new int[N+1];
g=new ArrayList[N+1];
for(int i=0; i<=N; i++)
{
g[i]=new ArrayList<>();
}
}
static long pow(long a,long b)
{
long pow=1L;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}
static long toggleBits(int x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;
return ((1<<n)-1)^x;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static long GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
}
class Pair{
int x;
int y;
Pair(int x,int y){
this.x = x;
this.y = y;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 6925c7f62b7e7ec2d8f0ee773d787b02 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class MinimumExtraction {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
Integer arr[]=new Integer[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
}
Arrays.parallelSort(arr);
int max=arr[0];
for(int i=1;i<n;i++) {
max=Math.max(max,arr[i]-arr[i-1]);
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 70275e641559553bc3828b5aa0f5835e | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.awt.Container;
import java.awt.image.SampleModel;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import javax.naming.TimeLimitExceededException;
import java.io.PrintStream;
import java.security.KeyStore.Entry;
public class Solution {
static class Pair<T,V>{
T first;
V second;
public Pair(T first, V second) {
super();
this.first = first;
this.second = second;
}
}
// public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;
private static FastScanner fs=new FastScanner();
private static Scanner sc=new Scanner(System.in);
private static int uperBound(long[] arr, long val) {
int start= 0;
int end=arr.length;
while(start<end) {
int mid=(start+end)/2;
if( arr[mid]==val ) {
return mid;
}
if( arr[mid]>val ) {
end=mid-1;
}else {
start=mid+1;
}
}
if( start >= arr.length || arr[start]>val) {
return start;
}else {
return start+1;
}
}
private static int log2(int n) {
if(n<=1) {
return 0;
}
return 1+log2(n/2);
}
private static int pow(int a, int b ) {
if(b==0) return 1;
long ans=1;
for(int i=0;i<b;i++) {
ans= (ans*a)%1000000007;
}
return (int)(ans%1000000007);
}
public static void main(String[] args) throws Exception {
int tcr=1;
//tcr = sc.nextInt();
tcr=fs.nextInt();
while(tcr-->0) {
solve(tcr);
}
System.gc();
}
private static void solve(int TC) throws Exception{
/* Codeforces Round #753 (Div. 3) */
int n=fs.nextInt();
long arr[]=new long[n];
PriorityQueue<Long> q=new PriorityQueue<Long>();
for(int i=0;i<n;i++) {
arr[i]=fs.nextLong();
q.add(arr[i]);
}
long max=q.poll();
long prev=max;
while( !q.isEmpty() ) {
long curr=q.poll();
max=Math.max(max, curr-prev );
prev=curr;
}
System.out.println(max);
/*long x=fs.nextLong();
long n=fs.nextLong();
long jump=1;
int t=100;
while(t-->0) {
if( Math.abs(x)%2==0 ) {
if( x-jump == n ) {
System.out.println(x);
return;
}else {
x=x-jump;
jump++;
}
}else {
if( x+jump == n ) {
System.out.println(x);
return;
}else {
x=x+jump;
jump++;
}
}
System.out.println(x);
}
/*String s=fs.next();
String word=fs.next();
Map<Character, Integer> map=new HashMap<Character, Integer>();
for(int i=0;i<s.length();i++) {
map.put(s.charAt(i), i);
}
long sum=0;
for(int i=1;i<word.length();i++) {
sum+=Math.abs( map.get( word.charAt(i-1)) - map.get(word.charAt(i)) );
}
System.out.println(sum);
/*int n=fs.nextInt();
ArrayList<Integer> arr=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
arr.add(fs.nextInt());
}
ArrayList<ArrayList<Integer>> list=new ArrayList<ArrayList<Integer>>();
list.add(arr);
for(int i=1;i< log2(n)+5 ; i++ ) {
ArrayList<Integer> arr2=new ArrayList<Integer>();
Map<Integer, Integer> map=new HashMap<Integer, Integer>();
for(int j=0;j<n;j++) {
map.put( list.get(i-1).get(j) , map.getOrDefault( list.get(i-1).get(j) , 0)+1 );
}
for(int j=0;j<n;j++) {
arr2.add( map.get( list.get(i-1).get(j) ) );
}
list.add(arr2);
}
int q=fs.nextInt();
while( q-- >0 ) {
int x=fs.nextInt();
int k=fs.nextInt();
System.out.println( list.get( Math.min(k, log2(n)+4 ) ).get(x-1) );
}
/*int n=fs.nextInt();
System.out.println( ( (n-1)/2) +" "+ (n-1) );
/*
int n=fs.nextInt();
int k=fs.nextInt();
ArrayList<Integer> list=new ArrayList<Integer>();
for( int i=n ; i> ( k-1 )/2 ;i-- ) {
if( i==k )
continue;
list.add(i);
}
System.out.println(list.size());
for(int i:list) {
System.out.print(i+" ");
}
System.out.println();
/*int n=fs.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++) {
arr[i]=fs.nextInt();
}
if( n%2==0 ) {
System.out.println("YES");
return ;
}
for(int i=1;i<n;i++) {
if( arr[i-1] >= arr[i] ) {
System.out.println("YES");
return ;
}
}
System.out.println("No");
long n=fs.nextLong();
//System.out.println("#1");
ArrayList<Long> arr1=new ArrayList<>();
ArrayList<Long> arr2=new ArrayList<>();
for(int i=0;i<n;i++) {
long temp=fs.nextLong();
temp= temp*(i+1)*(n-i);
arr1.add(temp);
}
for(int i=0;i<n;i++) {
arr2.add(fs.nextLong());
}
Collections.sort(arr1);
Collections.sort(arr2, Collections.reverseOrder());
final long mod=998244353;
long sum=0;
for(int i=0;i<n;i++) {
sum= ( sum + ( ( arr1.get(i)% mod )* (arr2.get(i)%mod ) ) % mod ) % mod;
}
System.out.println(sum);
/*long n=fs.nextLong();
long k=fs.nextLong();
long time=0;
long done=1;
while( done < k ) {
done*=2;
time++;
}
long left= n-done;
time+= (left+k-1)/k;
System.out.println(time);
/*String s=fs.next();
if( s.charAt(0)==s.charAt(s.length()-1) ) {
System.out.println(s);
}else {
System.out.println(s.substring(0, s.length()-1)+s.charAt(0));
}
/*int n=fs.nextInt();
if(n==1) {
System.out.println(1);
}else if(n==2) {
System.out.println(-1);
}else {
int arr[][]=new int[n][n];
int num=1;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
arr[i][j]=num;
num+=2;
if(num> n*n) {
num=2;
}
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
/*WRITE CODE HERE*/
/*String s=fs.next();
int count=0;
for(int i=0;i<s.length()-1;i++) {
if( s.charAt(i)=='a' && s.charAt(i+1)=='b' ) {
count++;
i++;
}
}
int count2=0;
for(int i=0;i<s.length()-1;i++) {
if( s.charAt(i)=='b' && s.charAt(i+1)=='a' ) {
count2++;
i++;
}
}
char arr[]= s.toCharArray();
if( count>count2) {
for(int i=0;i<s.length()-1;i++) {
if( arr[i]=='b' && arr[i+1]=='b' ) {
arr[i]='a';
count--;
if(count==count2)
break;
}
}
}else if( count2> count) {
for(int i=0;i<s.length()-1;i++) {
if( arr[i]=='a' && arr[i+1]=='a' ) {
arr[i]='b';
count2--;
if(count==count2)
break;
}
}
}
if(count==count2) {
System.out.println(String.copyValueOf(arr));
}else {
for(int i=0;i<s.length();i++) {
System.out.print("b");
}
System.out.println();
}
/*int n=fs.nextInt();
int arr1[]=new int[n];
for(int i=0;i<n;i++) {
arr1[i]=fs.nextInt();
}
int m=fs.nextInt();
int arr2[]=new int[m];
for(int i=0;i<m;i++) {
arr2[i]=fs.nextInt();
}
int max1=Integer.MIN_VALUE;
for(int i=0;i<n;i++) {
max1=Math.max(max1, arr1[i]);
}
int max2=Integer.MIN_VALUE;
for(int i=0;i<m;i++) {
max2=Math.max(max2, arr2[i]);
}
System.out.println(max1+" "+max2);
/*int n=fs.nextInt();
char c=fs.next().charAt(0);
String s=fs.next();
ArrayList<Integer> list=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
if(s.charAt(i)==c) {
list.add(i);
}
}
if( list.size()==n ) {
System.out.println(0);
}else if( list.size()==0) {
System.out.println(2);
System.out.println(2);
if(n%2==0) {
System.out.println(n-1);
}else {
System.out.println(n);
}
}
else {
if( (list.get(list.size()-1)+1)*2 > n ) {
System.out.println(1);
System.out.println(list.get(list.size()-1)+1);
}else {
System.out.println(2);
System.out.print(2+" ");
if(n%2==0) {
System.out.println(n-1);
}else {
System.out.println(n);
}
}
}
/*int n=fs.nextInt();
int k=fs.nextInt();
long sum=0;
while(k>3) {
int log=log2(k);
k= k- (int) pow(2, log);
//System.out.println(log);
sum= (long) (sum+ ( pow(n, log)%1000000007 ) ) % 1000000007;
}
if(k==1) {
sum=(sum+1)%1000000007;;
}else if(k==2) {
sum=(sum+n)%1000000007;
}else if(k==3) {
sum=(sum+n+1)%1000000007;;
}
System.out.println(sum);
/*int arr[]=new int[n];
for(int i=0;i<n;i++) {
arr[i]=fs.nextInt();
}
for(int i=0;i<n;i++) {
arr[i]=~arr[i];
}
Arrays.sort(arr);
for(int i=0;i<n;i++) {
arr[i]=~arr[i];
}
for(int i=0;i<n;i++) {
System.out.print(arr[i]+" ");
}
/*long max=Long.MIN_VALUE;
for(int i=1;i<n;i++) {
max=Math.max(max, 1l*arr[i-1]*arr[i]);
}
System.out.println(max);
/*int n=fs.nextInt();
int m=fs.nextInt();
int k=fs.nextInt();
k=k-2;
if( m< n-1 ) {
System.out.println("NO");
return ;
}
if( m*1l > (n*1l*(n-1))/2 ) {
System.out.println("NO");
return;
}
if(k<=-1) {
System.out.println("NO");
}
else if(k==0) {
if(n==1)
System.out.println("YES");
else
System.out.println("NO");
}
else if(k==1 ) {
if( m*1l==(n*1l*(n-1))/2 )
System.out.println("YES");
else
System.out.println("NO");
}
else
System.out.println("YES");
/*int n=fs.nextInt();
int arr[]=new int[n];
int min=Integer.MAX_VALUE;
for(int i=0;i<n;i++) {
arr[i]=fs.nextInt();
if(min>arr[i]) {
min=arr[i];
}
}
ArrayList<Integer> list=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
int diff=arr[i]-min;
if(diff>0) {
list.add(diff);
}
}
int gcd;
if(list.size()==0) {
gcd=-1;
}else {
gcd=list.get(0);
}
for(int i=1;i<list.size();i++) {
gcd=(int)gcd(gcd, list.get(i));
}
System.out.println(gcd);
/*int n=fs.nextInt();
int k=fs.nextInt();
ArrayList<Integer> mic=new ArrayList<Integer>();
for(int i=0;i<k;i++) {
mic.add(fs.nextInt());
}
int ans=0;
Collections.sort(mic, Collections.reverseOrder());
/*for(int i:mic) {
System.out.print(i+" ");
}
System.out.println();
int catMov=0;
for(int i=0; i< mic.size();i++) {
if(catMov<mic.get(i)) {
int mov= n- mic.get(i);
catMov+=mov;
ans++;
}else {
break;
}
}
System.out.println(ans);
/*String n=fs.next();
int i=0;
for(i=n.length()-1 ; i>=0 ; i--) {
if(n.charAt(i)=='0') {
break;
}
}
int ans1=Integer.MAX_VALUE;
int ans2=Integer.MAX_VALUE;
if( i!=-1 ) {
ans1=n.length()-i-1;
ans2=n.length()-i-1;
int j=i-1;
for(; j>=0 ; j--) {
if(n.charAt(j)=='0') {
break;
}
}
if(j==-1) {
ans1=Integer.MAX_VALUE;
}else {
ans1+= i-j-1;
}
j=i-1;
for(; j>=0 ; j--) {
if(n.charAt(j)=='5') {
break;
}
}
if(j==-1) {
ans2=Integer.MAX_VALUE;
}else {
ans2+= i-j-1;
}
}
i=0;
for(i=n.length()-1 ; i>=0 ; i--) {
if(n.charAt(i)=='5') {
break;
}
}
int ans3=Integer.MAX_VALUE;
int ans4=Integer.MAX_VALUE;
if( i!=-1 ) {
ans3=n.length()-i-1;
ans4=n.length()-i-1;
int j=i-1;
for(; j>=0 ; j--) {
if(n.charAt(j)=='2') {
break;
}
}
if(j==-1) {
ans3=Integer.MAX_VALUE;
}else {
ans3+= i-j-1;
}
j=i-1;
for(; j>=0 ; j--) {
if(n.charAt(j)=='7') {
break;
}
}
if(j==-1) {
ans4=Integer.MAX_VALUE;
}else {
ans4+= i-j-1;
}
}
int min= Math.min(ans1, Math.min(ans2, Math.min(ans3, ans4 ) ) );
System.out.println(min);
/*int a=fs.nextInt();
int b=fs.nextInt();
int c=fs.nextInt();
int max=Math.max(a, Math.max(b, c));
int ans1= max==a ? 0 : (max-a+1);
int ans2= max==b ? 0 : (max-b+1);
int ans3= max==c ? 0 : (max-c+1);
if(max==a && max==b && max==c) {
System.out.println(1+" "+1+" "+1);
}
else if(a==b && max==a) {
c=max-c;
System.out.println(1+" "+1+" "+(c+1));
}else if( b==c && max==b ) {
a=max-a;
System.out.println((a+1)+" "+1+" "+1);
}else if( a==c && max==a ) {
b=max-b;
System.out.println(1+" "+(b+1)+" "+1);
}
else
System.out.println(ans1+" "+ans2+" "+ans3);
/*Queue<Integer> q=new LinkedList<Integer>();
q.add(23);
//q.poll();
System.out.println(q.peek());
/*
int n=fs.nextInt();
int m=fs.nextInt();
ArrayList<String> list=new ArrayList<String>();
Map<String, Integer> map=new HashMap<String, Integer>();
for(int i=0;i<n;i++) {
list.add(fs.next());
map.put(list.get(i), i);
}
Collections.sort(list, new Comparator<String>() {
public int compare(String o1, String o2) {
// TODO Auto-generated method stub
for (int i = 0; i < o1.length(); i++) {
int t = i+1;
if (o1.charAt(i) == o2.charAt(i)) continue;
if (t%2==1) {
return o1.charAt(i)- o2.charAt(i);
}
else {
return o2.charAt(i) - o1.charAt(i);
}
}
return 0;
}
});
for(int i=0;i<n;i++) {
System.out.print(map.get(list.get(i))+1+" ");
}
System.out.println();
//System.out.println(list);
/*for(int i=0;i<m;i++) {
for(int j=1;j<n;j++) {
if(i%2==0) {
int k=0;
while( j-1-k>=0 && list.get(j-1-k).substring(0,i).equals(list.get(j-k).substring(0,i)) && list.get(j-1-k).charAt(i) > list.get(j-k).charAt(i) ) {
//System.out.println(list.get(j-1-k)+" "+list.get(j-k));
String temp=list.get(j-1-k);
list.set(j-1-k, list.get(j-k));
list.set(j-k, temp);
k++;
//System.out.println(list);
}
}else {
int k=0;
while( j-1-k>=0 && list.get(j-1-k).substring(0,i).equals(list.get(j-k).substring(0,i)) && list.get(j-1-k).charAt(i) < list.get(j-k).charAt(i) ) {
String temp=list.get(j-1-k);
list.set(j-1-k, list.get(j-k));
list.set(j-k, temp);
k++;
}
}
}
}
for(int i=0;i<n;i++) {
System.out.print(map.get(list.get(i))+1+" ");
}
System.out.println();
//System.out.println(list);
/*int a=fs.nextInt();
int b=fs.nextInt();
int n=fs.nextInt();
for(int i=0;i<n;i++) {
int sum=a;
for(int j=0;j<=i;j++) {
sum+=Math.pow(2, j)*b;
}
System.out.print(sum+" ");
}
System.out.println();
/*int n=fs.nextInt();
int temp=n;
ArrayList<Pair<Integer,Integer>> list=new ArrayList<Solution.Pair<Integer,Integer>>();
for(int i=2;i*i<=temp;i++) {
if(temp%i==0) {
int cnt=0;
while(temp%i==0) {
cnt++;
temp/=i;
}
list.add(new Pair<Integer, Integer>(i,cnt));
}
}
if(temp!=1) {
list.add(new Pair<Integer, Integer>(temp, 1));
}
if(list.size()==1) {
if(list.get(0).second<6) {
System.out.println("NO");
}
else {
System.out.println("YES");
int num=list.get(0).first;
System.out.println(num+" "+(num*num)+" "+ (n/(num*num*num)));
}
return;
}
int a=list.get(0).first;
int b=list.get(1).first;
int c= n/(a*b);
if( a==c || b==c || c==1 ) {
System.out.println("NO");
}else {
System.out.println("YES");
System.out.println(a+" "+b+" "+c);
}
return;
/*long n=fs.nextLong();
System.out.println((-(n-1))+" "+n);
/*int n=fs.nextInt();
int arr[]=new int[n+1];
for(int i=2;i<=n;i++) {
//System.out.println("#1");
if( arr[i]==0 ) {
for(int j=2*i;j<=n;j+=i) {
arr[j]++;
//System.out.println("#2");
}
}
}
int count=0;
for(int i=2;i<=n;i++) {
//System.out.println("#3");
if(arr[i]==2) {
count++;
}
}
System.out.println(count);
/*int n = fs.nextInt(), x = fs.nextInt();
int[] a =new int[n];
for(int i=0;i<n;i++) {
a[i]=fs.nextInt();
}
int[] b = a.clone();
Arrays.sort(b);
for (int i = 0; i < n; i++) {
if (i < x && n - 1 - i < x && a[i] != b[i]) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
/*int n=fs.nextInt();
int x=fs.nextInt();
ArrayList<Long> list=new ArrayList<Long>();
for(int i=0;i<n;i++) {
list.add(fs.nextLong());
}
ArrayList<Long> copy=(ArrayList<Long>)list.clone();
Collections.sort(copy);
for(int i=0;i<n;i++) {
if( copy.get(i)!=list.get(i) ) {
if( i < x && n - 1 - i < x ) {
System.out.println("NO");
return;
}
}
}
System.out.println("YES");
/*int n=fs.nextInt();
int h=fs.nextInt();
ArrayList<Integer> list=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
list.add(fs.nextInt());
}
Collections.sort(list, Collections.reverseOrder());
int sum=list.get(0)+list.get(1);
int count= (h/sum)*2 ;
int left=h%sum;
if( left<=list.get(0) && left!=0 ) {
count++;
}else if(left!=0){
count+=2;
}
System.out.println(count);
/*int n=fs.nextInt();
PriorityQueue<Pair<Integer,Integer>> pq=new PriorityQueue<Solution.Pair<Integer,Integer>>( (o1,o2)-> o2.first.compareTo(o1.first) );
for(int i=1;i<=n;i++) {
int num=fs.nextInt();
if(num==0) {
continue;
}
pq.add(new Pair<Integer,Integer>(num, i));
}
ArrayList<Pair<Integer,Integer>> ans=new ArrayList<Solution.Pair<Integer,Integer>>();
while(pq.size()>1) {
Pair p1=pq.poll();
Pair p2=pq.poll();
ans.add(new Pair(p1.second, p2.second));
p1.first=(int)p1.first-1;
p2.first=(int)p2.first-1;
if(!p1.first.equals(0)) pq.add(p1);
if(!p2.first.equals(0)) pq.add(p2);
}
System.out.println(ans.size());
for(Pair p:ans) {
System.out.println(p.first+" "+p.second);
}
/*int r=fs.nextInt();
int col=fs.nextInt();
int k=fs.nextInt();
char arr[][]=new char[r][col];
for(int i=0;i<r;i++) {
char ch[]=fs.next().toCharArray();
arr[i]=ch;
}
boolean visited[][]=new boolean[r][col];
for(boolean b[]:visited) {
Arrays.fill(b, false);
}
for(int i=r-1;i>=1;i--) {
for(int j=1;j<col-1;j++) {
if( arr[i][j]=='*' ) {
int len = 0;
int a1 = i - 1, l1 = j - 1, l2 = j + 1;
ArrayList<Pair<Integer, Integer>> v=new ArrayList<Solution.Pair<Integer,Integer>>();
while (a1 >= 0 && l1 >= 0 && l2 < col) {
if (arr[a1][l1] == '*' && arr[a1][l2] == '*') {
len++;
v.add(new Pair(a1,l1));
v.add(new Pair(a1,l2));
l1--;
l2++;
a1--;
continue;
}
break;
}
if (len < k && visited[i][j] == false) {
System.out.println("NO");
return;
}
if (len >= k) {
for (Pair p:v) {
visited[(int)p.first][(int)p.second] = true;
}
}
visited[i][j] = true;
}
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < col; j++) {
if (arr[i][j] == '*' && !visited[i][j]) {
System.out.println("NO");
return;
}
}
}
System.out.println("YES");
/*int n=fs.nextInt();
int arr[]=new int[n+1];
for(int i=1;i<=n;i++) {
arr[i]=fs.nextInt();
}
ArrayList<int[]> list=new ArrayList<int[]>();
int smallAns[]=new int[3];
for(int i=1;i<=n ;i++) {
int minI=i;
for(int j=i+1;j<=n;j++) {
if(arr[minI]>arr[j]) {
minI=j;
}
}
if(minI==i) {
continue;
}
//System.out.println(minI);
int temp=arr[minI];
for(int j=minI;j>i;j--) {
arr[j]=arr[j-1];
}
arr[i]=temp;
smallAns[0]=i;
smallAns[1]=minI;
smallAns[2]=minI-i;
list.add(Arrays.copyOf(smallAns,smallAns.length));
}
System.out.println(list.size());
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i)[0]+" "+list.get(i)[1]+" "+list.get(i)[2]);
}
/*System.out.println("sort");
for(int i=1;i<=n;i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
/*String s=fs.next();
int a=0;
int b=0;
int c=0;
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='A') {
a++;
}else if( s.charAt(i)=='B' ) {
b++;
}else {
c++;
}
}
if( a+c==b ) {
System.out.println("YES");
}else {
System.out.println("NO");
}
/*int w=fs.nextInt();
int h=fs.nextInt();
int x1=fs.nextInt();
int y1=fs.nextInt();
int x2=fs.nextInt();
int y2=fs.nextInt();
int tw=fs.nextInt();
int th=fs.nextInt();
if( !( ( w>= (Math.abs(x1-x2)+tw) || h>= (Math.abs(y1-y2)+th) ) || ( w>= ( Math.abs(x1-x2)+th ) || h>= ( Math.abs(y1-y2)+tw ) ) ) ) {
System.out.println(-1);
return ;
}
int ans=Integer.MAX_VALUE;
if( y1>= th || h-y2>=th ) {
ans=0;
}else if( th+y2-y1 <= h ) {
ans= th-y1;
ans = Math.min(ans, th-( h-y2 ) );
}
if( x1>=tw || w-x2 >= tw) {
ans=0;
}else if( tw+ x2-x1 <= w ) {
ans=Math.min(ans, tw-x1 );
ans= Math.min(ans, tw-(w-x2) );
}
if(ans== Integer.MAX_VALUE ) {
System.out.println(-1);
}else if( ans<0 ) {
System.out.println(0);
}else
System.out.println(ans);
/*int col=fs.nextInt();
int in[][]=new int[2][col];
for(int i=0;i<col;i++) {
in[0][i]=fs.nextInt();
}
for(int i=0;i<col;i++) {
in[1][i]=fs.nextInt();
}
int leftSum[][]=new int[2][col];
leftSum[0][0]=in[0][0];
leftSum[1][0]=in[1][0];
for(int i=1;i<col;i++) {
leftSum[0][i]=in[0][i]+leftSum[0][i-1];
leftSum[1][i]=in[1][i]+leftSum[1][i-1];
}
int rightSum[][]=new int[2][col];
rightSum[0][col-1]=in[0][col-1];
rightSum[1][col-1]=in[1][col-1];
for(int i=col-2;i>=0;i--) {
rightSum[0][i]=rightSum[0][i+1] + in[0][i];
rightSum[1][i]=rightSum[1][i+1] + in[1][i];
}
int minScore=Integer.MAX_VALUE;
for(int i=0;i<col;i++) {
int score1= ( i+1<col ) ? rightSum[0][i+1] : 0;
int score2= (i-1>=0) ? leftSum[1][i-1] : 0;
minScore= Math.min(minScore, Math.max(score1, score2));
}
System.out.println(minScore);
/*int n=fs.nextInt();
long input[]=new long[n];
for(int i=0;i<n;i++) {
input[i]=fs.nextLong();
}
int even=0;
for(int i=0;i<n;i++) {
if( (input[i]&1) ==0 ) {
even++;
}
}
int odd=n-even;
if( Math.abs(odd-even) > 1 ) {
System.out.println(-1);
return ;
}
for(int i=0;i<n;i++) {
input[i]= ( (input[i]&1)==1 )?1 :0;
}
int ans=Integer.MAX_VALUE;
if( (n&1)==0 ) {
int output[]=new int[n];
for(int i=0;i<n;i++) {
output[i] = ( i&1 )==1 ? 1:0;
}
ArrayList<Integer> oddpos=new ArrayList<Integer>();
ArrayList<Integer> evenpos=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
if( input[i] != output[i] ) {
if( (i&1)==1 ) oddpos.add(i);
else evenpos.add(i);
}
}
int smallAns=0;
for(int i=0;i<oddpos.size();i++) {
smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i));
}
ans=Math.min(ans, smallAns);
output=new int[n];
for(int i=0;i<n;i++) {
output[i] = ( i&1 )==0 ? 1:0;
}
oddpos=new ArrayList<Integer>();
evenpos=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
if( input[i] != output[i] ) {
if( (i&1)==1 ) oddpos.add(i);
else evenpos.add(i);
}
}
smallAns=0;
for(int i=0;i<oddpos.size();i++) {
smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i));
}
ans=Math.min(ans, smallAns);
}else if( odd> even ) {
int output[]=new int[n];
for(int i=0;i<n;i++) {
output[i] = ( i&1 )==0 ? 1:0;
}
ArrayList<Integer> oddpos=new ArrayList<Integer>();
ArrayList<Integer> evenpos=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
if( input[i] != output[i] ) {
if( (i&1)==1 ) oddpos.add(i);
else evenpos.add(i);
}
}
int smallAns=0;
for(int i=0;i<oddpos.size();i++) {
smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i));
}
ans=Math.min(ans, smallAns);
}else {
int output[]=new int[n];
for(int i=0;i<n;i++) {
output[i] = ( i&1 )==1 ? 1:0;
}
ArrayList<Integer> oddpos=new ArrayList<Integer>();
ArrayList<Integer> evenpos=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
if( input[i] != output[i] ) {
if( (i&1)==1 ) oddpos.add(i);
else evenpos.add(i);
}
}
int smallAns=0;
for(int i=0;i<oddpos.size();i++) {
smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i));
}
ans=Math.min(ans, smallAns);
}
System.out.println(ans);
/*
int len=fs.nextInt();
String row1=fs.next();
String row2=fs.next();
int prev=-1;
int count=0;
for(int i=0;i<len; i++) {
if( row1.charAt(i) != row2.charAt(i) ) {
count+=2;
prev=-1;
}else if ( row1.charAt(i)=='1') {
if(prev==0) {
count++;
prev=-1;
}else {
prev=1;
}
}else {
if(prev==1) {
count+=2;
prev=-1;
}else {
count++;
prev=0;
}
}
}
System.out.println(count);
/*int a=fs.nextInt();
int b=fs.nextInt();
int c=fs.nextInt();
int m=fs.nextInt();
int max=a+b+c-3;
int arr[]= {a,b,c};
Arrays.parallelSort(arr);
int min=arr[2]-arr[1]-arr[0]-1;
if(m>=min && m<=max) {
System.out.println("YES");
}else {
System.out.println("No");
}
*/
/*
int n=fs.nextInt();
long hero[]=new long[n];
long sum=0;
for(int i=0;i<n;i++) {
hero[i]=Long.parseLong(fs.next());
sum+=hero[i];
}
//System.out.println(sum);
Arrays.sort(hero);
//for(long x: hero)
//System.out.print(x+" ");
//System.out.println();
int m=fs.nextInt();
while(m-->0) {
long df=Long.parseLong(fs.next());
long at=Long.parseLong(fs.next());
long nextGrt=(long)Math.pow(10, 18);
long nextSmall=-1;
int index=uperBound(hero, df);
//System.out.println(hero[index]);
//System.out.println(index);
if(index>=n) {
nextSmall=hero[n-1];
}else if(index<=0 ) {
nextGrt=hero[0];
}else {
nextGrt=hero[index];
nextSmall=hero[index-1];
}
/*for(int i=0;i<n;i++) {
if(hero[i]>=df && hero[i]<nextGrt ) {
nextGrt=hero[i];
}
if(hero[i]<=df && hero[i]>nextSmall ) {
nextSmall=hero[i];
}
}
//System.out.println(nextGrt +" : "+nextSmall);
if( nextGrt!= (long) Math.pow(10, 18) && sum-nextGrt >=at ) {
System.out.println(0);
}else {
if(nextGrt==(long)Math.pow(10, 18)) {
long ans= df- nextSmall;
ans+= ( at<= ( sum-nextSmall ) ) ? 0 : (at- sum+nextSmall);
System.out.println(ans);
}
else if(nextSmall==-1) {
long ans= ( at <= sum- nextGrt ) ? 0 : ( at- sum+nextGrt);
System.out.println(ans);
}else {
long ans1=df- nextSmall;
ans1+= ( at<= ( sum-nextSmall ) ) ? 0 : (at- sum+nextSmall);
long ans2= ( at <= sum- nextGrt ) ? 0 : ( at- sum+nextGrt);
System.out.println(Math.min(ans1, ans2));
}
}
}
/*int n=fs.nextInt();
for(int i=1;i<=n;i++) {
String open="";
String close="";
for(int j=1;j<=i;j++) {
open+="(";
close+=")";
}
int j=0;
while( j+2*i <= 2* n) {
System.out.print(open);
System.out.print(close);
j=j+2*i;
}
//System.out.println(j);
if(j<2*n) {
while(j<2*n) {
System.out.print("(");
System.out.print(")");
j+=2;
}
}
System.out.println();
}
*/
}
static int computeXOR(int n)
{
// If n is a multiple of 4
if (n % 4 == 0)
return n;
// If n%4 gives remainder 1
if (n % 4 == 1)
return 1;
// If n%4 gives remainder 2
if (n % 4 == 2)
return n + 1;
// If n%4 gives remainder 3
return 0;
}
static boolean isSorted (int[] nums) {
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] > nums[i + 1]) {
return false;
}
}
return true;
}
static void firstOperation (int[] nums) {
for (int i = 1; i < nums.length; i += 2) {
int temp = nums[i];
nums[i] = nums[i - 1];
nums[i - 1] = temp;
}
}
static void secondOperation (int[] nums) {
int n = nums.length / 2;
for (int i = 0; i < n; i++) {
int temp = nums[i];
nums[i] = nums[i + n];
nums[i + n] = temp;
}
}
private static long numOfDigits(long a) {
long ans=0;
while(a!=0) {
ans++;
a/=10;
}
return ans;
}
private static String reverse(String s) {
String ans="";
for(int i=s.length()-1;i>=0;i--) {
ans+=s.charAt(i);
}
return ans;
}
private static boolean isPalindrome(String s) {
int i=0;
int j=s.length()-1;
while(i<j) {
if(s.charAt(i)!=s.charAt(j)) {
return false;
}
i++;
j--;
}
return true;
}
static class FastScanner {
BufferedReader br;
StringTokenizer st ;
FastScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
FastScanner(String file) {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
st = new StringTokenizer("");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("file not found");
e.printStackTrace();
}
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
String readLine() throws IOException{
return br.readLine();
}
}
public static long[] sort(long arr[]){
List<Long> list = new ArrayList<>();
for(long n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
public static int[] sort(int arr[]){
List<Integer> list = new ArrayList<>();
for(int n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
// return the (index + 1)
// where index is the pos of just smaller element
// i.e count of elemets strictly less than num
public static int justSmaller(long arr[],long num){
// System.out.println(num+"@");
int st = 0;
int e = arr.length - 1;
int ans = -1;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] >= num){
e = mid - 1;
}else{
ans = mid;
st = mid + 1;
}
}
return ans + 1;
}
//return (index of just greater element)
//count of elements smaller than or equal to num
public static int justGreater(long arr[],long num){
int st = 0;
int e = arr.length - 1;
int ans = arr.length;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] <= num){
st = mid + 1;
}else{
ans = mid;
e = mid - 1;
}
}
return ans;
}
public static boolean isPrime(int n) {
for(int i=2;i<n;i++) {
if(n%i==0) {
return false;
}
}
return true;
}
public static void println(Object obj){
System.out.println(obj.toString());
}
public static void print(Object obj){
System.out.println(obj.toString());
}
public static long gcd(long a,long b){
if(b == 0l){
return a;
}
return gcd(b,a%b);
}
public static int find(int parent[],int v){
if(parent[v] == v){
return v;
}
return parent[v] = find(parent, parent[v]);
}
public static List<Integer> sieve(){
List<Integer> prime = new ArrayList<>();
int arr[] = new int[100001];
Arrays.fill(arr,1);
arr[1] = 0;
arr[2] = 1;
for(int i=2;i<=100000;i++){
if(arr[i] == 1){
prime.add(i);
for(long j = (i*1l*i);j<100001;j+=i){
arr[(int)j] = 0;
}
}
}
return prime;
}
static boolean isPower(long n,long a){
long log = (long)(Math.log(n)/Math.log(a));
long power = (long)Math.pow(a,log);
if(power == n){return true;}
return false;
}
private static int mergeAndCount(int[] arr, int l,int m, int r)
{
// Left subarray
int[] left = Arrays.copyOfRange(arr, l, m + 1);
// Right subarray
int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
int i = 0, j = 0, k = l, swaps = 0;
while (i < left.length && j < right.length) {
if (left[i] <= right[j])
arr[k++] = left[i++];
else {
arr[k++] = right[j++];
swaps += (m + 1) - (l + i);
}
}
while (i < left.length)
arr[k++] = left[i++];
while (j < right.length)
arr[k++] = right[j++];
return swaps;
}
// Merge sort function
private static int mergeSortAndCount(int[] arr, int l,int r)
{
// Keeps track of the inversion count at a
// particular node of the recursion tree
int count = 0;
if (l < r) {
int m = (l + r) / 2;
// Total inversion count = left subarray count
// + right subarray count + merge count
// Left subarray count
count += mergeSortAndCount(arr, l, m);
// Right subarray count
count += mergeSortAndCount(arr, m + 1, r);
// Merge count
count += mergeAndCount(arr, l, m, r);
}
return count;
}
static class Debug {
//change to System.getProperty("ONLINE_JUDGE")==null; for CodeForces
public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;
private static <T> String ts(T t) {
if(t==null) {
return "null";
}
try {
return ts((Iterable) t);
}catch(ClassCastException e) {
if(t instanceof int[]) {
String s = Arrays.toString((int[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof long[]) {
String s = Arrays.toString((long[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof char[]) {
String s = Arrays.toString((char[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof double[]) {
String s = Arrays.toString((double[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof boolean[]) {
String s = Arrays.toString((boolean[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}
try {
return ts((Object[]) t);
}catch(ClassCastException e1) {
return t.toString();
}
}
}
private static <T> String ts(T[] arr) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: arr) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}");
return ret.toString();
}
private static <T> String ts(Iterable<T> iter) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: iter) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}");
return ret.toString();
}
public static void dbg(Object... o) throws Exception {
if(LOCAL) {
PrintStream ps = new PrintStream("src/Debug.txt");
System.setErr(ps);
System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [");
for(int i = 0; i<o.length; i++) {
if(i!=0) {
System.err.print(", ");
}
System.err.print(ts(o[i]));
}
System.err.println("]");
}
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 0392c7f064420480762ac9ad8310caeb | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution
{
public static void main (String[] args) throws java.lang.Exception
{
InputReader sc=new InputReader(System.in);
int t = sc.readInt();
PrintWriter pw=new PrintWriter(System.out);
while(t-->0){
int n = sc.readInt();
ArrayList<Integer> a = new ArrayList<>();
for(int i=0;i<n;i++){
a.add(sc.readInt());
}
Collections.sort(a);
int sum=a.get(0);
int max = a.get(0);
for(int i=1;i<n;i++){
if(a.get(i)-sum>max){
max=a.get(i)-sum;
}
sum+=a.get(i)-sum;
}
pw.println(max);
}
pw.close();
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String readLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 2e59ed1986947bd58474a48ecdbf8260 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.security.KeyStore.Entry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.*;
public class test2 {
// static boolean[] f = new boolean[(int) 10e6];
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter sp = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
ArrayList<Integer> x = new ArrayList<Integer>();
for (int i = 0; i < n; i++)
x.add(sc.nextInt());
Collections.sort(x);
ArrayList<Integer> y = new ArrayList<Integer>();
y.add(x.get(0));
for (int i = 1; i < x.size(); i++) {
y.add(x.get(i) - x.get(i - 1));
}
Collections.sort(y, Collections.reverseOrder());
sp.println(y.get(0));
}
sp.flush();
}
//
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
// 1 1 1 1 1 2 2
class Pair implements Comparable {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Object o) {
Pair z = (Pair) o;
if (this.x >= z.x && this.y >= z.y)
return 1;
return -1;
}
public boolean contains(Pair q) {
if (q.x == x || q.x == y || q.y == x || q.y == y)
return true;
return false;
}
public int getx() {
return x;
}
public int gety() {
return y;
}
public String toString() {
return x + " " + y;
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 682a5ee11add0666f61701226232e096 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.*;
import java.util.*;
public class C_Minimum_Extraction {
public static void main(String[] args) {
FastScanner scn = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = scn.nextInt();
while (t-- > 0) {
int n = scn.nextInt();
Long[] arr = new Long[n];
for (int i = 0; i < n; i++) {
arr[i] = scn.nextLong();
}
Arrays.sort(arr);
long mx = arr[0];
for (int i = 1; i < n; i++) {
mx = max(arr[i] - arr[i - 1], mx);
}
out.println(mx);
}
out.close();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a8def52f33defbbda93d8290f2348281 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner scn = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = scn.nextInt();
while (t-- > 0) {
int n = scn.nextInt();
Long[] arr = new Long[n];
for (int i = 0; i < n; i++) {
arr[i] = scn.nextLong();
}
Arrays.sort(arr);
long mx = arr[0];
for (int i = 1; i < n; i++) {
mx = Math.max(arr[i] - arr[i - 1], mx);
}
out.println(mx);
}
out.close();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 2b4fcea937c55fea2e49bd6618650d63 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
Reader scn = new Reader();
int t = scn.nextInt();
while (t-- > 0) {
int n = scn.nextInt();
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = scn.nextInt();
}
Arrays.sort(arr);
int mx = arr[0];
for (int i = 1; i < n; i++) {
mx = max(mx, arr[i] - arr[i - 1]);
}
System.out.println(mx);
}
}
}
class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | df5c75b83e1078b9caf0ad25c7bfb507 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
/**
* @author Micgogi
* on 11/17/2021 12:26 PM
* Rahul Gogyani
*/
public class C1607 {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
long t = sc.nextLong();
while(t--!=0){
int n= sc.nextInt();
Long a[] = new Long[n];
for (int i = 0; i <n ; i++) {
a[i] = sc.nextLong();
}
Arrays.sort(a);
long res = a[0];
for (int i = 0; i <n-1 ; i++) {
res = Math.max(res,a[i+1]-a[i]);
}
System.out.println(res);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 77252fcd98c9abc3d83c2c403d454d5b | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class MinimumExtraction {
public static void main(String[] args) {
new MinimumExtraction().run();
}
BufferedReader br;
PrintWriter out;
long mod = (long) (1e9 + 7), inf = (long) (3e18);
class pair {
int F, S;
pair(int f, int s) {
F = f; S = s;
}
}
void solve() {
int t = ni();
while(t-- > 0) {
//TODO:
int n=ni();
Long[] a=new Long[n];
for(int i=0;i<n;i++){a[i]=nl();}
Arrays.sort(a);
long M=a[0];
for(int i=0;i<n-1;i++){
if(a[i+1]-a[i]>M)M=a[i+1]-a[i];
}
out.println(M);
}
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
int[] na(int n) {
int a[] = new int[n];
for(int i = 0; i < n; i++) a[i] = ni();
return a;
}
StringTokenizer ip;
String ns() {
if(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
if(ip == null || !ip.hasMoreTokens())
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void run() {
try {
if (System.getProperty("ONLINE_JUDGE") == null) {
br = new BufferedReader(new FileReader("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt"));
out = new PrintWriter("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt");
} else {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
solve();
out.flush();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | efc3ec79c35d66be925cda1bf216a629 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class minExtraction{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
Integer[] arr = new Integer[n];
for(int i=0;i<n;i++){
int a = sc.nextInt();
arr[i] = new Integer(a);
}
Arrays.sort(arr);
int ans =arr[0];
int curr = 0 ;
for(int i=0;i<n-1;i++){
curr+= arr[i];
arr[i+1]-= curr;
ans = Math.max(ans,arr[i+1]);
}
System.out.println(ans);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 07d345c9df2e497253dbcedc5845b922 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.math.*;
import java.util.* ;
import java.io.* ;
@SuppressWarnings("unused")
//i am working for the day i will surpass you
//Scanner in = new Scanner(new File("input.txt"));
//in.close();
//PrintWriter writer = new PrintWriter("output.txt");
//writer.close();
public class A
{
static final int mod = (int)1e9+7 ;
static final double pi = 3.1415926536 ;
static boolean not_prime[] = new boolean[1000001] ;
static void sieve() {
for(int i=2 ; i*i<1000001 ; i++) {
if(not_prime[i]==false) {
for(int j=2*i ; j<1000001 ; j+=i) {
not_prime[j]=true ;
}
}
}not_prime[0]=true ; not_prime[1]=true ;
}
public static long bexp(long base , long power)
{
long res=1L ;
base = base%mod ;
while(power>0) {
if((power&1)==1) {
res=(res*base)%mod ;
power-- ;
}
else {
base=(base*base)%mod ;
power>>=1 ;
}
}
return res ;
}
static long modInverse(long n, long p){return power(n, p - 2, p); }
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
x = (x * x) % p;
}
return res;
}
static long nCrModPFermat(int n, int r, long p){if(n<r) return 0 ;if (r == 0)return 1; long[] fac = new long[n + 1];fac[0] = 1;for (int i = 1; i <= n; i++)fac[i] = fac[i - 1] * i % p;return (fac[n] * modInverse(fac[r], p) % p* modInverse(fac[n - r], p) % p) % p;}
static long modular_add(long a, long b){ return ((a % mod) + (b % mod)) % mod; }
static long modular_sub(long a, long b){ return ((a % mod) - (b % mod) + mod) % mod; }
static long modular_mult(long a, long b){ return ((a % mod) * (b % mod)) % mod; }
static long lcm(int a, int b){ return (a / gcd(a, b)) * b; }
static long gcd(long a, long b){if (b == 0) {return a;}return gcd(b, a % b);}
static int cbits(long x) {return (int)(Math.log(x)/Math.log(2)+1) ;}
public static void main(String[] args)throws Exception
{
FastReader in = new FastReader() ;
StringBuilder op = new StringBuilder() ;
int T = in.nextInt();
// int T=1 ;
for(int tt=0 ; tt<T ; tt++){
int n = in.nextInt() ;
int a[] = in.readArray(n) ;
sort(a) ;
int max=a[0] ;
for(int i=1 ; i<n ; i++) {
max = Math.max(max, a[i]-a[i-1]) ;
}
op.append(max+"\n");
}
System.out.println(op.toString());
}
static class pair implements Comparable<pair>
{
int first , second ;
pair(int first , int second){
this.first=first ;
this.second=second;
}
public int compareTo(pair other) {
return this.first-other.first ;
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble(){ return Double.parseDouble(next()); };
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 1f60ed3072bb547353852e24f9c2db40 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class MinExtract {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t = Integer.parseInt(st.nextToken());
for(int i=0; i<t; i++) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
ArrayList<Integer> nums = new ArrayList<Integer>();
st = new StringTokenizer(br.readLine());
for(int a=0; a<n; a++)
nums.add(Integer.parseInt(st.nextToken()));
Collections.sort(nums);
int max_min = nums.get(0);
int sub = nums.get(0);
for(int a=1; a<nums.size();a++) {
int nm = nums.get(a);
if(nm-sub>max_min) max_min = nm-sub;
sub += nm-sub;
}
System.out.println(max_min);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 945a7fc729b9ea2a2323d4c72090af7d | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class MinExtract {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t = Integer.parseInt(st.nextToken());
for(int i=0; i<t; i++) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
ArrayList<Integer> nums = new ArrayList<Integer>();
st = new StringTokenizer(br.readLine());
for(int a=0; a<n; a++)
nums.add(Integer.parseInt(st.nextToken()));
Collections.sort(nums);
int max_min = nums.get(0);
int sub = nums.get(0);
for(int a=1; a<nums.size();a++) {
if(nums.get(a)-sub>max_min) max_min = nums.get(a)-sub;
sub += nums.get(a)-sub;
}
System.out.println(max_min);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 8687cfb34133394a6391c89af211d4b7 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 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();
Long[] a=new Long[n];
for(int i=0;i<n;i++){a[i]=sc.nextLong();}
Arrays.sort(a);
long M=a[0];
for(int i=0;i<n-1;i++){
if(a[i+1]-a[i]>M)M=a[i+1]-a[i];
}
System.out.println(M);
}
sc.close();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 444be26cd7baea4063db3553f762edcb | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class C_Minimum_Extraction
{
static int M = 1_000_000_007;
static final PrintWriter out =new PrintWriter(System.out);
static final FastReader fs = new FastReader();
static boolean prime[];
public static void main (String[] args) throws java.lang.Exception
{
int t= fs.nextInt();
for(int i=0;i<t;i++)
{
int n=fs.nextInt();
long a[]=fs.arrayIn(n);
ruffleSort(a);
long gg=0;
int in=0;
if(a[in]<0){
gg=(-1)*a[in];
in++;
}
if(in==n){
out.println(gg+2*a[n-1]);
}else{
long max=0;
long sub=0;
for(int j=in;j<n;j++){
long ff=a[j]-sub+gg;
max=Math.max(max,ff);
sub=sub+ff;
}
out.println(max);
}
}
out.flush();
}
public static long power(long x, long y)
{
long temp;
if (y == 0)
return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return modMult(temp,temp);
else {
if (y > 0)
return modMult(x,modMult(temp,temp));
else
return (modMult(temp,temp)) / x;
}
}
static void sieveOfEratosthenes(int n)
{
prime = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
prime[0]=false;
if(1<=n)
prime[1]=false;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
long [] arrayIn(int n) throws IOException
{
long arr[] = new long[n];
for(int i=0; i<n; i++)
{
arr[i] = nextLong();
}
return arr;
}
}
public static class Pairs implements Comparable<Pairs>
{
int value,index;
Pairs(int value, int index)
{
this.value = value;
this.index = index;
}
public int compareTo(Pairs p)
{
return Integer.compare(this.value, p.value);
}
}
static final Random random = new Random();
static void ruffleSort(long arr[])
{
int n = arr.length;
for(int i=0; i<n; i++)
{
int j = random.nextInt(n);
long temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr);
}
static long nCk(int n, int k) {
return (modMult(fact(n),fastexp(modMult(fact(n-k),fact(k)),M-2)));
}
static long fact (long n) {
long fact =1;
for(int i=1; i<=n; i++) {
fact = modMult(fact,i);
}
return fact%M;
}
static long modMult(long a,long b) {
return a*b%M;
}
static long fastexp(long x, int y){
if(y==1) return x;
long ans = fastexp(x,y/2);
if(y%2 == 0) return modMult(ans,ans);
else return modMult(ans,modMult(ans,x));
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 4c199713b483e5ff2580892cbd94a610 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long[]fac=new long[200100];
static long[] two= new long[200100] ;
static long mod=((long)1e18)+7;
static String[]pow=new String[63];
static int n;
static int x=0;
static int[][]perm,b;
static int[]pe,aa,a;
public static void main(String[] args) throws IOException, InterruptedException{
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
Long[]a=new Long[n];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextLong();
}
Arrays.sort(a);
long ans=a[0];
for (int i = 1; i < a.length; i++) {
ans=Math.max(ans, a[i]-a[i-1]);
}
pw.println(ans);
}
pw.close();
}
public static long[] Extended(long p, long q) {
if (q == 0)
return new long[] { p, 1, 0 };
long[] vals = Extended(q, p % q);
long d = vals[0];
long a = vals[2];
long b = vals[1] - (p / q) * vals[2];
return new long[] { d, a, b };
}
static class STree{
int N;
long[]arr;
long[]tree;
int[]lazy;
long id;
public static long operation(long x,long y) {
return x^y;
}
public STree(int[]a,long id) {
this.id=id;
N=1;
int n=a.length;
while(N<n) {
N*=2;
}
arr=new long[N+1];
Arrays.fill(arr, id);
for (int i = 1; i <= a.length; i++) {
arr[i]=a[i-1];
}
tree=new long[2*N];
Arrays.fill(tree, id);
build(1,N,1);
lazy=new int[2*N];
}
public void build(int l,int r,int node) {
if(l==r) {
tree[node]=arr[l];
return;
}
int mid=(l+r)/2;
build(l,mid,node*2);
build(mid+1,r,node*2+1);
tree[node]=operation(tree[node*2],tree[node*2+1]);
}
// public void update(int node,int value) {
// int i=node+N-1;
// tree[i]=value;
// i/=2;
// while(i>0) {
// tree[i]=operation(tree[i*2], tree[i*2+1]);
// i/=2;
// }
// }
//
// public void updateRange(int l,int r,int v) {
// updateRange(1, N, l, r, 1,v);
// }
//
// public void updateRange(int s,int e,int l,int r,int node,int v) {
// if(s>=l&&e<=r) {
// lazy[node]^=v;
// tree[node]=propagate(tree[node],lazy[node],e-s+1);
//// lazy[node]=0;
// return;
// }
// if(s>r||e<l)return;
// int mid=(s+e)/2;
// lazy[node*2] ^= lazy[node];
// lazy[node*2+1] ^= lazy[node];
// tree[node*2] = propagate(tree[node*2], v, (e-s+1)/2);
// tree[node*2+1] = propagate(tree[node*2+1], v, (e-s+1)/2);
// lazy[node] = 0;
// updateRange(s, mid, l, r, node*2, v);
// updateRange(mid+1, e, l, r, node*2+1, v);
// tree[node]=operation(tree[node*2], tree[node*2+1]);
// return;
// }
//
public long q(int l,int r) {
return q(1,N,l,r,1);
}
public long q(int s,int e,int l,int r,int node) {
if(s>=l&&r>=e) {
return tree[node];
}
if(s>r||e<l)
return id;
int mid=(s+e)/2;
return operation(q(s,mid,l,r,node*2), q(mid+1,e,l,r,node*2+1));
}
// public static segment propagate(segment x,int v,int length) {
// int[]bit=x.bit.clone();
// long sum=x.sum;
// for (int i = 0; i < bit.length; i++) {
// if((v&1<<i)!=0) {
// sum-=(1<<i)*(bit[i]);
// sum+=(1<<i)*(length-bit[i]);
// bit[i]=length-bit[i];
// }
// }
// return new segment(sum, bit);
// }
}
public static class segment{
long sum;
int[] bit;
public segment (long sum,int[]bit) {
this.sum=sum;
this.bit=bit.clone();
}
@Override
public String toString() {
return sum+" "+Arrays.toString(bit);
}
}
public static int LIS(int[] a) {
int n = a.length;
int[] ser = new int[n];
int[]ser1=new int[n];
Arrays.fill(ser1, Integer.MAX_VALUE);
Arrays.fill(ser, Integer.MAX_VALUE);
int cur = -1;
int[]inc=new int[n];
int[]dec=new int[n];
for (int i = 0; i < n; i++) {
int low = 0;
int high = n - 1;
int mid = (low + high) / 2;
while (low <= high) {
if (ser[mid] < a[i]) {
low = mid + 1;
} else {
high = mid - 1;
}
mid = (low + high) / 2;
}
inc[i]=high+2;
cur = Math.max(cur, high + 1);
ser[high + 1] = Math.min(ser[high + 1], a[i]);
}
for (int i = n-1; i >= 0; i--) {
int low = 0;
int high = n - 1;
int mid = (low + high) / 2;
while (low <= high) {
if (ser1[mid] < a[i]) {
low = mid + 1;
} else {
high = mid - 1;
}
mid = (low + high) / 2;
}
dec[i]=high+2;
cur = Math.max(cur, high + 1);
ser1[high + 1] = Math.min(ser1[high + 1], a[i]);
}
int ans=1;
for (int i = 0; i < dec.length; i++) {
ans=Math.max(ans, 2*Math.min(inc[i], dec[i])-1);
}
return ans;
}
public static void permutation(int idx,int v) {
if(v==(1<<n)-1) {
perm[x++]=pe.clone();
return ;
}
for (int i = 0; i < n; i++) {
if((v&1<<i)==0) {
pe[idx]=aa[i];
permutation(idx+1, v|1<<i);
}
}
return ;
}
public static void pre2() {
for (int i = 0; i < pow.length; i++) {
long x=1l<<i;
pow[i]=x+"";
}
}
public static void sort(int[]a) {
mergesort(a, 0, a.length-1);
}
public static void sortIdx(long[]a,long[]idx) {
mergesortidx(a, idx, 0, a.length-1);
}
public static long C(int a,int b) {
long x=fac[a];
long y=fac[a-b]*fac[b];
return x*pow(y,mod-2)%mod;
}
public static long pow(long a,long b) {
long ans=1;a%=mod;
for(long i=b;i>0;i/=2) {
if((i&1)!=0)
ans=ans*a%mod;
a=a*a%mod;
}
return ans;
}
public static void pre(){
fac[0]=1;
fac[1]=1;
fac[2]=1;
for (int i = 3; i < fac.length; i++) {
fac[i]=((fac[i-1]*2*i)/2)%mod;
}
}
public static long eval(String s) {
long p=1;
long res=0;
for (int i = 0; i < s.length(); i++) {
res+=p*(s.charAt(s.length()-1-i)=='1'?1:0);
p*=2;
}
return res;
}
public static String binary(long x) {
String s="";
while(x!=0) {
s=(x%2)+s;
x/=2;
}
return s;
}
public static boolean allSame(String s) {
char x=s.charAt(0);
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i)!=x)return false;
}
return true;
}
public static boolean isPalindrom(String s) {
int l=0;
int r=s.length()-1;
while(l<r) {
if(s.charAt(r--)!=s.charAt(l++))return false;
}
return true;
}
public static boolean isSubString(String s,String t) {
int ls=s.length();
int lt=t.length();
boolean res=false;
for (int i = 0; i <=lt-ls; i++) {
if(t.substring(i, i+ls).equals(s)) {
res=true;
break;
}
}
return res;
}
public static boolean isSorted(long[]a) {
for (int i = 0; i < a.length-1; i++) {
if(a[i]>a[i+1])return false;
}
return true;
}
public static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
public static int whichPower(int x) {
int res=0;
for (int j = 0; j < 31; j++) {
if((1<<j&x)!=0) {
res=j;
break;
}
}
return res;
}
public static long evaln(String x,int n) {
long res=0;
for (int i = 0; i < x.length(); i++) {
res+=Long.parseLong(x.charAt(x.length()-1-i)+"")*Math.pow(n, i);
}
return res;
}
static void merge(int[] arr,int b,int m,int e) {
int len1=m-b+1,len2=e-m;
int[] l=new int[len1];
int[] r=new int[len2];
for(int i=0;i<len1;i++)l[i]=arr[b+i];
for(int i=0;i<len2;i++)r[i]=arr[m+1+i];
int i=0,j=0,k=b;
while(i<len1 && j<len2) {
if(l[i]<r[j])arr[k++]=l[i++];
else arr[k++]=r[j++];
}
while(i<len1)arr[k++]=l[i++];
while(j<len2)arr[k++]=r[j++];
return;
}
static void mergesortidx(long[] arr,long[]idx,int b,int e) {
if(b<e) {
int m=b+(e-b)/2;
mergesortidx(arr,idx,b,m);
mergesortidx(arr,idx,m+1,e);
mergeidx(arr,idx,b,m,e);
}
return;
}
static void mergeidx(long[] arr,long[]idx,int b,int m,int e) {
int len1=m-b+1,len2=e-m;
long[] l=new long[len1];
long[] lidx=new long[len1];
long[] r=new long[len2];
long[] ridx=new long[len2];
for(int i=0;i<len1;i++) {
l[i]=arr[b+i];
lidx[i]=idx[b+i];
}
for(int i=0;i<len2;i++) {
r[i]=arr[m+1+i];
ridx[i]=idx[m+1+i];
}
int i=0,j=0,k=b;
while(i<len1 && j<len2) {
if(l[i]<=r[j]) {
arr[k++]=l[i++];
idx[k-1]=lidx[i-1];
}
else {
arr[k++]=r[j++];
idx[k-1]=ridx[j-1];
}
}
while(i<len1) {
idx[k]=lidx[i];
arr[k++]=l[i++];
}
while(j<len2) {
idx[k]=ridx[j];
arr[k++]=r[j++];
}
return;
}
static void mergesort(int[] arr,int b,int e) {
if(b<e) {
int m=b+(e-b)/2;
mergesort(arr,b,m);
mergesort(arr,m+1,e);
merge(arr,b,m,e);
}
return;
}
static long mergen(int[] arr,int b,int m,int e) {
int len1=m-b+1,len2=e-m;
int[] l=new int[len1];
int[] r=new int[len2];
for(int i=0;i<len1;i++)l[i]=arr[b+i];
for(int i=0;i<len2;i++)r[i]=arr[m+1+i];
int i=0,j=0,k=b;
long c=0;
while(i<len1 && j<len2) {
if(l[i]<r[j])arr[k++]=l[i++];
else {
arr[k++]=r[j++];
c=c+(long)(len1-i);
}
}
while(i<len1)arr[k++]=l[i++];
while(j<len2)arr[k++]=r[j++];
return c;
}
static long mergesortn(int[] arr,int b,int e) {
long c=0;
if(b<e) {
int m=b+(e-b)/2;
c=c+(long)mergesortn(arr,b,m);
c=c+(long)mergesortn(arr,m+1,e);
c=c+(long)mergen(arr,b,m,e);
}
return c;
}
public static long fac(int n) {
if(n==0)return 1;
return n*fac(n-1);
}
public static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long summ(long x) {
long sum=0;
while(x!=0) {
sum+=x%10;
x=x/10;
}
return sum;
}
public static ArrayList<Integer> findDivisors(int n){
ArrayList<Integer>res=new ArrayList<Integer>();
for (int i=1; i<=Math.sqrt(n); i++)
{
if (n%i==0)
{
// If divisors are equal, print only one
if (n/i == i)
res.add(i);
else {
res.add(i);
res.add(n/i);
}
}
}
return res;
}
public static void sort2darray(Integer[][]a){
Arrays.sort(a,Comparator.<Integer[]>comparingInt(x -> x[0]).thenComparingInt(x -> x[1]));
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public int[] nextArrint(int size) throws IOException {
int[] a=new int[size];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextInt();
}
return a;
}
public long[] nextArrlong(int size) throws IOException {
long[] a=new long[size];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextLong();
}
return a;
}
public int[][] next2dArrint(int rows,int columns) throws IOException{
int[][]a=new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
a[i][j]=sc.nextInt();
}
}
return a;
}
public long[][] next2dArrlong(int rows,int columns) throws IOException{
long[][]a=new long[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
a[i][j]=sc.nextLong();
}
}
return a;
}
}
static class Side{
Point a;
Point b;
public Side(Point a,Point b) {
this.a=a;
this.b=b;
}
@Override
public boolean equals(Object obj) {
Side s=(Side)obj;
return (s.a.equals(a)&&s.b.equals(b))||(s.b.equals(a)&&s.a.equals(b));
}
@Override
public String toString() {
return "("+a.toString()+","+b.toString()+")";
}
}
static class Point{
int x;
int y;
int z;
public Point(int x,int y,int z) {
this.x=x;
this.y=y;
this.z=z;
}
@Override
public boolean equals(Object obj) {
Point p=(Point)obj;
return x==p.x&&y==p.y&&z==p.z;
}
@Override
public String toString() {
return "("+x+","+y+","+z+")";
}
}
static class Pair implements Comparable{
long x;
long y;
public Pair(long x,long y) {
this.x=x;
this.y=y;
}
@Override
public boolean equals(Object obj) {
Pair p=(Pair)obj;
return x==p.x&&y==p.y;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "("+x+","+y+")";
}
@Override
public int compareTo(Object o) {
Pair p=(Pair)o;
return x>p.x?1:x==p.x?0:-1;
}
}
static class sPair{
String s;
Pair p;
public sPair(String s,Pair p) {
this.p=p;
this.s=s;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return s+" "+p;
}
}
static Scanner sc=new Scanner(System.in);
static PrintWriter pw=new PrintWriter(System.out);
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 57d953770d660c2158492e0c67152444 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /**
*
*/
import java.util.Arrays;
import java.util.Scanner;
/**
* @author rohithvazhathody
*
*
*/
public class MinimumExtraction {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
Long[] nums = new Long[n];
for (int i = 0; i < n; i++) {
nums[i] = sc.nextLong();
}
System.out.println(findTheMinimumExtraction(nums, n));
}
}
private static Long findTheMinimumExtraction(Long[] nums, int n) {
if (n == 1) {
return nums[0];
}
Arrays.sort(nums);
long maxAnswer = nums[0];
for (int i = 0; i < n - 1; i++) {
long currentMin = nums[i + 1] - nums[i];
if (maxAnswer < currentMin) {
maxAnswer = currentMin;
}
}
return maxAnswer;
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 95140654c7b159c49a96ee3d7e473184 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
/**
* @author KaiXin
* @version 11
* @date 2022-07-12 20:06
*/
public class TaskC {
static final int SIZE = (int)2e5 + 5;
static ArrayList<Long> li = new ArrayList<>();
public static void solve(InputReader in,PrintWriter out){
int n = in.nextInt();
li.clear();
for(int i = 1; i <= n; ++i){
long v = in.nextLong();
li.add(v);
}
li.sort(Long::compareTo);
int len = li.size();
long res = li.get(0);
for(int i = 1; i < len; ++i){
long t = li.get(i - 1);
res = Math.max(res,li.get(i) - t);
}
out.println(res);
}
public static void init(){}
public static void clear(int n){}
public static void main(String[] args) {
init();
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = 1;
T = in.nextInt();
for (int i = 1; i <= T; ++i) {
solve(in,out);
}
out.close();
}
private static class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String str = "";
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
/*
1
2
2 3
*/ | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | e58ff4a1433e02b1a9d201d08b55a32f | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Solver {
public static void main(String[] args) {
PrintWriter pw = new PrintWriter(System.out);
br = new BufferedReader(new InputStreamReader(System.in));
int t = nextInt();
for (int i = 0; i < t; i++) {
int a = nextInt();
Integer mas[] = new Integer[a];
for (int j = 0; j < a; j++) {
mas[j] = nextInt();
}
Collections.sort(Arrays.asList(mas));
long min = mas[0];
long sum = 0;
for (int j = 1; j < a; j++) {
int copy = mas[j];
min=Math.max(min,(mas[j]-mas[j-1]));
sum+=copy;
}
pw.println(min);
}
pw.close();
}
static BufferedReader br;
static StringTokenizer st;
static String nextToken() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
static int nextInt() {
return Integer.parseInt(nextToken());
}
static long nextLong() {
return Long.parseLong(nextToken());
}
static double nextDouble() {
return Double.parseDouble(nextToken());
}
static String next() {
return nextToken();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 50550892f1dbf2ecd204083745dd0715 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static class FastInput{
private BufferedReader br;
private StringTokenizer st;
public FastInput(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next(){
while (st == null || !st.hasMoreTokens()){
try {
st = new StringTokenizer(br.readLine());
}catch (IOException obj){
System.out.println(obj);
}
}
return st.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public Double nextDouble(){
return Double.parseDouble(next());
}
public String nextLine(){
String str = "";
try {
str = br.readLine().trim();
}catch (IOException O){
O.printStackTrace();
}
return str;
}
public int[] inputIntArray(int n){
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = nextInt();
return arr;
}
public long[] inputLongArray(int n){
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = nextLong();
return arr;
}
}
public static class FastOutput{
private final BufferedWriter bw;
public FastOutput(){
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException{
bw.write(""+object+" ");
}
public void println(Object object) throws IOException{
bw.write(""+object+"\n");
}
public void intArrayPrintln(int[] arr)throws IOException{
for(int obj : arr)
println(obj);
}
public void longArrayPrintln(long[] arr)throws IOException{
for(long obj : arr)
println(obj);
}
public void flush()throws IOException{
bw.flush();
}
public void close() throws IOException{
bw.close();
}
}
public static void main(String[] args) throws IOException{
FastInput input = new FastInput();
FastOutput out = new FastOutput();
int test = input.nextInt();
int max = 0;
while (test-- > 0){
int size = input.nextInt();
ArrayList<Integer> arr = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
arr.add(input.nextInt());
}
Collections.sort(arr);
int sum = 0;
for (int i = 0; i < size; i++) {
int min = arr.get(i);
if(i == 0)
max = min;
else
max = Math.max(min,max);
//System.out.println(sum);
sum += min;
if(i < size-1)
arr.set(i+1,arr.get(i+1)-sum);
}
out.println(max);
out.flush();
}
out.close();
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | b90fdef59948aacb1eea582388af397f | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class CodeForces {
static void sort (int[]a){
ArrayList<Integer> b = new ArrayList<>();
for(int i:a)b.add(i);
Collections.sort(b);
for(int i=0;i<b.size();i++){
a[i]=b.get(i);
}
}
static int manage(int[]arr){
sort(arr);
int ans=arr[0];
int sub=0;
for(int i=0;i<arr.length;i++){
int val = arr[i]-sub;
sub+=val;
ans=Math.max(ans, val);
}
return ans;
}
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int t = sc.nextInt();
StringBuilder sb = new StringBuilder();
for (int i=0;i<t;i++){
int n =sc.nextInt();
int []A = new int [n];
for (int j=0;j<n;j++){
A[j]=sc.nextInt();
}
sb.append(manage(A)+"\n");
}
System.out.println(sb.toString());
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | c568828f65a9f4c6b3b72704069dca9c | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class C {
public static void main(String args[]) {
Scanner fs = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int T = fs.nextInt();
for(int loop=1; loop<=T; loop++) {
int n = fs.nextInt();
if(n == 1) {
System.out.println(fs.nextInt());
continue;
}
PriorityQueue<Integer> h = new PriorityQueue<>();
for(int i = 0; i < n; i++) h.offer(fs.nextInt());
int p = 0;
int ans = 0;
while(!h.isEmpty()) {
int x = h.poll();
x += p;
p -= x;
ans = Math.max(ans, x);
}
// int[] a = new int[n];
// for(int i = 0; i < n; i++) a[i] = fs.nextInt();
// int prefix = 0;
// Arrays.sort(a);
// int ans = Integer.MIN_VALUE;
// for(int i = 0; i < n; i++) {
// a[i] += prefix;
// prefix -= a[i];
// ans = Math.max(ans, a[i]);
// }
System.out.println(ans);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 277ddff6c1ee7268aa423825f69de920 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class WriteNow {
public static void main(String[] args) throws IOException {
MyReader reader = new MyReader();
MyWriter writer = new MyWriter();
int q = reader.nextInt();
while(q-- > 0) {
int n = reader.nextInt();
ArrayList<Integer> list = new ArrayList<>(n);
for(int i = 0 ; i < n ; i ++) {
list.add(reader.nextInt());
}
int sum = 0;
Collections.sort(list);
long max = list.get(0);
for(int i = 0 ; i < n - 1 ; i ++) {
sum -= (list.get(i) + sum);
max = Math.max(max, list.get(i + 1) + sum);
}
writer.println(max);
}
writer.close();
}
}
class MyReader {
private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private StringTokenizer tokenizer = new StringTokenizer("");
private String innerNextLine() {
try {
return reader.readLine();
} catch (IOException ex) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String nextLine = innerNextLine();
if (nextLine == null) {
return false;
}
tokenizer = new StringTokenizer(nextLine);
}
return true;
}
public String nextLine() {
tokenizer = new StringTokenizer("");
return innerNextLine();
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Long nextLong() {
return Long.parseLong(next());
}
}
class MyWriter implements Closeable {
private BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
public void print(Object object) throws IOException {
writer.write(object.toString());
}
public void println(Object object) throws IOException {
writer.write(object.toString());
writer.write(System.lineSeparator());
}
@Override
public void close() throws IOException {
writer.close();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 7ec4efad2dfd01c79f60ce52bab0e2c8 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | //package div3_753;
import java.util.*;
public class MinExtract_C {
private static int getMinExtract(List<Integer>list,int len) {
Collections.sort(list);
int Min=list.get(0);
for(int i=0;i<len-1;i++)
Min=Math.max(Min, list.get(i+1)-list.get(i));
return Min;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int test_case=in.nextInt();
while(test_case-->0) {
int len=in.nextInt();
List<Integer>list=new ArrayList<>();
for(int i=0;i<len;i++)
list.add(in.nextInt());
int res=getMinExtract(list,len);
System.out.println(res);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | b84c9e86d145500943fa2a728069fddd | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main1670c {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int time = sc.nextInt();
while (time-- > 0) {
int n = sc.nextInt();
if (n==1) {
System.out.println(sc.nextInt());
continue;
}
PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1 - o2;
};
});
while (n-- > 0) {
priorityQueue.add(sc.nextInt());
}
int sumcontrol = 0;
int max = Integer.MIN_VALUE;
while (priorityQueue.size() != 1) {
int temp = priorityQueue.poll();
temp+=sumcontrol;
max = Math.max(max, temp);
sumcontrol -=temp ;
}
max = Math.max(max, priorityQueue.poll()+sumcontrol);
System.out.println(max);
}
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 4b059c43dda120c9422552fd2268d335 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for(int i=0;i<n;i++)
{
pq.add(sc.nextInt());
}
int max=pq.poll();
int temp1=max;
while(!pq.isEmpty())
{
int temp2=pq.poll();
if( temp2-temp1>max)
{
max=temp2-temp1;
}
temp1=temp2;
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 1f28994a376ed84bbd033188e1a9e7ac | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
for (int j = 0 ; j < t ; j++) {
int n = sc.nextInt();
Integer[] vals = new Integer[n];
for (int k = 0 ; k < n ; k++) {
vals[k] = sc.nextInt();
}
Arrays.sort(vals);
long max = vals[0];
for (int k = 1 ; k < n ; k++) {
max = Math.max(max,vals[k] - vals[k-1] );
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 9d9fd602240454804b93087f346f47d2 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class codeforcesB{
public static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String args[]){
FastReader sc=new FastReader();
StringBuilder sb=new StringBuilder();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
Integer ar[]=new Integer[n];
for(int i=0;i<n;i++){ar[i]=sc.nextInt();}
Arrays.sort(ar);
long x=ar[0];
long min=ar[0];
for(int i=1;i<n;i++){
min=Math.max(min,(long)ar[i]-x);
x+=(long)((long)ar[i]-x);
}
System.out.println(min);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 1d590491313d13cd73f0fbde1f0cd0b5 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader f= new BufferedReader(new InputStreamReader(System.in));
StringTokenizer s=new StringTokenizer(f.readLine());
int t=Integer.parseInt(s.nextToken());
for(int i=0;i<2*t;i+=2){
ArrayList<Integer> arr=new ArrayList<Integer>();
s=new StringTokenizer(f.readLine());
int n=Integer.parseInt(s.nextToken());
s=new StringTokenizer(f.readLine());
for(int k=0;k<n;k++){
arr.add(Integer.parseInt(s.nextToken()));
}
Collections.sort(arr);
int max=arr.get(0);
for(int k=1;k<arr.size();k++){
max=Math.max(max,arr.get(k)-arr.get(k-1));
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 8b45a52600c1fb05946c8bfbcb116c12 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | // Working program with FastReader
import java.io.*;
import java.util.*;
public class hh
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static final int MAXN = 100001;
// stores smallest prime factor for every number
static int spf[] = new int[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
static void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
// checking if i is prime
if (spf[i] == i)
{
// marking SPF for all numbers divisible by i
for (int j=i*i; j<MAXN; j+=i)
// marking spf[j] if it is not
// previously marked
if (spf[j]==j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
static int getFactorization(int x)
{
int c=0;
while (x != 1)
{
c++;
x = x / spf[x];
}
return c;
}
/*
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(int a[], int x) {// x is the key or target value
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
*/
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// method to return LCM of two numbers
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
public static int[] swap(int a[], int left, int right)
{
int temp = a[left];
a[left] = a[right];
a[right] = temp;
return a;
}
public static int[] reverse(int a[], int left, int right)
{
// Reverse the sub-array
while (left < right) {
int temp = a[left];
a[left++] = a[right];
a[right--] = temp;
}
return a;
}
public static int[] findNextPermutation(int a[])
{
int last = a.length - 2;
// find the longest non-increasing suffix
// and find the pivot
while (last >= 0) {
if (a[last] < a[last + 1]) {
break;
}
last--;
}
// If there is no increasing pair
// there is no higher order permutation
if (last < 0)
return a;
int nextGreater = a.length - 1;
// Find the rightmost successor to the pivot
for (int i = a.length - 1; i > last; i--) {
if (a[i] > a[last]) {
nextGreater = i;
break;
}
}
// Swap the successor and the pivot
a = swap(a, nextGreater, last);
// Reverse the suffix
a = reverse(a, last + 1, a.length - 1);
// Return true as the next_permutation is done
return a;
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static double pow(double p,double tt)
{
double ii,q,r;
q=1;
r=p;
while(tt>1)
{
for(ii=1;2*ii<=tt;ii*=2)
p*=p;
tt-=ii;
q*=p;
p=r;
}
if(tt==1)
q*=r;
return q;
}
static long pow(long p,long tt,long mod)
{
long ii,q,r;
q=1l;
r=p;
while(tt>1)
{
for(ii=1l;2*ii<=tt;ii*=2l)
p=((p%mod)*(p%mod))%mod;
tt-=ii;
q=((q%mod)*(p%mod))%mod;
p=r;
}
if(tt==1)
q=((q%mod)*(r%mod))%mod;
return q;
}
static int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
public static long primeFactors(long n)
{
long c=0l;
long max=0l;
long z=0l;
//ArrayList <Integer> ll=new ArrayList<>();
// Print the number of 2s that divide n
while (n%2==0)
{
c++;
n /= 2l;
//ll.add(2);
}
if(c>max)
{
max=c;
z=2;
}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (int i = 3; i <= Math.sqrt(n); i+= 2)
{
// While i divides n, print i and divide n
c=0;
while (n%i == 0)
{
c++;
n /= i;
//ll.add(i);
}
if(c>max)
{
max=c;
z=i;
}
}
c=0;
// This condition is to handle the case whien
// n is a prime number greater than 2
if (n > 2)
{
c++;
//ll.add((int)n);
}
if(c>max)
{
max=c;
z=n;
}
return z;
}
static void PrimeList(){
int i,j;
int sieve[]=new int[100001];
for(i=2;i*i<=100000;i++)
{
if(sieve[i]==0)
{
for(j=i*i;j<=100000;j+=i)
sieve[j]=1;
}
}
ArrayList<Integer> primes=new ArrayList<>();
for(i=2;i<=100000;i++)
{
if(sieve[i]==0)
primes.add(i);
}
}
static int comp(int a[],int b[],int n)
{
int z=0;
for(int i=0;i<n;i++)
{
if(a[i]!=b[i])
{
z=1;
break;
}
}
if(z==0)
return 1;
else
return 0;
}
static boolean isPowerOfTwo(int x)
{
return x!=0 && ((x&(x-1))==0);
}
static long calc (int a[],int b[],int n,int mod)
{
long sum=0l;
int i;
HashMap<Long,Long>x=new HashMap<>();
HashMap<Long,Long>y=new HashMap<>();
for(i=0;i<n;i++)
{
x.put((long)a[i],(long)i);
y.put((long)b[i],(long)i);
}
for(i=0;i<n;i++)
{
sum=(sum+Math.abs(x.get((long)i)-y.get((long)i))%mod)%mod;
}
return sum;
}
static int[] rotate(int arr[])
{
int x = arr[arr.length-1], i;
for (i = arr.length-1; i > 0; i--)
arr[i] = arr[i-1];
arr[0] = x;
return arr;
}
public static void main(String[] args)
{
//try
//{
FastReader d=new FastReader();
PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringBuilder sb=new StringBuilder();
int t,i,j,k,l,r,n;
int mod = (int) 1e9 + 7;
int Inf=Integer.MAX_VALUE;
int negInf=Integer.MIN_VALUE;
t=d.nextInt();
//t=1;
String s,s1;
//char ch1,ch2,ch3,ch4;
long ans,c,z;
while(t-->0)
{
z=c=0l;
ans=0l;
n=d.nextInt();
long a[]=new long[n];
for(i=0;i<n;i++)
a[i]=d.nextLong();
sort(a);
long x=0l;
if(n==1)
pr.println(a[0]);
else
{
long min=a[0];
x=a[0];
for(i=1;i<n;i++)
{
if(a[i]-x>min)
min=a[i]-x;
x=a[i];
}
pr.println(min);
}
}
/*
}catch(Exception e) {
System.out.println(0);
}*/
pr.flush();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 339583ad9175d513aa18b3493925ccc4 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class CMinimumExtraction2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0) {
int n = in.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
for(int i = 0; i < n; i++) {
arr.add(in.nextInt());
}
Collections.sort(arr);
//ArrayList<Integer> array = new ArrayList<Integer>();
//int[] array = new int[n];
int max = arr.get(0);
for(int j = 0; j < n-1; j++) {
int max1 = arr.get(j+1) - arr.get(j);
max = Math.max(max, max1);
}
System.out.println(max);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 1bdd95731178eb1167f2a417a023499c | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class C1607{
static FastScanner fs = null;
public static void main(String[] args) {
fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
while (t-->0) {
int n = fs.nextInt();
int cp = 0;
long mn = Long.MAX_VALUE;
cp = n;
long pa[] = new long[cp];
for(int i=0;i<n;i++){
pa[i] = fs.nextLong();
}
long ans = 0;
if(n==1){
ans = pa[0];
}
else{
sort(pa);
long min[] = new long[cp];
min[cp-1] = pa[cp-1];
for(int i=cp-2;i>=0;i--){
min[i] = Math.min(min[i+1],pa[i]);
}
long max = pa[0];
long sum = pa[0];
for(int i=1;i<cp;i++){
long mi = pa[i]-sum;
max = Math.max(max,mi);
sum+=mi;
}
ans = max;
}
out.println(ans);
}
out.println();
out.close();
}
static void sort(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 1c2ee39a48d0060efe482612270478ff | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /*
* Everything is Hard
* Before Easy
* Jai Mata Dii
*/
import java.util.*;
import java.io.*;
public class Main {
static class FastReader{ BufferedReader br;StringTokenizer st;public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));}String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}int nextInt(){ return Integer.parseInt(next());}long nextLong(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}String nextLine(){String str = ""; try{str = br.readLine(); } catch (IOException e) {e.printStackTrace();} return str; }}
static long mod = (long)(1e9+7);
// static long mod = 998244353;
// static Scanner sc = new Scanner(System.in);
static FastReader sc = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
public static void main (String[] args) {
int ttt = 1;
ttt = sc.nextInt();
z :for(int tc=1;tc<=ttt;tc++){
int n = sc.nextInt();
long arr[] = new long[n];
for(int i=0;i<n;i++) {
arr[i] = sc.nextLong();
}
sort(arr);
ArrayList<Long> a = new ArrayList<>();
int i = 0;
while(i<n) {
a.add(arr[i++]);
}
long ans = Math.min(a.get(0), a.get(n-1));
int l=0, h=n-1;
long cur = 0;
while(l<=h) {
long now = cur + Math.min(a.get(l)-cur, a.get(h)-cur);
if(a.get(l)-cur > a.get(h)-cur) {
ans = Math.max(ans, a.get(h)-cur);
cur = now;
h--;
}
else {
ans = Math.max(ans, a.get(l)-cur);
cur = now;
l++;
}
}
out.write(ans+"\n");
}
out.close();
}
static long pow(long a, long b){long ret = 1;while(b>0){if(b%2 == 0){a = (a*a)%mod;b /= 2;}else{ret = (ret*a)%mod;b--;}}return ret%mod;}
static long gcd(long a,long b){if(b==0) return a; return gcd(b,a%b); }
private static void sort(int[] a) {List<Integer> k = new ArrayList<>();for(int val : a) k.add(val);Collections.sort(k);for(int i=0;i<a.length;i++) a[i] = k.get(i);}
private static void ini(List<Integer>[] tre2){for(int i=0;i<tre2.length;i++){tre2[i] = new ArrayList<>();}}
private static void init(List<int[]>[] tre2){for(int i=0;i<tre2.length;i++){tre2[i] = new ArrayList<>();}}
private static void sort(long[] a) {List<Long> k = new ArrayList<>();for(long val : a) k.add(val);Collections.sort(k);for(int i=0;i<a.length;i++) a[i] = k.get(i);}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 1f07836fe29dd2c5473ebaae72949958 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class Codechef
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
try {
FastReader sc = new FastReader();
PrintWriter pout = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
ArrayList<Long> arr = new ArrayList<>();
for(int i=0;i<n;i++)
{
arr.add(sc.nextLong());
}
Collections.sort(arr);
long max = arr.get(0);
long temp =0;
ArrayList<Long> ans = new ArrayList<>();
ans.add(arr.get(0));
for(int i=1;i<n;i++)
{
ans.add(arr.get(i)-arr.get(i-1));
}
pout.println(Collections.max(ans));
}
pout.flush();
} catch (Exception e) {
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 7b7c8ec72436f148d1a32f5fc8f2bfb1 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution
{
public static void main(String[] arg)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
Long a[]=new Long[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextLong();
}
Arrays.sort(a);
long res=a[0];
for(int i=0;i<n-1;i++)
{
res=Math.max(res,a[i+1]-a[i]);
}
System.out.println(res);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | d225c547ac22bf442cc6e63428828954 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | // package com.company;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
public class Main {
public static int solve(PriorityQueue<Integer> pq) {
int res = Integer.MIN_VALUE;
int sum = 0;
while(pq.size() > 0) {
int min = pq.poll();
min -= sum;
sum += min;
res = Math.max(res, min);
}
return res;
}
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();
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int j = 0 ; j < n; j++) {
pq.add(sc.nextInt());
}
System.out.println(solve(pq));
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 0643469c9490a01d58c40b85eb3ad997 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.Math;
public class Main {
public class MainSolution extends MainSolutionT {
// global vars
long[] ans;
public void init(int tests_count){
ans = new long[tests_count];
}
public class TestCase extends TestCaseT
{
public Object solve()
{
int n = readInt();
long[] a = new long[n];
readLongArrayRev(a, n);
Arrays.sort(a);
long max = a[0];
long S = 0;
for (int i=0; i<n; i++)
{
a[i] -= S;
if (max < a[i])
{
max = a[i];
}
S += a[i];
}
ans[this.caseNumber-1] = max;
return null;
}
}
public void run()
{
int t = multiply_test ? readInt() : 1;
this.init(t);
for (int i = 0; i < t; i++) {
TestCase T = new TestCase();
T.run(i + 1);
}
printArray(ans, t, '\n');
}
public void loc_params()
{
this.log_enabled = false;
}
public void params(){
this.multiply_test = true;
}
}
public class MainSolutionT extends MainSolutionBase
{
public class TestCaseT extends TestCaseBase
{
}
}
public class MainSolutionBase
{
public boolean is_local = false;
public MainSolutionBase()
{
}
public class TestCaseBase
{
public Object solve() {
return null;
}
public int caseNumber;
public TestCaseBase() {
}
public void run(int cn){
this.caseNumber = cn;
Object r = this.solve();
if ((r != null))
{
out.println(r);
}
}
}
public String impossible(){
return "IMPOSSIBLE";
}
public String strf(String format, Object... args)
{
return String.format(format, args);
}
public BufferedReader in;
public PrintStream out;
public boolean log_enabled = false;
public boolean multiply_test = true;
public void params()
{
}
public void loc_params()
{
}
private StringTokenizer tokenizer = null;
public int readInt() {
return Integer.parseInt(readToken());
}
public long readLong() {
return Long.parseLong(readToken());
}
public double readDouble() {
return Double.parseDouble(readToken());
}
public String readLn() {
try {
String s;
while ((s = in.readLine()).length() == 0);
return s;
} catch (Exception e) {
return "";
}
}
public String readToken() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
} catch (Exception e) {
return "";
}
}
public int[] readIntArray(int n) {
int[] x = new int[n];
readIntArray(x, n);
return x;
}
public void readIntArray(int[] x, int n) {
for (int i = 0; i < n; i++) {
x[i] = readInt();
}
}
public long[] readLongArray(int n) {
long[] x = new long[n];
readLongArray(x, n);
return x;
}
public void readLongArray(long[] x, int n) {
for (int i = 0; i < n; i++) {
x[i] = readLong();
}
}
public void readLongArrayRev(long[] x, int n) {
for (int i = 0; i < n; i++) {
x[n-i-1] = readLong();
}
}
public void logWrite(String format, Object... args) {
if (!log_enabled) {
return;
}
out.printf(format, args);
}
public void readLongArrayBuf(long[] x, int n) {
char[]buf = new char[1000000];
long r = -1;
int k= 0, l = 0;
long d;
while (true)
{
try{
l = in.read(buf, 0, 1000000);
}
catch(Exception E){};
for (int i=0; i<l; i++)
{
if (('0'<=buf[i])&&(buf[i]<='9'))
{
if (r == -1)
{
r = 0;
}
d = buf[i] - '0';
r = 10 * r + d;
}
else
{
if (r != -1)
{
x[k++] = r;
}
r = -1;
}
}
if (l<1000000)
return;
}
}
public void readIntArrayBuf(int[] x, int n) {
char[]buf = new char[1000000];
int r = -1;
int k= 0, l = 0;
int d;
while (true)
{
try{
l = in.read(buf, 0, 1000000);
}
catch(Exception E){};
for (int i=0; i<l; i++)
{
if (('0'<=buf[i])&&(buf[i]<='9'))
{
if (r == -1)
{
r = 0;
}
d = buf[i] - '0';
r = 10 * r + d;
}
else
{
if (r != -1)
{
x[k++] = r;
}
r = -1;
}
}
if (l<1000000)
return;
}
}
public void printArray(long[] a, int n)
{
printArray(a, n, ' ');
}
public void printArray(int[] a, int n)
{
printArray(a, n, ' ');
}
public void printArray(long[] a, int n, char dl)
{
long x;
int i, l = 0;
for (i=0; i<n; i++)
{
x = a[i];
if (x<0)
{
x = -x;
l++;
}
if (x==0)
{
l++;
}
else
{
while (x>0)
{
x /= 10;
l++;
}
}
}
l += n-1;
char[] s = new char[l];
l--;
boolean z;
for (i=n-1; i>=0; i--)
{
x = a[i];
z = false;
if (x<0)
{
x = -x;
z = true;
}
do{
s[l--] = (char)('0' + (x % 10));
x /= 10;
} while (x>0);
if (z)
{
s[l--] = '-';
}
if (i>0)
{
s[l--] = dl;
}
}
out.println(new String(s));
}
public void printArray(double[] a, int n, char dl)
{
long x;
double y;
int i, l = 0;
for (i=0; i<n; i++)
{
x = (long)a[i];
if (x<0)
{
x = -x;
l++;
}
if (x==0)
{
l++;
}
else
{
while (x>0)
{
x /= 10;
l++;
}
}
}
l += n-1 + 10*n;
char[] s = new char[l];
l--;
boolean z;
int j;
for (i=n-1; i>=0; i--)
{
x = (long)a[i];
y = (long)(1000000000*(a[i]-x));
z = false;
if (x<0)
{
x = -x;
z = true;
}
for (j=0; j<9; j++)
{
s[l--] = (char)('0' + (y % 10));
y /= 10;
}
s[l--] = '.';
do{
s[l--] = (char)('0' + (x % 10));
x /= 10;
} while (x>0);
if (z)
{
s[l--] = '-';
}
if (i>0)
{
s[l--] = dl;
}
}
out.println(new String(s));
}
public void printArray(int[] a, int n, char dl)
{
int x;
int i, l = 0;
for (i=0; i<n; i++)
{
x = a[i];
if (x<0)
{
x = -x;
l++;
}
if (x==0)
{
l++;
}
else
{
while (x>0)
{
x /= 10;
l++;
}
}
}
l += n-1;
char[] s = new char[l];
l--;
boolean z;
for (i=n-1; i>=0; i--)
{
x = a[i];
z = false;
if (x<0)
{
x = -x;
z = true;
}
do{
s[l--] = (char)('0' + (x % 10));
x /= 10;
} while (x>0);
if (z)
{
s[l--] = '-';
}
if (i>0)
{
s[l--] = dl;
}
}
out.println(new String(s));
}
public void printMatrix(int[][] a, int n, int m)
{
int x;
int i,j, l = 0;
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
{
x = a[i][j];
if (x<0)
{
x = -x;
l++;
}
if (x==0)
{
l++;
}
else
{
while (x>0)
{
x /= 10;
l++;
}
}
}
l += m-1;
}
l += n-1;
char[] s = new char[l];
l--;
boolean z;
for (i=n-1; i>=0; i--)
{
for (j=m-1; j>=0; j--)
{
x = a[i][j];
z = false;
if (x<0)
{
x = -x;
z = true;
}
do{
s[l--] = (char)('0' + (x % 10));
x /= 10;
} while (x>0);
if (z)
{
s[l--] = '-';
}
if (j>0)
{
s[l--] = ' ';
}
}
if (i>0)
{
s[l--] = '\n';
}
}
out.println(new String(s));
}
public void printMatrix(long[][] a, int n, int m)
{
long x;
int i,j, l = 0;
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
{
x = a[i][j];
if (x<0)
{
x = -x;
l++;
}
if (x==0)
{
l++;
}
else
{
while (x>0)
{
x /= 10;
l++;
}
}
}
l += m-1;
}
l += n-1;
char[] s = new char[l];
l--;
boolean z;
for (i=n-1; i>=0; i--)
{
for (j=m-1; j>=0; j--)
{
x = a[i][j];
z = false;
if (x<0)
{
x = -x;
z = true;
}
do{
s[l--] = (char)('0' + (x % 10));
x /= 10;
} while (x>0);
if (z)
{
s[l--] = '-';
}
if (j>0)
{
s[l--] = ' ';
}
}
if (i>0)
{
s[l--] = '\n';
}
}
out.println(new String(s));
}
}
public void run()
{
MainSolution S;
try {
S = new MainSolution();
S.in = new BufferedReader(new InputStreamReader(System.in));
//S.out = System.out;
S.out = new PrintStream(new BufferedOutputStream( System.out ));
} catch (Exception e) {
return;
}
S.params();
S.run();
S.out.flush();
}
public static void main(String args[]) {
Locale.setDefault(Locale.US);
Main M = new Main();
M.run();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 884bece4b0079ed42a45b37890bd5bed | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
import javax.print.attribute.standard.NumberUpSupported;
import java.math.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
public class Codechef {
public static fastReader sc = new fastReader();
public static List<Integer> primeNo = new ArrayList<>();
public final static int M = 1000000007;
public final static int iMin = Integer.MIN_VALUE;
public final static int iMax = Integer.MAX_VALUE;
public static HashMap<Integer, Integer> hashMap = new HashMap<>();
public static HashMap<Integer, Integer> isPrime = new HashMap<>();
public static class fastReader {
BufferedReader br;
StringTokenizer st;
public fastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void sieveOfEratosthenes(int n) {
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int i = 2; i <= n; i++) {
if (prime[i] == true)
primeNo.add(i);
}
}
static void sieveOfEratosthenesMap(int n) {
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
int count = 0;
for (int i = 2; i <= n; i++) {
if (prime[i] == true) {
// primeNo.add(i);
isPrime.put(i, 1);
count++;
}
hashMap.put(i, count);
}
}
public static ArrayList<Integer> removeDuplicates(List<Integer> list) {
// Create a new ArrayList
ArrayList<Integer> newList = new ArrayList<Integer>();
// Traverse through the first list
for (Integer element : list) {
// If this element is not present in newList
// then add it
if (!newList.contains(element)) {
newList.add(element);
}
}
// return the new list
return newList;
}
// returns the string binary value of a of particular size
public static String binary(int a, int size) {
String word = Integer.toBinaryString(a);
while (word.length() != size) {
word = "0" + word;
}
return word;
}
// checks if string is palindrome or not
static boolean isPalindrome(String str) {
if (str.length() == 1)
return true;
int i = 0, j = str.length() - 1;
while (i < j) {
if (str.charAt(i) != str.charAt(j))
return false;
i++;
j--;
}
return true;
}
public static boolean isEmpty(String s) {
return s == null || s.length() == 0;
}
// counts the number of occurance of str in text
public static int countMatches(String text, String str) {
if (isEmpty(text) || isEmpty(str)) {
return 0;
}
int index = 0, count = 0;
while (true) {
index = text.indexOf(str, index);
if (index != -1) {
count++;
index += str.length();
} else {
break;
}
}
return count;
}
public static void main(String[] args) throws Exception {
try {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
List<Integer> arr = new ArrayList<>();
for (int i = 0; i < n; i++) {
arr.add(sc.nextInt());
}
Collections.sort(arr);
int max = iMin;
int sub = 0;
for (int i = 0; i < n; i++) {
int current = arr.get(i) - sub;
// System.out.println("element is " + arr.get(i) + " sub:" + sub + " current is"
// + current);
sub += current;
// arr.remove(0);
if (max < current)
max = current;
}
System.out.println(max);
}
} catch (Exception e) {
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 268c781cf09d922713ecff0c03b9292b | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class s1 {
public static FastScanner scan;
public static PrintWriter out;
public static void main(String[] args) throws Exception {
scan=new FastScanner(System.in);
out=new PrintWriter(System.out);
// int T=1;
int T=scan.nextInt();
while(T-->0) {
int n=scan.nextInt();
PriorityQueue<Integer> que=new PriorityQueue<>();
for(int i=0;i<n;i++) que.add(scan.nextInt());
long max=Long.MIN_VALUE;
long glob=0;
while(que.size()>0) {
int cur=que.poll();
max=Math.max(max,cur+glob);
glob-=cur+glob;
} out.println(max);
} out.close();
}
}
class Triple {
Triple(int a,int b,int c) {
this.l=a;
this.r=b;
this.c=c;
} int l,r;
int c;
}
class Pair {
int a,b;
Pair(int a,int b) {
this.a=a;
this.b=b;
}
}
class FastScanner {
private InputStream stream;
private byte[] buf=new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) { this.stream=stream; }
int read() {
if(numChars==-1) throw new InputMismatchException();
if(curChar>=numChars) {
curChar=0;
try { numChars=stream.read(buf); }
catch(IOException e) { throw new InputMismatchException(); }
if(numChars<=0) return -1;
} return buf[curChar++];
}
boolean isSpaceChar(int c) { return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; }
boolean isEndline(int c) { return c=='\n'||c=='\r'||c==-1; }
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String next() {
int c=read();
while(isSpaceChar(c)) c=read();
StringBuilder res=new StringBuilder();
do {
res.appendCodePoint(c);
c=read();
} while(!isSpaceChar(c));
return res.toString();
}
String nextLine() {
int c=read();
while(isEndline(c)) c=read();
StringBuilder res=new StringBuilder();
do {
res.appendCodePoint(c);
c=read();
} while(!isEndline(c));
return res.toString();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 5a08ac49985523ef8b15456b6b51d99c | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Practice1 {
static long[] sort(long[] arr) {
int n=arr.length;
ArrayList<Long> al=new ArrayList<>();
for(int i=0;i<n;i++) {
al.add(arr[i]);
}
Collections.sort(al);
for(int i=0;i<n;i++) {
arr[i]=al.get(i);
}
return arr;
}
public static void main (String[] args) {
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
// out.print();
//out.println();
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
long[] arr=new long[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextLong();
}
if(n==1) {
out.println(arr[0]);
continue;
}
sort(arr);
long sub=0,max=arr[0],min=arr[0];
for(int i=1;i<n;i++) {
max=Math.max(max,arr[i]-sub-min);
sub +=arr[i];
min=arr[i]-sub;
}
out.println(max);
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 80df8cee70c56d89b5d1cee5b654a53f | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Round753C {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuffer sb=new StringBuffer();
while (t-- > 0) {
int n=Integer.parseInt(br.readLine());
args=(br.readLine()).split(" ");
int arr[]=new int[n];
PriorityQueue<Integer> pq=new PriorityQueue<>();
for (int i=0;i<n;i++) {
arr[i]=Integer.parseInt(args[i]);
pq.offer(arr[i]);
}
long sum=0,min=Long.MIN_VALUE;
while(pq.size()>0){
long a=pq.poll();
a=a-sum;
min=Math.max(min,a);
sum+=a;
}
sb.append(min).append("\n");
}
System.out.println(sb);
}
private static void printArray(int[] arr) {
for (int i : arr) {
System.out.print(i + " ");
}
System.out.println();
}
private static <T> void printArray(T[] arr) {
for (T i : arr) {
System.out.print(i + " ");
}
System.out.println();
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | bbf949e5896f61cb51337c7c8b0dcbca | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.TreeMap;
import java.util.PriorityQueue;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Iterator;
public class First {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int T = fs.nextInt();
for (int tt = 0; tt < T; tt++) {
solve(fs);
}
}
static void solve(FastScanner fs)
{
int n=fs.nextInt();
int[] arr=takeInt(n, fs);
sort(arr);
if(n==1)
{
pn(arr[0]);
}
else
{
long ans=arr[0];
for(int i=1;i<n;++i)
{
ans=Math.max(ans, (long)arr[i]-arr[i-1]);
}
pn(ans);
}
}
static int MOD=(int)(1e9+7);
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
static void pn(Object o) { System.out.println(o); }
static void p(Object o) { System.out.print(o); }
static void flush() { System.out.flush(); }
static void debugInt(int[] arr)
{
for(int i=0;i<arr.length;++i)
System.out.print(arr[i]+" ");
System.out.println();
}
static void debugIntInt(int[][] arr)
{
for(int i=0;i<arr.length;++i)
{
for(int j=0;j<arr[0].length;++j)
System.out.print(arr[i][j]+" ");
System.out.println();
}
System.out.println();
}
static void debugLong(long[] arr)
{
for(int i=0;i<arr.length;++i)
System.out.print(arr[i]+" ");
System.out.println();
}
static void debugLongLong(long[][] arr)
{
for(int i=0;i<arr.length;++i)
{
for(int j=0;j<arr[0].length;++j)
System.out.print(arr[i][j]+" ");
System.out.println();
}
System.out.println();
}
static long[] takeLong(int n, FastScanner fs)
{
long[] arr=new long[n];
for(int i=0;i<n;++i)
arr[i]=fs.nextLong();
return arr;
}
static long[][] takeLongLong(int m, int n, FastScanner fs)
{
long[][] arr=new long[m][n];
for(int i=0;i<m;++i)
for(int j=0;j<n;++j)
arr[i][j]=fs.nextLong();
return arr;
}
static int[] takeInt(int n, FastScanner fs)
{
int[] arr=new int[n];
for(int i=0;i<n;++i)
arr[i]=fs.nextInt();
return arr;
}
static int[][] takeIntInt(int m, int n, FastScanner fs)
{
int[][] arr=new int[m][n];
for(int i=0;i<m;++i)
for(int j=0;j<n;++j)
arr[i][j]=fs.nextInt();
return arr;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
class Pair
{
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 8b907ed461c9a5a892cd7ddff1814e47 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class A
{
public static void main(String ar[]){
Scanner sc= new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
Long arr[] = new Long[n];
for(int i = 0;i<n;i++)
{
arr[i]= new Long(sc.nextLong());
}
Arrays.sort(arr);
long min = arr[0];
for(int i = 0;i<n-1;i++)
{
min = Math.max(min, arr[i+1] - arr[i]);
}
System.out.println(min);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a886d69d080b19c673a10bc62a6c1475 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class cfContest1607 {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-- > 0) {
int n = scan.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
a.add(scan.nextInt());
}
Collections.sort(a);
int res = a.get(0);
for (int i = 0; i < n - 1; i++) {
res = Math.max(res,a.get(i + 1) - a.get(i));
}
System.out.println(res);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 5e8b43e7525906ce06f63faaecb1afb9 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Practice {
public static long mod = (long) Math.pow(10, 9) + 7;
public static long mod2 = 998244353;
public static int tt = 0;
public static ArrayList<Integer> prime;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
int p = 1;
// System.out.println(list.size());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
Long[] a = new Long[n];
String str = (br.readLine());
String[] s1 = str.split(" ");
for (int i = 0; i < n; i++) {
a[i] = Long.parseLong(s1[i]);
}
Arrays.sort(a);
long[] arr = new long[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = a[i].longValue();
}
long ans = Long.MIN_VALUE;
long curr = 0;
for (int i = 0; i < n; i++) {
if (i == n - 1 && arr[i] < 0) {
ans = Math.max(ans, arr[i] - curr);
break;
}
if (arr[i] < 0) {
ans = Math.max(ans, arr[i] - curr);
curr += (arr[i] - curr);
} else {
ans = Math.max(ans, arr[i] - curr);
curr += (arr[i] - curr);
}
//pw.println(ans);
}
pw.println(ans);
}
pw.close();
}
}
// private static void getFac(long n, PrintWriter pw) {
// // TODO Auto-generated method stub
// int a = 0;
// while (n % 2 == 0) {
// a++;
// n = n / 2;
// }
// if (n == 1) {
// a--;
// }
// for (int i = 3; i <= Math.sqrt(n); i += 2) {
// while (n % i == 0) {
// n = n / i;
// a++;
// }
// }
// if (n > 1) {
// a++;
// }
// if (a % 2 == 0) {
// pw.println("Bob");
// } else {
// pw.println("Alice");
// }
// //System.out.println(a);
// return;
// }
// private static long power(long a, long p) {
// // TODO Auto-generated method stub
// long res = 1;
// while (p > 0) {
// if (p % 2 == 1) {
// res = (res * a) % mod;
// }
// p = p / 2;
// a = (a * a) % mod;
// }
// return res;
// }
//
// private static void fac() {
// fac[0] = 1;
// // TODO Auto-generated method stub
// for (int i = 1; i < fac.length; i++) {
// if (i == 1) {
// fac[i] = 1;
// } else {
// fac[i] = i * fac[i - 1];
// }
// if (fac[i] > mod) {
// fac[i] = fac[i] % mod;
// }
// }
// }
//
// private static int getLower(Long long1, Long[] st) {
// // TODO Auto-generated method stub
// int left = 0, right = st.length - 1;
// int ans = -1;
// while (left <= right) {
// int mid = (left + right) / 2;
// if (st[mid] <= long1) {
// ans = mid;
// left = mid + 1;
// } else {
// right = mid - 1;
// }
// }
// return ans;
// }
// private static long getGCD(long l, long m) {
//
// long t1 = Math.min(l, m);
// long t2 = Math.max(l, m);
// while (true) {
// long temp = t2 % t1;
// if (temp == 0) {
// return t1;
// }
// t2 = t1;
// t1 = temp;
// }
// } | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | d5f3f408bdc8cb4776c16995d2507cef | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception
{
FastReader fr=new FastReader();
int t=fr.nextInt();
while(t-->0) {
int n=fr.nextInt();
PriorityQueue<Long> pq=new PriorityQueue<>();
for(int i=0;i<n;i++) {
pq.add(fr.nextLong());
}
long min=Integer.MIN_VALUE;
long rem=0;
while(!pq.isEmpty()) {
// System.out.println("p..."+pq.peek());
long f=pq.remove()-rem;
min=Math.max(min,f);
rem+=f;
// System.out.println("r..."+rem);
}
System.out.println(min);
}
}
public static int bs(long av[],long low,long high,boolean taken[]) {
int i=0;
int ans=Integer.MAX_VALUE;
int j=av.length-1;
while(i<=j) {
int mid=i+(j-i)/2;
if(av[mid]>=low&&av[mid]<=high&&taken[mid]==false) {
ans=Math.min(ans,mid);
j=mid-1;
}
else if(av[mid]<low)
i=mid+1;
else
j=mid-1;
}
return ans;
}
public static long facto(long n) {
if(n==1||n==0)
return 1;
return n*facto(n-1);
}
public static long gcd(long n1,long n2) {
if (n2 == 0) {
return n1;
}
return gcd(n2, n1 % n2);
}
public static boolean isPali(String s) {
int i=0;
int j=s.length()-1;
while(i<=j) {
if(s.charAt(i)!=s.charAt(j))
return false;
i++;
j--;
}
return true;
}
public static String reverse(String s) {
String res="";
for(int i=0;i<s.length();i++) {
res+=s.charAt(i);
}
return res;
}
public static int bsearch(long suf[],long val) {
int i=0;
int j=suf.length-1;
while(i<=j) {
int mid=(i+j)/2;
if(suf[mid]==val)
return mid;
else if(suf[mid]<val)
j=mid-1;
else
i=mid+1;
}
return -1;
}
public static int[] getFreq(String s) {
int a[]=new int[26];
for(int i=0;i<s.length();i++) {
a[s.charAt(i)-'a']++;
}
return a;
}
}
class Pair implements Comparable<Pair>{
int ele;
int freq;
Pair(int ele,int freq){
this.ele=ele;
this.freq=freq;
}
public int compareTo(Pair o) {
return (int)(o.freq-this.freq);
}
}
class myPair implements Comparable<myPair>{
String str;
String identi;
myPair(String str,String identi){
this.str=str;
this.identi=identi;
}
public int compareTo(myPair o) {
if(!this.str.equals(o.str))
return this.str.compareTo(o.str);
else {
int a=this.identi.charAt(3)-'0';
int b=o.identi.charAt(3)-'0';
return a-b;
}
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a4557acfee3cf5e50e785f991c913ee7 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import org.omg.CORBA.MARSHAL;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Solution solve = new Solution();
int t = 1;
t = scan.nextInt();
for (int qq = 0; qq < t; qq++) {
solve.solve(scan, out);
out.println();
}
out.close();
}
static class Solution {
/*
* think and coding
*/
static long MOD = (long) (1e9 + 7);
public void solve(FastReader scan, PrintWriter out) {
int n = scan.nextInt();
List<Long> arr = new ArrayList<>();
for (int i = 0; i < n; i++) {
arr.add(scan.nextLong());
}
Collections.sort(arr);
long mx = arr.get(0);
for (int i = 1; i < n; i++) {
mx = Math.max(mx,arr.get(i) - arr.get(i-1));
}
out.print(mx);
}
}
static class FastReader {
private final BufferedReader br;
private StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 338b8fda357eb4635e00bafeb334bfd2 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | //package practice;
import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class C1607 {
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static int fasterScanner() {
try {
boolean in = false;
int res = 0;
for (; ; ) {
int b = System.in.read() - '0';
if (b >= 0) {
in = true;
res = 10 * res + b;
} else if (in) {
return res;
}
}
} catch (IOException e) {
throw new Error(e);
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = fasterScanner();
while (t-- > 0) {
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
shuffle(arr, n);
Arrays.sort(arr);
long sum = arr[0];
long max = sum;
for (int i = 1; i < n; i++) {
max = Math.max(max, arr[i] - sum);
sum += arr[i] - sum;
}
out.println(max);
}
out.close();
}
private static void shuffle(int[] arr, int n) {
Random random = new Random();
for (int i = 0; i < n; i++) {
int j = random.nextInt(n);
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
char nextChar() {
return next().charAt(0);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 5db7e272cc959f238c21cb3ade2b5e8d | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.PrintWriter;
import java.util.*;
public class habd {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int tc = sc.nextInt();
while(tc-->0){
int n = sc.nextInt();
Long[] arr = new Long[n]; for(int i = 0; i<n; i++)arr[i] = sc.nextLong();
if(n == 1)pw.println(arr[0]);
else {
Arrays.sort(arr);
long ans = arr[0];
for(int i = 0; i<n-1; i++){
ans = Math.max(ans, arr[i + 1] -arr[i]);
}
pw.println(ans);
}
}
pw.flush();
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | b64faa7f2d6a8212debafa9d4a49e50d | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class SolutionB {
public static long gcd(long a, long b){
if(b==0){
return a;
}
return gcd(b, a%b);
}
public static long gcdSum(long b){
long a = 0;
long temp = b;
while(temp!=0){
a = a + temp%10;
temp = temp/10;
}
return gcd(a,b);
}
public static class Pair{
Long a;
Long b;
public Pair(Long a, Long b) {
this.a = a;
this.b = b;
}
}
public static long factorial (long n){
if(n==0)
return 1;
else if(n==1)
return n;
return n * factorial(n-1);
}
public static long lcm (long n){
if(n<3)
return n;
return lcmForBig(n,n-1);
}
private static long lcmForBig(long n, long l) {
if(l==1)
return n;
n = (n * l) / gcd(n, l);
return lcmForBig(n, l-1);
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
//int t = s.nextInt();
//long factArray[] = new long [42];
int t = s.nextInt();
for(int i =0;i<t;i++) {
int n = s.nextInt();
Integer arr[] = new Integer[n];
for(int j =0;j<n;j++){
arr[j] = s.nextInt();
}
//System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
int ans = 0;
//System.out.println(Arrays.toString(arr));
//if(arr[0]>0){
ans = arr[0];
for(int j =1;j<n;j++){
//System.out.println(arr[j] + " -- " + arr[j-1] );
if(arr[j]-arr[j-1]>ans){
ans = arr[j]-arr[j-1];
}
}
//}
System.out.println(ans);
}
return;
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 6604b802ac3a8615e781dc5d34c27466 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public class GFG {
private static int mod = 1000000007;
public static long modPow(long a, long b){
long ans = 1;
while(b > 0){
if((b & 1) != 0){
ans = mulMod(ans, a);
}
b >>= 1;
a = mulMod(a, a);
}
return ans;
}
public static long mulMod(long a, long b){
long ans = ((a % mod) * (b % mod)) % mod;
return ans;
}
public static void main (String[] args) {
Scanner scn = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int t = scn.nextInt();
while(t-- > 0){
int n = scn.nextInt();
ArrayList<Integer> al = new ArrayList<>();
for(int i=0; i<n; i++){
int num = scn.nextInt();
al.add(num);
}
Collections.sort(al);
int max_diff = al.get(0);
for(int i=0; i<n-1; i++){
int diff = al.get(i+1) - al.get(i);
max_diff = Math.max(max_diff, diff);
}
System.out.println(max_diff);
}
System.out.println(sb);
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | e2cb5b72ce2a595e6006f5d06b30943f | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter writer = new PrintWriter(System.out);
int t = sc.nextInt();
for (; t > 0; t--) {
int n = sc.nextInt();
List<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++) {
a.add(sc.nextInt());
}
Collections.sort(a);
int sum = 0;
int maxMin = a.get(0);
for (int i = 0; i < n-1; i++) {
int d = a.get(i) - sum;
maxMin = Math.max(maxMin, d);
sum += d;
}
writer.println(Math.max(a.get(n-1) - sum, maxMin));
}
writer.close();
sc.close();
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 10aa3c1ff79c8d97c53bbb9a7eb41bb1 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;
// Sachin_2961 submission //
public class Codeforces {
static void solve(){
int n = fs.nInt();
long[]ar = new long[n];
for(int i=0;i<n;i++){
ar[i] = fs.nLong();
}
sort(ar);
long ans = ar[0];
long last = ar[0];
for(int i=1;i<n;i++){
ans = max(ans,ar[i]-last);
last = ar[i];
}
out.println(ans);
}
static class Pair{
int f,s;
Pair(int f,int s){
this.f = f;
this.s = s;
}
}
static boolean multipleTestCase = true;
static FastScanner fs;
static PrintWriter out;
public static void main(String[]args){
try{
out = new PrintWriter(System.out);
fs = new FastScanner();
int tc = multipleTestCase?fs.nInt():1;
while (tc-->0)solve();
out.flush();
out.close();
}catch (Exception e){
e.printStackTrace();
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String n() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
String Line()
{
String str = "";
try
{
str = br.readLine();
}catch (IOException e)
{
e.printStackTrace();
}
return str;
}
int nInt() {return Integer.parseInt(n()); }
long nLong() {return Long.parseLong(n());}
double nDouble(){return Double.parseDouble(n());}
int[]aI(int n){
int[]ar = new int[n];
for(int i=0;i<n;i++)
ar[i] = nInt();
return ar;
}
}
public static void sort(int[] arr){
ArrayList<Integer> ls = new ArrayList<Integer>();
for(int x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
public static void sort(long[] arr){
ArrayList<Long> ls = new ArrayList<>();
for(long x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 33adb3134b7995be65d7a8fcc770b372 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution{
public static void main(String[] args){
FastReader fs = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
while(t > 0){
int n = fs.nextInt();
int[] a = new int[n];
for(int i = 0; i < a.length; i++){
a[i] = fs.nextInt();
}
sort(a);
long max = a[0];
for(int i = 1; i < a.length; i++){
max = Math.max(max, a[i] - a[i-1]);
}
out.println(max);
t--;
}
out.flush();
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 7dd673f4b240676861a73643557eed5a | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-->0) {
int n = in.nextInt();
PriorityQueue<Integer>queue = new PriorityQueue<>();
for (int i = 0; i < n; i++) {
int a = in.nextInt();
queue.offer(a);
}
int max = queue.peek();
int a = queue.poll();
if(n>1) {
int b = queue.poll();
while (!queue.isEmpty()) {
if ((b - a) > max) {
max = b - a;
}
a = b;
b = queue.poll();
}
if ((b - a) > max) {
max = b - a;
}
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | ae7679088b33813b070d1002584bd679 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
public static void main(String args[]){
FScanner in = new FScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int n=in.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=in.nextInt();
sort(arr);
long max=arr[0];
long prev=0,min=0;
for(int i=0;i<arr.length-1;i++)
{
min=arr[i];
arr[i+1]+=prev;
arr[i+1]-=(min);
max=Math.max(max,arr[i+1]);
if(min<0)
prev+=(min*-1);
else
prev-=min;
}
out.println(max);
}
out.close();
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean checkprime(int n1)
{
if(n1%2==0||n1%3==0)
return false;
else
{
for(int i=5;i*i<=n1;i+=6)
{
if(n1%i==0||n1%(i+2)==0)
return false;
}
return true;
}
}
static class FScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer sb = new StringTokenizer("");
String next(){
while(!sb.hasMoreTokens()){
try{
sb = new StringTokenizer(br.readLine());
} catch(IOException e){ }
}
return sb.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
float nextFloat(){
return Float.parseFloat(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a9f649832205c9f46b125a10cbe5b4a9 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
static FastReader in;
static PrintWriter out;
static int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
static void p(Object o) {
out.print(o);
}
static void pn(Object o) {
out.println(o);
}
static void pni(Object o) {
out.println(o);
out.flush();
}
static String n() throws Exception {
return in.next();
}
static String nln() throws Exception {
return in.nextLine();
}
static int ni() throws Exception {
return Integer.parseInt(in.next());
}
static long nl() throws Exception {
return Long.parseLong(in.next());
}
static double nd() throws Exception {
return Double.parseDouble(in.next());
}
static class FastReader {
static BufferedReader br;
static StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
static long power(long a, long b) {
if (b == 0)
return 1;
long val = power(a, b / 2);
val = val * val;
if ((b % 2) != 0)
val = val * a;
return val;
}
static ArrayList<Long> prime_factors(long n) {
ArrayList<Long> ans = new ArrayList<Long>();
while (n % 2 == 0) {
ans.add(2L);
n /= 2;
}
for (long i = 3; i <= Math.sqrt(n); i++) {
while (n % i == 0) {
ans.add(i);
n /= i;
}
}
if (n > 2)
ans.add(n);
return ans;
}
static void sort(long[] a) {
Arrays.sort(a);
}
static void reverse_sort(long[] a) {
Arrays.sort(a);
for (int i = 0; i < a.length; i++) {
long temp = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = temp;
}
}
static void sort(ArrayList<Long> a) {
Collections.sort(a);
}
static void reverse_sort(ArrayList<Long> a) {
Collections.sort(a, Collections.reverseOrder());
}
static void temp(long[] a, int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static void temp(List<Long> a, int i, int j) {
long temp = a.get(i);
a.set(j, a.get(i));
a.set(j, temp);
}
static void sieve(boolean[] prime) {
int n = prime.length - 1;
Arrays.fill(prime, true);
for (int i = 2; i * i <= n; i++) {
if (prime[i]) {
for (int j = 2 * i; j <= n; j += i) {
prime[j] = false;
}
}
}
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long mod = 1000000007;
static class pair implements Comparable<pair> {
long x, y;
public pair(long x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(pair p) {
return this.y * (p.x - 1L) > p.y * (this.x - 1L) ? 1 : -1;
}
}
public static void main(String[] args) throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int t = ni();
while (t-- > 0) {
int n = ni();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nl();
}
merge_sort(arr,0,n-1);
if (n == 1) {
pn(arr[0]);
continue;
}
long[] a = new long[n - 1];
for (int i = 1; i < n; i++) {
a[i - 1] = arr[i] - arr[0];
}
merge_sort(a,0,a.length-1);
long ans = Math.max(a[0],arr[0]);
long diff = a[0];
for (int i = 0; i < a.length; i++) {
ans = Math.max(ans, a[i] - diff);
if (i != 0)
diff += a[i] - a[i - 1];
}
pn(ans);
}
out.flush();
out.close();
}
public static void merge_sort(long[] arr, int l, int r){
if(l>=r)return ;
int mid=(l+r)/2;
merge_sort(arr, l, mid);
merge_sort(arr, mid+1, r);
merge(arr,l,mid,r);
}
static void merge(long[] arr, int l, int mid, int r){
long[] left=new long[mid-l+1];
long[] right=new long[r-mid];
for(int i=l;i<=mid;i++){
left[i-l]=arr[i];
}
for(int i=mid+1;i<=r;i++){
right[i-(mid+1)]=arr[i];
}
int left_start=0;
int right_start=0;
int left_length=mid-l+1;
int right_length=r-mid;
int temp=l;
while(left_start<left_length && right_start<right_length){
if(left[left_start]<right[right_start]){
arr[temp]=left[left_start++];
}else{
arr[temp]=right[right_start++];
}
temp++;
}
while(left_start<left_length){
arr[temp++]=left[left_start++];
}
while(right_start<right_length){
arr[temp++]=right[right_start++];
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | f34f6fed446222e3bf452b0da4a43144 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long startTime = System.currentTimeMillis();
// for global initializations and methods starts here
static long hash;
// global initialisations and methods end here
static void run() {
boolean tc = true;
AdityaFastIO r = new AdityaFastIO();
//FastReader r = new FastReader();
try (OutputStream out = new BufferedOutputStream(System.out)) {
//long startTime = System.currentTimeMillis();
int testcases = tc ? r.ni() : 1;
int tcCounter = 1;
// Hold Here Sparky------------------->>>
// Solution Starts Here
start:
while (testcases-- > 0) {
int n = r.ni();
List<Long> al = new ArrayList<>();
for (int i = 0; i < n; i++) al.add(r.nl());
PriorityQueue<Long> pq = new PriorityQueue<>();
for (long ele : al) pq.add(ele - hash);
Collections.sort(al);
long ans = al.get(0);
for (int i = 0; i < n; i++) {
long get = pq.poll() + hash;
ans = Math.max(ans, get);
hash -= get;
}
out.write((ans + " ").getBytes());
out.write(("\n").getBytes());
}
// Solution Ends Here
} catch (IOException e) {
e.printStackTrace();
}
}
static class AdityaFastIO {
final private int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
public BufferedReader br;
public StringTokenizer st;
public AdityaFastIO() {
br = new BufferedReader(new InputStreamReader(System.in));
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public AdityaFastIO(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String readLine() throws IOException {
byte[] buf = new byte[100000001]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int ni() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public long nl() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public double nd() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null) return;
din.close();
}
}
public static void main(String[] args) throws Exception {
run();
}
static long mod = 998244353;
static long modInv(long base, long e) {
long result = 1;
base %= mod;
while (e > 0) {
if ((e & 1) > 0) result = result * base % mod;
base = base * base % mod;
e >>= 1;
}
return result;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int ni() {
return Integer.parseInt(word());
}
long nl() {
return Long.parseLong(word());
}
double nd() {
return Double.parseDouble(word());
}
}
static int MOD = (int) (1e9 + 7);
static long powerLL(long x, long n) {
long result = 1;
while (n > 0) {
if (n % 2 == 1) result = result * x % MOD;
n = n / 2;
x = x * x % MOD;
}
return result;
}
static long powerStrings(int i1, int i2) {
String sa = String.valueOf(i1);
String sb = String.valueOf(i2);
long a = 0, b = 0;
for (int i = 0; i < sa.length(); i++) a = (a * 10 + (sa.charAt(i) - '0')) % MOD;
for (int i = 0; i < sb.length(); i++) b = (b * 10 + (sb.charAt(i) - '0')) % (MOD - 1);
return powerLL(a, b);
}
static long gcd(long a, long b) {
if (a == 0) return b;
else return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static long lower_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] >= x) r = m;
else l = m;
}
return r;
}
static int upper_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] <= x) l = m;
else r = m;
}
return l + 1;
}
static void addEdge(ArrayList<ArrayList<Integer>> graph, int edge1, int edge2) {
graph.get(edge1).add(edge2);
graph.get(edge2).add(edge1);
}
public static class Pair implements Comparable<Pair> {
int first;
int second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if (this.first != o.first)
return (int) (this.first - o.first);
else return (int) (this.second - o.second);
}
}
public static class PairC<X, Y> implements Comparable<PairC> {
X first;
Y second;
public PairC(X first, Y second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(PairC o) {
// TODO Auto-generated method stub
return o.compareTo((PairC) first);
}
}
static boolean isCollectionsSorted(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) <= list.get(i - 1)) return false;
return true;
}
static boolean isCollectionsSortedReverseOrder(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) >= list.get(i - 1)) return false;
return true;
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 4bb4cb144bd86ce7941fc83f5457c331 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long startTime = System.currentTimeMillis();
// for global initializations and methods starts here
// global initialisations and methods end here
static void run() {
boolean tc = true;
AdityaFastIO r = new AdityaFastIO();
//FastReader r = new FastReader();
try (OutputStream out = new BufferedOutputStream(System.out)) {
//long startTime = System.currentTimeMillis();
int testcases = tc ? r.ni() : 1;
int tcCounter = 1;
// Hold Here Sparky------------------->>>
// Solution Starts Here
start:
while (testcases-- > 0) {
int n = r.ni();
List<Long> al = new ArrayList<>();
for (int i = 0; i < n; i++) al.add(r.nl());
boolean neg = Collections.min(al) < 0;
Collections.sort(al);
if (n == 1) {
out.write((al.get(0) + " ").getBytes());
out.write(("\n").getBytes());
continue start;
}
long first = al.get(0);
int count = 0;
if (neg) {
for (int i = 1; i < n; i++) {
al.set(i, al.get(i) - first);
}
count++;
}
long min = al.get(count);
long get = al.get(count);
int i = count;
while (i < n) {
al.set(i, al.get(i) - get);
get += al.get(i);
min = Math.max(al.get(i), min);
i++;
}
out.write((min + " ").getBytes());
out.write(("\n").getBytes());
}
// Solution Ends Here
} catch (IOException e) {
e.printStackTrace();
}
}
static class AdityaFastIO {
final private int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
public BufferedReader br;
public StringTokenizer st;
public AdityaFastIO() {
br = new BufferedReader(new InputStreamReader(System.in));
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public AdityaFastIO(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String readLine() throws IOException {
byte[] buf = new byte[100000001]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int ni() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public long nl() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public double nd() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null) return;
din.close();
}
}
public static void main(String[] args) throws Exception {
run();
}
static long mod = 998244353;
static long modInv(long base, long e) {
long result = 1;
base %= mod;
while (e > 0) {
if ((e & 1) > 0) result = result * base % mod;
base = base * base % mod;
e >>= 1;
}
return result;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int ni() {
return Integer.parseInt(word());
}
long nl() {
return Long.parseLong(word());
}
double nd() {
return Double.parseDouble(word());
}
}
static int MOD = (int) (1e9 + 7);
static long powerLL(long x, long n) {
long result = 1;
while (n > 0) {
if (n % 2 == 1) result = result * x % MOD;
n = n / 2;
x = x * x % MOD;
}
return result;
}
static long powerStrings(int i1, int i2) {
String sa = String.valueOf(i1);
String sb = String.valueOf(i2);
long a = 0, b = 0;
for (int i = 0; i < sa.length(); i++) a = (a * 10 + (sa.charAt(i) - '0')) % MOD;
for (int i = 0; i < sb.length(); i++) b = (b * 10 + (sb.charAt(i) - '0')) % (MOD - 1);
return powerLL(a, b);
}
static long gcd(long a, long b) {
if (a == 0) return b;
else return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static long lower_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] >= x) r = m;
else l = m;
}
return r;
}
static int upper_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] <= x) l = m;
else r = m;
}
return l + 1;
}
static void addEdge(ArrayList<ArrayList<Integer>> graph, int edge1, int edge2) {
graph.get(edge1).add(edge2);
graph.get(edge2).add(edge1);
}
public static class Pair implements Comparable<Pair> {
int first;
int second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if (this.first != o.first)
return (int) (this.first - o.first);
else return (int) (this.second - o.second);
}
}
public static class PairC<X, Y> implements Comparable<PairC> {
X first;
Y second;
public PairC(X first, Y second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(PairC o) {
// TODO Auto-generated method stub
return o.compareTo((PairC) first);
}
}
static boolean isCollectionsSorted(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) <= list.get(i - 1)) return false;
return true;
}
static boolean isCollectionsSortedReverseOrder(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) >= list.get(i - 1)) return false;
return true;
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 0d5715dd064008590572ae4141f0e294 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
//CODE FORCES
public class anshulvmc {
public static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
public static int gcd(int a, int b) {
if (b==0) return a;
return gcd(b, a%b);
}
public static void google(int t) {
System.out.println("Case #"+t+": ");
}
// public static void gt(int[][] arr,int k) {
// int n = arr.length+1;
// k = Math.min(k,n+1);
//
// Node[] nodes = new Node[n];
// for(int i=0;i<n;i++) nodes[i] = new Node();
// for(int i=0;i<n-1;i++) {
// int a = arr[i][0];
// int b = arr[i][1];
// System.out.println(a+" "+b);
// nodes[a].adj.add(nodes[b]);
// nodes[b].adj.add(nodes[a]);
// }
//
// ArrayDeque<Node> bfs = new ArrayDeque<>();
// for(Node nn:nodes) {
// if(nn.adj.size()<2) {
// bfs.addLast(nn);
// nn.dist=0;
// }
// }
//
// while(bfs.size()>0) {
// Node nn = bfs.removeFirst();
// for(Node a : nn.adj) {
// if(a.dist!=-1) continue;
// a.usedDegree++;
// if(a.adj.size() - a.usedDegree <= 1) {
// a.dist = nn.dist+1;
// bfs.addLast(a);
// }
// }
// }
//
// int[] cs = new int[n+1];
// for(Node nn:nodes) {
// cs[nn.dist]++;
// }
// for(int i=1;i<cs.length;i++) cs[i]+=cs[i-1];
// System.out.println(n-cs[k-1]);
// }
public static class Node{
ArrayList<Node> adj = new ArrayList<>();
int dist = -1;
int usedDegree = 0;
}
public static void cat_mice(int dest,int[] arr) {
sort(arr);
int time = dest;
int timeleft = dest-1;
int counter=0;
for(int i=arr.length-1;i>=0;i--) {
int val = arr[i];
int takes = time - val;
if(takes <= timeleft) {
timeleft -= takes;
counter++;
}
}
System.out.println(counter);
}
public static void minex(int n,int[] arr) {
sort(arr);
int ans=arr[0];
for(int i=0;i<arr.length-1;i++) {
ans = Math.max(ans,arr[i+1] - arr[i]);
}
System.out.println(ans);
}
public static void robot(int n,int m,String moves) {
int left = 0;
int right = 0;
int up = 0;
int down = 0;
int h = 0;
int v = 0;
for(int i=0;i<moves.length();i++) {
char ch = moves.charAt(i);
if(ch == 'L') {
h--;
}
else if(ch == 'R') {
h++;
}
else if(ch == 'U') {
v--;
}
else {
v++;
}
left = Math.min(left,h);
right = Math.max(right,h);
up = Math.max(v,up);
down = Math.min(down,v);
}
System.out.println(left+" "+right+" "+up+" "+down);
int vmov = up - down;
int hmov = right - left;
System.out.println(hmov+" "+vmov);
if(vmov <= n && hmov <= m) {
System.out.println("possible");
}
else {
System.out.println("not possible");
}
}
public static void main(String args[])
{
Scanner scn = new Scanner(System.in);
int test = scn.nextInt();
for(int i=0;i<test;i++) {
int n = scn.nextInt();
int[] arr = new int[n];
for(int j=0;j<n;j++) {
arr[j] = scn.nextInt();
}
minex(n,arr);
}
// int n = 1;
// int[] dp = new int[2];
// System.out.println(fact(n,dp));
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 0899aa0d05ef077d90b520b124b03be1 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder bw = new StringBuilder();
int TC = Integer.parseInt(br.readLine());
while (TC-- > 0) {
int N = Integer.parseInt(br.readLine());
ArrayList<Long> S = new ArrayList<>(N);
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < N; i++) S.add(Long.parseLong(st.nextToken()));
Collections.sort(S);
long t = 0;
long ret = S.get(0);
for (int i = 0; i < N - 1; i++) {
t -= (S.get(i) + t);
ret = Math.max(ret, S.get(i + 1) + t);
}
bw.append(ret);
bw.append("\n");
}
System.out.print(bw);
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | dfde3fb4cc2a051b8aa9836d2ef9c1fe | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
static StringBuilder sb;
static long fact[];
static long mod = (long) (1e9 + 7);
static int[] arr = { 0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111 };
static void solve(int[] arr) {
if (arr.length == 1) {
sb.append(arr[0] + "\n");
return;
}
HashSet<Integer> visited = new HashSet<>();
ArrayList<Integer> uniqueElements = new ArrayList<>();
for (int ele : arr) {
if (!visited.contains(ele)) {
uniqueElements.add(ele);
visited.add(ele);
}
}
Collections.sort(uniqueElements);
if (uniqueElements.size() == 1 && uniqueElements.get(0) < 0) {
sb.append("0\n");
return;
}
long ans = uniqueElements.get(0);
for (int i = 0; i < uniqueElements.size() - 1; i++) {
long diff = uniqueElements.get(i + 1) - uniqueElements.get(i);
ans = Math.max(ans, diff);
}
sb.append(ans + "\n");
}
public static void main(String[] args) {
sb = new StringBuilder();
int test = i();
while (test-- > 0) {
int n = i();
int[] arr = readArray(n);
solve(arr);
}
out.printLine(sb);
out.flush();
out.close();
}
/*
* fact=new long[(int)1e6+10]; fact[0]=fact[1]=1; for(int i=2;i<fact.length;i++)
* { fact[i]=((long)(i%mod)1L(long)(fact[i-1]%mod))%mod; }
*/
// **************NCR%P******************
static long p(long x, long y)// POWER FXN //
{
if (y == 0)
return 1;
long res = 1;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y = y / 2;
}
return res;
}
static long ncr(int n, int r) {
if (r > n)
return (long) 0;
long res = fact[n] % mod;
// System.out.println(res);
res = ((long) (res % mod) * (long) (p(fact[r], mod - 2) % mod)) % mod;
res = ((long) (res % mod) * (long) (p(fact[n - r], mod - 2) % mod)) % mod;
// System.out.println(res);
return res;
}
// **************END******************
// *************Disjoint set
// union*********//
// ***************PRIME FACTORIZE
// ***********************************//
static TreeMap<Integer, Integer> prime(long n) {
TreeMap<Integer, Integer> h = new TreeMap<>();
long num = n;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (n % i == 0) {
int nt = 0;
while (n % i == 0) {
n = n / i;
nt++;
}
h.put(i, nt);
}
}
if (n != 1)
h.put((int) n, 1);
return h;
}
// *****CLASS PAIR
// *************************************************
static class Pair implements Comparable<Pair> {
int x;
long y;
Pair(int x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair o) {
return (int) (this.y - o.y);
}
}
// *****CLASS PAIR
// ***************************************************
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static InputReader in = new InputReader(System.in);
static OutputWriter out = new OutputWriter(System.out);
public static long[] sortlong(long[] a2) {
int n = a2.length;
ArrayList<Long> l = new ArrayList<>();
for (long i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static int[] sortint(int[] a2) {
int n = a2.length;
ArrayList<Integer> l = new ArrayList<>();
for (int i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static long pow(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 != 0) {
res = (res * x);// % modulus;
y--;
}
x = (x * x);// % modulus;
y = y / 2;
}
return res;
}
// GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
// ******LOWEST COMMON MULTIPLE
// *********************************************
public static long lcm(long x, long y) {
return (x * (y / gcd(x, y)));
}
// INPUT
// PATTERN********************************************************
public static int i() {
return in.Int();
}
public static long l() {
String s = in.String();
return Long.parseLong(s);
}
public static String s() {
return in.String();
}
public static int[] readArray(int n) {
int A[] = new int[n];
for (int i = 0; i < n; i++) {
A[i] = i();
}
return A;
}
public static long[] readArray(long n) {
long A[] = new long[(int) n];
for (int i = 0; i < n; i++) {
A[i] = l();
}
return A;
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 84b47665dfca4a420a451aa438ba6440 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class aaa {
//--------------------------INPUT READER--------------------------------//
static class fs {
public BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public fs() { this(System.in); }
public fs(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
String next() {
while (!st.hasMoreTokens()) {
try { st = new StringTokenizer(br.readLine()); }
catch (IOException e) { e.printStackTrace(); }
}
return st.nextToken();
}
int ni() { return Integer.parseInt(next()); }
long nl() { return Long.parseLong(next()); }
double nd() { return Double.parseDouble(next()); }
String ns() { return next(); }
int[] na(long nn) {
int n = (int) nn;
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
long[] nal(long nn) {
int n = (int) nn;
long[] l = new long[n];
for(int i = 0; i < n; i++) l[i] = nl();
return l;
}
}
//-----------------------------------------------------------------------//
//---------------------------PRINTER-------------------------------------//
static class Printer {
static PrintWriter w;
public Printer() {this(System.out);}
public Printer(OutputStream os) {
w = new PrintWriter(os);
}
public void p(int i) {w.println(i);};
public void p(long l) {w.println(l);};
public void p(double d) {w.println(d);};
public void p(String s) { w.println(s);};
public void pr(int i) {w.print(i);};
public void pr(long l) {w.print(l);};
public void pr(double d) {w.print(d);};
public void pr(String s) { w.print(s);};
public void pl() {w.println();};
public void close() {w.close();};
}
//------------------------------------------------------------------------//
//--------------------------VARIABLES------------------------------------//
static fs sc = new fs();
static OutputStream outputStream = System.out;
static Printer w = new Printer(outputStream);
static long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE;
static long ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE;
//-----------------------------------------------------------------------//
//--------------------------ADMIN_MODE-----------------------------------//
private static void ADMIN_MODE() throws IOException {
if (System.getProperty("ONLINE_JUDGE") == null) {
w = new Printer(new FileOutputStream("output.txt"));
sc = new fs(new FileInputStream("input.txt"));
}
}
//-----------------------------------------------------------------------//
//----------------------------START--------------------------------------//
public static void main(String[] args)
throws IOException {
ADMIN_MODE();
int t = sc.ni();while(t-->0)
solve();
w.close();
}
static void solve() throws IOException {
int n = sc.ni();
Long[] arr = new Long[n];
for(int i = 0; i < n; i++) arr[i] = sc.nl();
Arrays.sort(arr);
long state = 0;
long maxx = -100000000000L;
for(int i = 0; i < n-1; i++) {
long curr = arr[i]+state;
maxx = Math.max(maxx, arr[i]+state);
state += (-1*(arr[i]+state));
}
maxx = Math.max(maxx, arr[n-1]+state);
w.p(maxx);
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 78f8125dc52c168df5e41cfaf0991c78 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
List<Integer> arr = new ArrayList<>();
for(int i = 0;i < n;i++)
arr.add(sc.nextInt());
arr.sort(Collections.reverseOrder());
int max = arr.get(arr.size() - 1);
for(int i = 1;i < n;i++)
max = Math.max(max,arr.get(i - 1) - arr.get(i));
out.println(max);
out.flush();
}
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if(st.hasMoreTokens())
str = st.nextToken("\n");
else
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
// ********************* GCD Function *********************
//int gcd(int a, int b){
// if (b == 0)
// return a;
// return gcd(b, a % b);
//}
// ********************* Prime Number Function *********************
//int isPrime(int n){
// if(n < 2)
// return 0;
// if(n < 4)
// return 1;
// if(n % 2 == 0 or n % 3 == 0)
// return 0;
// for(int i = 5; i*i <= n; i += 6)
// if(n % i == 0 or n % (i+2) == 0)
// return 0;
// return 1;
//}
// ********************* Custom Pair Class *********************
//class Pair implements Comparable<Pair> {
// int a,b;
// public Pair(int a,int b) {
// this.a = a;
// this.b = b;
// }
// @Override
// public int compareTo(Pair other) {
// if(this.b == other.b)
// return Integer.compare(this.a,other.a);
// return Integer.compare(this.b,other.b);
// }
//}
// ****************** Segment Tree ******************
//public class SegmentTreeNode {
// public SegmentTreeNode left;
// public SegmentTreeNode right;
// public int Start;
// public int End;
// public int Sum;
// public SegmentTreeNode(int start, int end) {
// Start = start;
// End = end;
// Sum = 0;
// }
//}
//public SegmentTreeNode buildTree(int start, int end) {
// if(start > end)
// return null;
// SegmentTreeNode node = new SegmentTreeNode(start, end);
// if(start == end)
// return node;
// int mid = start + (end - start) / 2;
// node.left = buildTree(start, mid);
// node.right = buildTree(mid + 1, end);
// return node;
//}
//public void update(SegmentTreeNode node, int index) {
// if(node == null)
// return;
// if(node.Start == index && node.End == index) {
// node.Sum += 1;
// return;
// }
// int mid = node.Start + (node.End - node.Start) / 2;
// if(index <= mid)
// update(node.left, index);
// else
// update(node.right, index);
// node.Sum = node.left.Sum + node.right.Sum;
//}
//public int SumRange(SegmentTreeNode root, int start, int end) {
// if(root == null || start > end)
// return 0;
// if(root.Start == start && root.End == end)
// return root.Sum;
// int mid = root.Start + (root.End - root.Start) / 2;
// if(end <= mid)
// return SumRange(root.left, start, end);
// else if(start > mid)
// return SumRange(root.right, start, end);
// return SumRange(root.left, start, mid) + SumRange(root.right, mid + 1, end);
//} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 49082ce6c8d822ffee7a51eaf73e1836 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /********
* @author Brennan Cox
*
********/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
public Main() {
FastScanner input = new FastScanner(System.in);
StringBuilder output = new StringBuilder();
int t = input.nextInt();
for (int i = 0; i < t; i++) {
int n = input.nextInt();
ArrayList<Integer> list = new ArrayList<>();
for (int j = 0; j < n; j++) {
list.add(input.nextInt());
}
Collections.sort(list);
//sort
/*
* This section builds an array that is meant to express
* the greatest value every index could achieve
*
* this works because the modifier functionally
* effects all values implicitly the same way
* in that because it is sorted an increase on the next value
* is the same increase on all values
*
* in this method you are simply finding the best increase
*/
int[] arr = new int[n];
int modifier = 0;
for (int j = 0; j < n; j++) {
arr[j] = list.get(j) - modifier;
modifier+= arr[j];
}
/*
* Take the least of the array
*/
int max = Integer.MIN_VALUE;
for(int num : arr) {
if (num > max) {
max = num;
}
}
output.append(max + "\n");
}
System.out.println(output);
}
public static void main(String[] args) {
new Main();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner(InputStream in) {
this(new InputStreamReader(in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() { return Double.parseDouble(next());}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 63b785280825f2bc6da71a51715c772f | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /********
* @author Brennan Cox
*
********/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
public Main() {
FastScanner input = new FastScanner(System.in);
StringBuilder output = new StringBuilder();
int t = input.nextInt();
for (int i = 0; i < t; i++) {
int n = input.nextInt();
ArrayList<Integer> list = new ArrayList<>();
for (int j = 0; j < n; j++) {
list.add(input.nextInt());
}
Collections.sort(list);
int[] arr = new int[n];
int modifier = 0;
for (int j = 0; j < n; j++) {
arr[j] = list.get(j) - modifier;
modifier+= arr[j];
}
int max = Integer.MIN_VALUE;
for(int num : arr) {
if (num > max) {
max = num;
}
}
output.append(max + "\n");
}
System.out.println(output);
}
public static void main(String[] args) {
new Main();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner(InputStream in) {
this(new InputStreamReader(in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() { return Double.parseDouble(next());}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 9eafabb67f68a6df1f87772cd8b6f1f7 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class minExt
{
void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int[n1];
int R[] = new int[n2];
/*Copy data to temp arrays*/
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarray array
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
}
else {
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
void sort(int arr[], int l, int r)
{
if (l < r) {
// Find the middle point
int m =l+ (r-l)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr, m + 1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
public static void main (String[] args) throws java.lang.Exception
{
try {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=sc.nextInt();
}
minExt ob=new minExt();
ob.sort(ar,0,n-1);
int sum=0;
for (int i=0;i<n;i++) {
ar[i]-=sum;
sum+=ar[i];
}
int max=ar[0];
for(int i=0;i<n;i++)
{
if(max<ar[i])
max=ar[i];
}
System.out.println(max);
}
} catch(Exception e) {
return;
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | ace85fdaafb2346aa4bcd72f791c13c4 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | /*#####################################################
################ >>>> Diaa12360 <<<< ##################
################ Just Nothing ##################
############ If You Need it, Fight For IT; ############
####################.-. 1 5 9 2 .-.####################
######################################################*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuilder out = new StringBuilder();
StringTokenizer tk;
int t = Integer.parseInt(in.readLine());
while(t-- > 0){
int n = Integer.parseInt(in.readLine());
ArrayList<Integer> arr= new ArrayList<>();
tk = new StringTokenizer(in.readLine());
for (int i = 0; i < n; i++)
arr.add(Integer.parseInt(tk.nextToken()));
arr.sort(Integer::compare);
int min = arr.get(0);
for (int i = 0; i < arr.size()-1; i++)
if(arr.get(i+1) - arr.get(i) > min)
min = arr.get(i+1) - arr.get(i);
out.append(min).append('\n');
}
System.out.println(out);
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 3ce4f77669868fb649f04c4a2031310b | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.*;
import java.util.StringTokenizer;
public class C {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void merge(int A[],int l,int m,int r){
int n1=m-l+1;
int n2=r-m;
int L[]=new int[n1];
int R[]=new int[n2];
int k=l;
for(int i=0;i<n1;i++) L[i]=A[k+i];
for(int i=0;i<n2;i++) R[i]=A[m+i+1];
int i=0;
int j=0;
while(i<n1 && j<n2){
if(L[i]<R[j]) A[k++]=L[i++];
else A[k++]=R[j++];
}
while(j<n2) A[k++]=R[j++];
while(i<n1){
A[k++]=L[i];
i++;
}
}
static void sort(int A[],int l,int r){
if(l<r){
int m=l+(r-l)/2;
sort(A,l,m);
sort(A,m+1,r);
merge(A,l,m,r);
}
}
public static void main(String[] args) {
FastReader s=new FastReader();
int t=s.nextInt();
while(t-->0){
int n=s.nextInt();
int A[]=new int[n];
for(int i=0;i<n;i++){
A[i]=s.nextInt();
}
sort(A,0,n-1);
int ans=A[0];
for(int i=0;i<n-1;i++){
int v=(int)Math.abs(A[i+1]-A[i]);
if(ans<v) ans=v;
}
System.out.println(ans);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 822baeb453612af733035d3585f557fa | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.math.*;
import java.math.BigInteger;
public final class Template
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static int g[][];
static long mod=(long) 998244353,INF=Long.MAX_VALUE;
// static boolean set[];
static int max=0;
static int lca[][];
static int par[],col[],D[];
static long dp[][][],fact[];
static int seg[],size[],N;
static int dp1[][],dp2[][];
static HashSet<Integer> set[];
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
int T=i();
while(T-->0)
{
int N=i();
int[] arr = new int[N];
for(int i=0; i<N; ++i) {
arr[i] = i();
}
sort(arr);
int res = arr[0];
int a = -arr[0];
int max = res;
// System.out.println(res + " " + a);
for(int i=1; i<N; ++i) {
res = arr[i] + a;
a -= res;
// System.out.println(res + " " + a);
if(max < res) {
max = res;
}
}
ans.append(max+"\n");
}
out.println(ans);
out.close();
}
static int distance(int a,int b)
{
int d=D[a]+D[b];
int l=LCA(a,b);
l=2*D[l];
return d-l;
}
static int LCA(int a,int b)
{
if(D[a]<D[b])
{
int t=a;
a=b;
b=t;
}
int d=D[a]-D[b];
int p=1;
for(int i=0; i>=0 && p<=d; i++)
{
if((p&d)!=0)
{
a=lca[a][i];
}
p<<=1;
}
if(a==b)return a;
for(int i=max-1; i>=0; i--)
{
if(lca[a][i]!=-1 && lca[a][i]!=lca[b][i])
{
a=lca[a][i];
b=lca[b][i];
}
}
return lca[a][0];
}
static void dfs(int n,int p)
{
lca[n][0]=p;
if(p!=-1)D[n]=D[p]+1;
for(int c:g[n])
{
if(c!=p)
{
dfs(c,n);
}
}
}
static int[] rev(int A[],int N)
{
int B[]=new int[N];
int j=N-1;
for(int i=0; i<N; i++)B[i]=A[j--];
return B;
}
static int[] last(int A[],int N)
{
int last[]=new int[N+5];
Arrays.fill(last, -1);
for(int i=N-1; i>=0; i--)
{
int a=A[i];
if(last[a]==-1)last[a]=i;
}
return last;
}
static int f(int A[],int last[])
{
int N=A.length;
int c=0;
int i=0;
int pre[]=new int[N+5];
while(i<N && last[A[i]]==i)
{
i++;
}
int from=i;
int counter=0;
while(i<N)
{
int r=last[A[i]];
pre[i+1]+=1;
pre[r]-=1;
int max=0,index=0;
for(int j=i+1; j<r; j++)
{
if(last[A[j]]>r)
{
max=Math.max(max, last[A[j]]);
if(max==last[A[j]])index=j;
}
}
//System.out.println(max+" "+index);
if(max==0)
{
i=r+1;
while(i<N && last[A[i]]==i)i++;
}
else
{
i=index;
counter++;
}
// break;
}
for( i=1; i<=N; i++)pre[i]+=pre[i-1];
for(int a:pre)if(a>0)c++;
c-=counter;
return c;
}
static void dfs2(int n,int p,int k)
{
if(p!=-1)
{
//System.out.println(n);
for(int i=1; i<=k; i++)
{
dp2[n][i]+=dp1[n][i];
int from_par=0;
if(i-2>=0)from_par=dp2[p][i-1]-dp1[n][i-2];
else from_par=1;
//System.out.println(i+" "+from_par);
dp2[n][i]+=from_par;
}
}
for(int c:g[n])
{
if(c!=p)
dfs2(c,n,k);
}
}
static void dfs(int n,int p,int k)
{
dp1[n][0]=1;
for(int c:g[n])
{
if(c!=p)
{
dfs(c,n,k);
for(int i=1; i<=k; i++)
{
dp1[n][i]+=dp1[c][i-1];
}
}
}
}
static int[] prefix_function(char X[])//returns pi(i) array
{
int N=X.length;
int pre[]=new int[N];
for(int i=1; i<N; i++)
{
int j=pre[i-1];
while(j>0 && X[i]!=X[j])
j=pre[j-1];
if(X[i]==X[j])j++;
pre[i]=j;
}
return pre;
}
static TreeNode start;
public static void f(TreeNode root,TreeNode p,int r)
{
if(root==null)return;
if(p!=null)
{
root.par=p;
}
if(root.val==r)start=root;
f(root.left,root,r);
f(root.right,root,r);
}
static int right(int A[],int Limit,int l,int r)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<Limit)l=m;
else r=m;
}
return l;
}
static int left(int A[],int a,int l,int r)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<a)l=m;
else r=m;
}
return l;
}
static int f(int k,int x,int N)
{
int l=x-1,r=N;
while(r-l>1)
{
int m=(l+r)/2;
int a=ask(1,0,N-1,x,m);
if(a<k)
{
l=m;
}
else r=m;
}
//System.out.println("-------");
if(r==N)return -1;
return r;
}
static void build(int v,int tl,int tr,int A[])
{
if(tl==tr)
{
seg[v]=A[tl];
return;
}
int tm=(tl+tr)/2;
build(v*2,tl,tm,A);
build(v*2+1,tm+1,tr,A);
seg[v]=Math.max(seg[v*2],seg[v*2+1]);
}
static void update(int v,int tl,int tr,int index,int a)
{
if(index==tl && tl==tr)
seg[v]=a;
else
{
int tm=(tl+tr)/2;
if(index<=tm)update(2*v,tl,tm,index,a);
else update(2*v+1,tm+1,tr,index,a);
seg[v]=Math.max(seg[v*2],seg[v*2+1]);
}
}
static int ask(int v,int tl,int tr,int l,int r)
{
if(l>r)return -1;
if(l==tl && tr==r)return seg[v];
int tm=(tl+tr)/2;
return Math.max(ask(v*2,tl,tm,l,Math.min(tm, r)),ask(2*v+1,tm+1,tr,Math.max(tm+1, l),r));
}
// static int query(long a,TreeNode root)
// {
// long p=1L<<30;
// TreeNode temp=root;
// while(p!=0)
// {
// System.out.println(a+" "+p);
// if((a&p)!=0)
// {
// temp=temp.right;
//
// }
// else temp=temp.left;
// p>>=1;
// }
// return temp.index;
// }
// static void delete(long a,TreeNode root)
// {
// long p=1L<<30;
// TreeNode temp=root;
// while(p!=0)
// {
// if((a&p)!=0)
// {
// temp.right.cnt--;
// temp=temp.right;
// }
// else
// {
// temp.left.cnt--;
// temp=temp.left;
// }
// p>>=1;
// }
// }
// static void insert(long a,TreeNode root,int i)
// {
// long p=1L<<30;
// TreeNode temp=root;
// while(p!=0)
// {
// if((a&p)!=0)
// {
// temp.right.cnt++;
// temp=temp.right;
// }
// else
// {
// temp.left.cnt++;
// temp=temp.left;
// }
// p>>=1;
// }
// temp.index=i;
// }
// static TreeNode create(int p)
// {
//
// TreeNode root=new TreeNode(0);
// if(p!=0)
// {
// root.left=create(p-1);
// root.right=create(p-1);
// }
// return root;
// }
static boolean f(long A[],long m,int N)
{
long B[]=new long[N];
for(int i=0; i<N; i++)
{
B[i]=A[i];
}
for(int i=N-1; i>=0; i--)
{
if(B[i]<m)return false;
if(i>=2)
{
long extra=Math.min(B[i]-m, A[i]);
long x=extra/3L;
B[i-2]+=2L*x;
B[i-1]+=x;
}
}
return true;
}
static int f(int l,int r,long A[],long x)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]>=x)l=m;
else r=m;
}
return r;
}
static boolean f(long m,long H,long A[],int N)
{
long s=m;
for(int i=0; i<N-1;i++)
{
s+=Math.min(m, A[i+1]-A[i]);
}
return s>=H;
}
static long ask(long l,long r)
{
System.out.println("? "+l+" "+r);
return l();
}
static long f(long N,long M)
{
long s=0;
if(N%3==0)
{
N/=3;
s=N*M;
}
else
{
long b=N%3;
N/=3;
N++;
s=N*M;
N--;
long a=N*M;
if(M%3==0)
{
M/=3;
a+=(b*M);
}
else
{
M/=3;
M++;
a+=(b*M);
}
s=Math.min(s, a);
}
return s;
}
static int ask(StringBuilder sb,int a)
{
System.out.println(sb+""+a);
return i();
}
static void swap(char X[],int i,int j)
{
char x=X[i];
X[i]=X[j];
X[j]=x;
}
static int min(int a,int b,int c)
{
return Math.min(Math.min(a, b), c);
}
static long and(int i,int j)
{
System.out.println("and "+i+" "+j);
return l();
}
static long or(int i,int j)
{
System.out.println("or "+i+" "+j);
return l();
}
static int len=0,number=0;
static void f(char X[],int i,int num,int l)
{
if(i==X.length)
{
if(num==0)return;
//update our num
if(isPrime(num))return;
if(l<len)
{
len=l;
number=num;
}
return;
}
int a=X[i]-'0';
f(X,i+1,num*10+a,l+1);
f(X,i+1,num,l);
}
static boolean is_Sorted(int A[])
{
int N=A.length;
for(int i=1; i<=N; i++)if(A[i-1]!=i)return false;
return true;
}
static boolean f(StringBuilder sb,String Y,String order)
{
StringBuilder res=new StringBuilder(sb.toString());
HashSet<Character> set=new HashSet<>();
for(char ch:order.toCharArray())
{
set.add(ch);
for(int i=0; i<sb.length(); i++)
{
char x=sb.charAt(i);
if(set.contains(x))continue;
res.append(x);
}
}
String str=res.toString();
return str.equals(Y);
}
static boolean all_Zero(int f[])
{
for(int a:f)if(a!=0)return false;
return true;
}
static long form(int a,int l)
{
long x=0;
while(l-->0)
{
x*=10;
x+=a;
}
return x;
}
static int count(String X)
{
HashSet<Integer> set=new HashSet<>();
for(char x:X.toCharArray())set.add(x-'0');
return set.size();
}
static int f(long K)
{
long l=0,r=K;
while(r-l>1)
{
long m=(l+r)/2;
if(m*m<K)l=m;
else r=m;
}
return (int)l;
}
// static void build(int v,int tl,int tr,long A[])
// {
// if(tl==tr)
// {
// seg[v]=A[tl];
// }
// else
// {
// int tm=(tl+tr)/2;
// build(v*2,tl,tm,A);
// build(v*2+1,tm+1,tr,A);
// seg[v]=Math.min(seg[v*2], seg[v*2+1]);
// }
// }
static int [] sub(int A[],int B[])
{
int N=A.length;
int f[]=new int[N];
for(int i=N-1; i>=0; i--)
{
if(B[i]<A[i])
{
B[i]+=26;
B[i-1]-=1;
}
f[i]=B[i]-A[i];
}
for(int i=0; i<N; i++)
{
if(f[i]%2!=0)f[i+1]+=26;
f[i]/=2;
}
return f;
}
static int[] f(int N)
{
char X[]=in.next().toCharArray();
int A[]=new int[N];
for(int i=0; i<N; i++)A[i]=X[i]-'a';
return A;
}
static int max(int a ,int b,int c,int d)
{
a=Math.max(a, b);
c=Math.max(c,d);
return Math.max(a, c);
}
static int min(int a ,int b,int c,int d)
{
a=Math.min(a, b);
c=Math.min(c,d);
return Math.min(a, c);
}
static HashMap<Integer,Integer> Hash(int A[])
{
HashMap<Integer,Integer> mp=new HashMap<>();
for(int a:A)
{
int f=mp.getOrDefault(a,0)+1;
mp.put(a, f);
}
return mp;
}
static long mul(long a, long b)
{
return ( a %mod * 1L * b%mod )%mod;
}
static void swap(int A[],int a,int b)
{
int t=A[a];
A[a]=A[b];
A[b]=t;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
{
if(par[a]>par[b]) //this means size of a is less than that of b
{
int t=b;
b=a;
a=t;
}
par[a]+=par[b];
par[b]=a;
}
}
static boolean isSorted(int A[])
{
for(int i=1; i<A.length; i++)
{
if(A[i]<A[i-1])return false;
}
return true;
}
static boolean isDivisible(StringBuilder X,int i,long num)
{
long r=0;
for(; i<X.length(); i++)
{
r=r*10+(X.charAt(i)-'0');
r=r%num;
}
return r==0;
}
static int lower_Bound(int A[],int low,int high, int x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static String f(String A)
{
String X="";
for(int i=A.length()-1; i>=0; i--)
{
int c=A.charAt(i)-'0';
X+=(c+1)%2;
}
return X;
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static String swap(String X,int i,int j)
{
char ch[]=X.toCharArray();
char a=ch[i];
ch[i]=ch[j];
ch[j]=a;
return new String(ch);
}
static int sD(long n)
{
if (n % 2 == 0 )
return 2;
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0 )
return i;
}
return (int)n;
}
static void setGraph(int N)
{
par=new int[N+1];
// D=new int[N+1];
// g=new ArrayList[N+1];
// set=new boolean[N+1];
col=new int[N+1];
for(int i=0; i<=N; i++)
{
col[i]=-1;
// g[i]=new ArrayList<>();
// D[i]=Integer.MAX_VALUE;
}
}
static long pow(long a,long b)
{
//long mod=1000000007;
long pow=1;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}
static long toggleBits(long x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;
return ((1<<n)-1)^x;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static long fact(long N)
{
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
static int kadane(int A[])
{
int lsum=A[0],gsum=A[0];
for(int i=1; i<A.length; i++)
{
lsum=Math.max(lsum+A[i],A[i]);
gsum=Math.max(gsum,lsum);
}
return gsum;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(boolean A[][])
{
for(boolean a[]:A)print(a);
}
static void print(long A[][])
{
for(long a[]:A)print(a);
}
static void print(int A[][])
{
for(int a[]:A)print(a);
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
static long GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
}
class segNode
{
long pref,suff,sum,max;
segNode(long a,long b,long c,long d)
{
pref=a;
suff=b;
sum=c;
max=d;
}
}
//class TreeNode
//{
// int cnt,index;
// TreeNode left,right;
// TreeNode(int c)
// {
// cnt=c;
// index=-1;
// }
// TreeNode(int c,int index)
// {
// cnt=c;
// this.index=index;
// }
//}
class post implements Comparable<post>
{
long x,y,d,t;
post(long a,long b,long c)
{
x=a;
y=b;
d=c;
}
public int compareTo(post X)
{
if(X.t==this.t)
{
return 0;
}
else
{
long xt=this.t-X.t;
if(xt>0)return 1;
return -1;
}
}
}
class TreeNode
{
int val;
TreeNode left, right,par;
TreeNode() {}
TreeNode(int item)
{
val = item;
left =null;
right = null;
par=null;
}
}
class edge
{
int a,wt;
edge(int a,int w)
{
this.a=a;
wt=w;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 8fb2e2af77d5a6fda8f27d06a3375c32 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | // package faltu;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//import java.security.KeyStore.Entry;
import java.util.*;
import java.util.Map.Entry;
public class Main {
static long LowerBound(long[] a2, long x) { // x is the target value or key
int l=-1,r=a2.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a2[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(int a[], int x) {// x is the key or target value
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
public static long getClosest(long val1, long val2,long target)
{
if (target - val1 >= val2 - target)
return val2;
else
return val1;
}
static void ruffleSort(long[] a) {
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
long oi=r.nextInt(n), temp=a[i];
a[i]=a[(int)oi];
a[(int)oi]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(int[] a) {
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n), temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
Arrays.sort(a);
}
private int ceilIndex(int input[], int T[], int end, int s){
int start = 0;
int middle;
int len = end;
while(start <= end){
middle = (start + end)/2;
if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){
return middle+1;
}else if(input[T[middle]] < s){
start = middle+1;
}else{
end = middle-1;
}
}
return -1;
}
public static int findIndex(long arr[], long t)
{
if (arr == null) {
return -1;
}
int len = arr.length;
int i = 0;
while (i < len) {
if (arr[i] == t) {
return i;
}
else {
i = i + 1;
}
}
return -1;
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
public static int[] swap(int a[], int left, int right)
{
int temp = a[left];
a[left] = a[right];
a[right] = temp;
return a;
}
public static void swap(long x,long max1)
{
long temp=x;
x=max1;
max1=temp;
}
public static int[] reverse(int a[], int left, int right)
{
// Reverse the sub-array
while (left < right) {
int temp = a[left];
a[left++] = a[right];
a[right--] = temp;
}
return a;
}
static int lowerLimitBinarySearch(ArrayList<Integer> A,int B) {
int n =A.size();
int first = 0,second = n;
while(first <second) {
int mid = first + (second-first)/2;
if(A.get(mid) > B) {
second = mid;
}else {
first = mid+1;
}
}
if(first < n && A.get(first) < B) {
first++;
}
return first; //1 index
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
// *******----segement tree implement---*****
// -------------START--------------------------
void buildTree (int[] arr,int[] tree,int start,int end,int treeNode)
{
if(start==end)
{
tree[treeNode]=arr[start];
return;
}
buildTree(arr,tree,start,end,2*treeNode);
buildTree(arr,tree,start,end,2*treeNode+1);
tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1];
}
void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value)
{
if(start==end)
{
arr[idx]=value;
tree[treeNode]=value;
return;
}
int mid=(start+end)/2;
if(idx>mid)
{
updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value);
}
else
{
updateTree(arr,tree,start,mid,2*treeNode,idx,value);
}
tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
}
// disjoint set implementation --start
static void makeSet(int n)
{
parent=new int[n];
rank=new int[n];
for(int i=0;i<n;i++)
{
parent[i]=i;
rank[i]=0;
}
}
static void union(int u,int v)
{
u=findpar(u);
v=findpar(v);
if(rank[u]<rank[v])parent[u]=v;
else if(rank[v]<rank[u])parent[v]=u;
else
{
parent[v]=u;
rank[u]++;
}
}
private static int findpar(int node)
{
if(node==parent[node])return node;
return parent[node]=findpar(parent[node]);
}
static int parent[];
static int rank[];
// *************end
static Long MOD=(long) (1e9+7);
static boolean coprime(int a, long l){
return (gcd(a, l) == 1);
}
static long[][] dp;
static long[]dpp;
static ArrayList<Integer>arr;
static boolean[] vis;
static ArrayList<ArrayList<Integer>>adj;
public static void main(String[] args)
{
FastReader s = new FastReader();
long tt = s.nextLong();
sieve();
// ArrayList<Long>aa=new ArrayList<>();
// aa.add((long) 3);
// aa.add((long) 11);
// aa.add((long) 101);
// aa.add((long) 1009);
// aa.add((long) 10007);
// aa.add((long) 100003);
// aa.add((long) 1000003);
// aa.add((long) 10000019);
// aa.add((long) 100030001);
while(tt-->0) {
int n=s.nextInt();
long[]a=new long[n];
PriorityQueue<Long>pq=new PriorityQueue<>();
for(int i=0;i<n;i++)
{
a[i]=s.nextLong();
pq.add(a[i]);
}
long ans=pq.poll();
long curr=ans;
while(!pq.isEmpty()) {
long temp=pq.poll();
long fg=temp-curr;
curr+=fg;
ans=Math.max(ans, fg);
}
System.out.println(ans);
}
}
static void palindromeSubStrs(String str) {
HashSet<String>set=new HashSet<>();
char[]a =str.toCharArray();
int n=str.length();
int[][]dp=new int[n][n];
for(int g=0;g<n;g++){
for(int i=0,j=g;j<n;j++,i++){
if(!set.contains(str.substring(i,i+1))&&g==0) {
dp[i][j]=1;
set.add(str.substring(i,i+1));
}
else {
if(!set.contains(str.substring(i,j+1))&&isPalindrome(str,i,j)) {
dp[i][j]=1;
set.add(str.substring(i,j+1));
}
}
}
}
int ans=0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
System.out.print(dp[i][j]+" ");
if(dp[i][j]==1)ans++;
}
System.out.println();
}
System.out.println(ans);
}
static boolean isPalindrome(String str,int i,int j)
{
while (i < j) {
if (str.charAt(i) != str.charAt(j))
return false;
i++;
j--;
}
return true;
}
static boolean sign(long num) {
return num>0;
}
static boolean isSquare(long x){
if(x==1)return true;
long y=(long) Math.sqrt(x);
return y*y==x;
}
private static void dfs(int i) {
vis[i]=true;
arr.add(i);
for(int x:adj.get(i))
{
if(vis[x]==false)dfs(x);
}
}
static long power1(long a,long b) {
if(b == 0){
return 1;
}
long ans = power(a,b/2);
ans *= ans;
if(b % 2!=0){
ans *= a;
}
return ans;
}
static void swap(StringBuilder sb,int l,int r)
{
char temp = sb.charAt(l);
sb.setCharAt(l,sb.charAt(r));
sb.setCharAt(r,temp);
}
// function to reverse the string between index l and r
static void reverse(StringBuilder sb,int l,int r)
{
while(l < r)
{
swap(sb,l,r);
l++;
r--;
}
}
// function to search a character lying between index l and r
// which is closest greater (just greater) than val
// and return it's index
static int binarySearch(StringBuilder sb,int l,int r,char val)
{
int index = -1;
while (l <= r)
{
int mid = (l+r)/2;
if (sb.charAt(mid) <= val)
{
r = mid - 1;
}
else
{
l = mid + 1;
if (index == -1 || sb.charAt(index) >= sb.charAt(mid))
index = mid;
}
}
return index;
}
// this function generates next permutation (if there exists any such permutation) from the given string
// and returns True
// Else returns false
static boolean nextPermutation(StringBuilder sb)
{
int len = sb.length();
int i = len-2;
while (i >= 0 && sb.charAt(i) >= sb.charAt(i+1))
i--;
if (i < 0)
return false;
else
{
int index = binarySearch(sb,i+1,len-1,sb.charAt(i));
swap(sb,i,index);
reverse(sb,i+1,len-1);
return true;
}
}
private static int lps(int m ,int n,String s1,String s2,int[][]mat)
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
if(s1.charAt(i-1)==s2.charAt(j-1))mat[i][j]=1+mat[i-1][j-1];
else mat[i][j]=Math.max(mat[i-1][j],mat[i][j-1]);
}
}
return mat[m][n];
}
static String lcs(String X, String Y, int m, int n)
{
int[][] L = new int[m+1][n+1];
// Following steps build L[m+1][n+1] in bottom up fashion. Note
// that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1]
for (int i=0; i<=m; i++)
{
for (int j=0; j<=n; j++)
{
if (i == 0 || j == 0)
L[i][j] = 0;
else if (X.charAt(i-1) == Y.charAt(j-1))
L[i][j] = L[i-1][j-1] + 1;
else
L[i][j] = Math.max(L[i-1][j], L[i][j-1]);
}
}
// Following code is used to print LCS
int index = L[m][n];
int temp = index;
// Create a character array to store the lcs string
char[] lcs = new char[index+1];
lcs[index] = '\u0000'; // Set the terminating character
// Start from the right-most-bottom-most corner and
// one by one store characters in lcs[]
int i = m;
int j = n;
while (i > 0 && j > 0)
{
// If current character in X[] and Y are same, then
// current character is part of LCS
if (X.charAt(i-1) == Y.charAt(j-1))
{
// Put current character in result
lcs[index-1] = X.charAt(i-1);
// reduce values of i, j and index
i--;
j--;
index--;
}
// If not same, then find the larger of two and
// go in the direction of larger value
else if (L[i-1][j] > L[i][j-1])
i--;
else
j--;
}
return String.valueOf(lcs);
// Print the lcs
// System.out.print("LCS of "+X+" and "+Y+" is ");
// for(int k=0;k<=temp;k++)
// System.out.print(lcs[k]);
}
static long lis(long[] aa2, int n)
{
long lis[] = new long[n];
int i, j;
long max = 0;
for (i = 0; i < n; i++)
lis[i] = 1;
for (i = 1; i < n; i++)
for (j = 0; j < i; j++)
if (aa2[i] >= aa2[j] && lis[i] <= lis[j] + 1)
lis[i] = lis[j] + 1;
for (i = 0; i < n; i++)
if (max < lis[i])
max = lis[i];
return max;
}
static boolean isPalindrome(String str)
{
int i = 0, j = str.length() - 1;
while (i < j) {
if (str.charAt(i) != str.charAt(j))
return false;
i++;
j--;
}
return true;
}
static boolean issafe(int i, int j, int r,int c, char ch)
{
if (i < 0 || j < 0 || i >= r || j >= c|| ch!= '1')return false;
else return true;
}
static long power(long a, long b)
{
a %=MOD;
long out = 1;
while (b > 0) {
if((b&1)!=0)out = out * a % MOD;
a = a * a % MOD;
b >>= 1;
a*=a;
}
return out;
}
static long[] sieve;
public static void sieve()
{
int nnn=(int) 1e6+1;
long nn=(int) 1e6;
sieve=new long[(int) nnn];
int[] freq=new int[(int) nnn];
sieve[0]=0;
sieve[1]=1;
for(int i=2;i<=nn;i++)
{
sieve[i]=1;
freq[i]=1;
}
for(int i=2;i*i<=nn;i++)
{
if(sieve[i]==1)
{
for(int j=i*i;j<=nn;j+=i)
{
if(sieve[j]==1)
{
sieve[j]=0;
}
}
}
}
}
}
class decrease implements Comparator<Long> {
// Used for sorting in ascending order of
// roll number
public int compare(long a, long b)
{
return (int) (b - a);
}
@Override
public int compare(Long o1, Long o2) {
// TODO Auto-generated method stub
return (int) (o2-o1);
}
}
class pair{
long x;
long y;
long c;
public pair(long x,long y) {
this.x=x;
this.y=y;
}
public pair(long x,long y,long c)
{
this.x=x;
this.y=y;
this.c=c;
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | a3cf1a80d90ff1fbe1c4a2fec5b37392 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Problem1607C {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int tc = scanner.nextInt();
while (tc-->0){
int size = scanner.nextInt();
Long [] array = new Long[size];
for (int i =0;i< array.length;i++){
array[i] = scanner.nextLong();
}
Arrays.sort(array);
Long min = array[0];
for (int i =0;i< array.length-1;i++){
min = Math.max(min,(array[i+1]-array[i]));
}
System.out.println(min);
}
}
}
| Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 770405cffd4f89c83b8414274140412a | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
// int x = 1;
// for (int i = 0; i <= 30; i++) {
// io.println(x);
// if (x % 2 == 0) {
// x -= i + 1;
// } else {
// x += i + 1;
// }
// }
// io.flush();
int tc = io.nextInt();
for (int i = 0; i < tc; i++) {
solve();
}
io.close();
}
private static void solve() throws Exception {
int n = io.nextInt();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = io.nextInt();
}
sort(arr);
long output = Long.MIN_VALUE;
long offset = 0;
for (int i = 0; i < n; i++) {
output = Math.max(arr[i] + offset, output);
offset = offset - (arr[i] + offset);
}
io.println(output);
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>(a.length);
for (long i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
//-----------PrintWriter for faster output---------------------------------
public static FastIO io = new FastIO();
//-----------MyScanner class for faster input----------
static class FastIO extends PrintWriter {
private InputStream stream;
private byte[] buf = new byte[1 << 16];
private int curChar, numChars;
// standard input
public FastIO() {
this(System.in, System.out);
}
public FastIO(InputStream i, OutputStream o) {
super(o);
stream = i;
}
// file input
public FastIO(String i, String o) throws IOException {
super(new FileWriter(o));
stream = new FileInputStream(i);
}
// throws InputMismatchException() if previously detected end of file
private int nextByte() {
if (numChars == -1) throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars == -1) return -1; // end of file
}
return buf[curChar++];
}
// to read in entire lines, replace c <= ' '
// with a function that checks whether c is a line break
public String next() {
int c;
do {
c = nextByte();
} while (c <= ' ');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > ' ');
return res.toString();
}
public String nextLine() {
int c;
do {
c = nextByte();
} while (c < '\n');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > '\n');
return res.toString();
}
public int nextInt() {
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public long nextLong() {
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
int[] nextInts(int n) {
int[] data = new int[n];
for (int i = 0; i < n; i++) {
data[i] = io.nextInt();
}
return data;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
//--------------------------------------------------------
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output | |
PASSED | 16c17b149bd9366021c0c74104d26c46 | train_108.jsonl | 1635863700 | Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. | 256 megabytes | import java.util.*;
public class Solution{
static Scanner sc = new Scanner(System.in);
public static void main(String args[]){
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
Long[] arr = new Long[n];
for(int i = 0; i < n; i++)
arr[i] = sc.nextLong();
long sum = 0;
long max = -(long)9e18;
Arrays.sort(arr);
for(int i = 0; i < n; i++){
arr[i] -= sum;
max = Math.max(max, arr[i]);
sum += arr[i];
}
System.out.println(max);
}
}
} | Java | ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2"] | 1 second | ["10\n0\n2\n5\n2\n2\n2\n-2"] | NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | Java 8 | standard input | [
"brute force",
"sortings"
] | 4bd7ef5f6b3696bb44e22aea87981d9a | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,000 | Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.