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
sequencelengths
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
409c17ec6d02bc99bd1d0b1a52e92806
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) > \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) < \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.stream.Collectors; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-->0){ int n = Integer.parseInt(br.readLine()); List<Long> val = Arrays.stream(br.readLine().split("\\s+")).map(Long::valueOf).collect(Collectors.toList());; Collections.sort(val); Integer firstidx = 1; Long first = val.get(0)+val.get(1); Long end = val.get(n-1); Integer endIdx = n-1; String ans = "NO"; while (firstidx+1<=endIdx){ if(end > first){ ans = "YES"; break; } endIdx--; end+=val.get(endIdx); firstidx++; first+=val.get(firstidx); } sb.append(ans); sb.append("\n"); } System.out.println(sb.toString().trim()); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
f024de6437f6d10f871b62171d925cd2
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
// Working program with FastReader import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.lang.*; public class B_Quality_vs_Quantity { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); ArrayList<Integer> arr=new ArrayList<>(); // int arr[]=new int[n]; for(int i=0;i<n;i++){ arr.add(sc.nextInt()); } if(n<3) { System.out.println("NO"); continue; } Collections.sort(arr); boolean flag=false; long sR=0,sB=0; sB=arr.get(0); int i=1,j=n-1; while(i<j){ sR+=arr.get(j); sB+=arr.get(i); if(sR>sB){ flag=true; break; } ++i; --j; } if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
e44dc6744dc93999f3470c367bd31271
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class faltu { static int mod= 998244353 ; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer:while(t-->0) { int n = fs.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); for(int i = 0;i < n;i++){ arr.add(fs.nextInt()); } Collections.sort(arr); boolean ans = false; long sum_blue = arr.get(0); long sum_red = 0; for(int i = 1;i <= (n/2);i++){ sum_blue += arr.get(i); sum_red += arr.get(n-i); if(sum_red > sum_blue){ ans = true; break; } } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } out.close(); } static long pow(long a,long b) { if(b<0) return 1; long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); int temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } // Use this to input code since it is faster than a Scanner 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[] readArrayL(int n) { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
234c2fc0b2221e465ff347f5365f1229
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class ProblemA { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[]) throws IOException { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512); FastReader in = new FastReader(); int t = in.nextInt(); while(t-- != 0) { int n = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(in.nextInt()); } long s1 = 0, s2 = 0; int l = 2, r = n-2; Collections.sort(list); s1 += list.get(0) + list.get(1); s2 += list.get(n-1); boolean bool = false; if(s1 < s2) bool = true; while(l <= r){ // System.out.println(l + " " + r + " " + s1 + " " + s2); if(s2 > s1){ bool = true; break; } s1 += list.get(l++); s2 += list.get(r--); } if(s2 > s1) { bool = true; } if(bool) out.write("YES"); else out.write("NO"); // if(bool) System.out.println("YES"); // else System.out.println("NO"); out.newLine(); } out.flush(); } } /* 6 l = 2 r = 3 5 6 7 8 9 10 lr 0 1 2 3 4 5 5 3 2 3 4 5 */
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
d65713e64870417086ee23bf3c41d7bd
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { final static int mod = 1000000007; public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int t = sc.nextInt(); outer: while (t-- > 0) { int n = sc.nextInt(); long[] a = new long[n]; long sum = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); sum += a[i]; } if (n <= 2) { System.out.println("NO"); continue outer; } sort(a); boolean found = false; long[] pre = new long[n]; long[] suf = new long[n]; pre[0] = a[0]; suf[n - 1] = a[n - 1]; for (int i = 1; i < n; i++) { pre[i] = pre[i - 1] + a[i]; } if (suf[n - 1] > pre[1]) { System.out.println("YES"); continue outer; } for (int i = n - 2; i > 0; i--) { suf[i] = suf[i + 1] + a[i]; if (suf[i] > pre[n - i]) { found = true; break; } } System.out.println(found ? "YES" : "NO"); } } 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); } public static boolean isSorted(int[] nums, int n) { for (int i = 1; i < n; i++) { if (nums[i] < nums[i - 1]) return false; } return true; } public static boolean isPalindrome(String s) { int i = 0, j = s.length() - 1; while (i <= j) { if (s.charAt(i) != s.charAt(j)) return false; i++; j--; } return true; } public static void sortByColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator if (entry1[col] > entry2[col]) return 1; else return -1; } }); } public static void backtrack(String[] letters, int index, String digits, StringBuilder build, List<String> result) { if (build.length() >= digits.length()) { result.add(build.toString()); return; } char[] key = letters[digits.charAt(index) - '2'].toCharArray(); for (int j = 0; j < key.length; j++) { build.append(key[j]); backtrack(letters, index + 1, digits, build, result); build.deleteCharAt(build.length() - 1); } } public static String get(String s, int k) { int n = s.length(); int rep = k % n == 0 ? k / n : k / n + 1; s = s.repeat(rep); return s.substring(0, k); } public static int diglen(Long y) { int a = 0; while (y != 0L) { y /= 10; a++; } return a; } static class FastReader { BufferedReader br; StringTokenizer st; // StringTokenizer() is used to read long strings 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 class Pair implements Comparable<Pair> { public final int index; public final int value; public Pair(int index, int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { // multiplied to -1 as the author need descending sort order return -1 * Integer.valueOf(this.value).compareTo(other.value); } } static String reverseString(String str) { StringBuilder input = new StringBuilder(); return input.append(str).reverse().toString(); } static long factorial(int n, int b) { if (n == b) return 1; return n * factorial(n - 1, b); } static int lcm(int ch, int b) { return ch * b / gcd(ch, b); } static int gcd(int ch, int b) { return b == 0 ? ch : gcd(b, ch % b); } static double ceil(double n, double k) { return Math.ceil(n / k); } static int sqrt(double n) { return (int) Math.sqrt(n); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
824a8fe89369bb1a6dace4fca1f2b637
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class B_Quality_vs_Quantity { static final PrintWriter out =new PrintWriter(System.out); static final FastReader sc = new FastReader(); static long m = 998244353; public static void main (String[] args) throws java.lang.Exception { // ArrayList<Long> arr = sieveOfEratosthenes(10000); long t = sc.nextLong(); 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 sumB =0; long sumR=0; long cB=0; long cR=0; boolean ch=false; sumB=arr.get(0); sumR=0; int i=1; int j= n-1; while(i<j) { sumB += arr.get(i); sumR += arr.get(j); if((sumR>sumB)) { out.println("YES"); ch =true; break; } i++; j--; } if(ch==false) out.println("NO"); } out.flush(); } static int[] reverseArray(int arr[]) { int arr1[] = new int[arr.length]; int j=0; for(int i=arr.length-1 ;i>=0 ; i--) { arr1[j] = arr[i]; j++; } return arr1; } static int maxSubArraySum(ArrayList<Integer> a) { int size = a.size(); int max_so_far = Integer.MIN_VALUE, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a.get(i); if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } static void printArray(int[] arr1) { for(int i=0 ; i<arr1.length ; i++) { out.print(arr1[i]+" "); } out.println(); } public static class Pair { long a; long b; long c ; Pair(long a , long b , long c) { this.a=a; this.b=b; this.c=c; } } static class Sort implements Comparator<Pair> { // Method // Sorting in ascending order of roll number public int compare(Pair a, Pair b) { return (int) (a.a - b.a); } } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop 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 ArrayList<Long> sieveOfEratosthenes(long n) { boolean[] prime = new boolean[(int) (n + 1)]; for (int i = 0; i <= n; i++) prime[i] = true; prime[0]=false; if(1<=n) prime[1]=false; ArrayList<Long> arr = new ArrayList<>(); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { if(p!=2 && p!=3 ) arr.add((long) p); for (int i = p * p; i <= n; i += p) prime[i] = false; } } return arr; } static int count(String s) { int count=0; for(int i=0 ; i<s.length() ; i++) { if(s.charAt(i)=='1' ) count++; } return count; } static long gcd(long a , long b) { if(b==0) return a; return gcd(b,a%b); } static long lcm(long a , long b) { return (a*b)/gcd(a,b); } static long fastPower(long a , long b , long n ) { long res=1; while(b>0) { if((b&1)!=0) { res = (res%n * a%n)%n; } a = (a%n * a%n)%n; b=b>>1; } return res; } static long modexp(long x, long n) { if (n == 0) { return 1; } else if (n % 2 == 0) { return modexp((x * x) % m, n / 2); } else { return (x * modexp((x * x) % m, (n - 1) / 2) % m); } } static long getFractionModulo(long a, long b) { long c = gcd(a, b); a = a / c; b = b / c; long d = modexp(b, m - 2); long ans = ((a % m) * (d % m)) % m; return ans; } 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 long modMult(long a,long b) { return a*b%m; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
4d5d279485b10e8f67da7f87fba7bf72
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Two { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { long n=sc.nextLong(); ArrayList<Long> a=new ArrayList<>(); for(long j=(long) 0;j<n;j=j+(long) 1) { long input=sc.nextLong(); a.add(input); } Collections.sort(a); long sum1=(long) 0; long sum2=(long) 0; long x=(n/(long) 2)+1; long y=n-x; for(long j=(long) 0;j<=y;j=j+(long) 1) { sum1=sum1+a.get((int) j); } for(long j=(long) x;j<n;j=j+(long) 1) { sum2=sum2+a.get((int) j); } if(sum2>sum1) { System.out.println("YES"); } else { System.out.println("NO"); } a.clear(); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
76d8fbfa2071502a7cc61b79fe0f3bcc
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
/* JAIKARA SHERAWAALI DA BOLO SACHE DARBAR KI JAI HAR HAR MAHADEV JAI BHOLENAATH Rohit Kumar "Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up." __Hope is a big word, never lose it__ */ import java.io.*; 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.hasMoreTokens()){ try{ st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken();} long nextLong(){ return Long.parseLong(next());} int nextInt(){ return Integer.parseInt(next());} } static int mod=(int)1e9+7; public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } FastReader sc = new FastReader(); int tt=sc.nextInt(); while(tt-->0) { int n=sc.nextInt(); List<Long> arr=new ArrayList<>(); for(int i=0;i<n;i++) { arr.add(sc.nextLong()); } Collections.sort(arr); boolean flag=false; long pref[]=new long[n]; pref[0]=arr.get(0); for(int i=1;i<n;i++) { pref[i]=arr.get(i)+pref[i-1]; } long sum=0; int elecnt=0; for(int i=n-1;i>=0;i--) { sum+=arr.get(i); elecnt++; if(2*elecnt>=arr.size()) { break; } if(sum>pref[elecnt]) { flag=true; } } if(flag) { print("YES"); } else{ print("NO"); } } } static <t>void print(t o){ System.out.println(o); } static boolean ispalindrome(String str) { int l=0,r=str.length()-1; while(l<r) { if(str.charAt(l)!=str.charAt(r)) { return false; } l++; r--; } return true; } static void reverse(int[] arr, int from, int till) { for (int i = from, j = till; i < j; i++, j--) { swap(arr, i, j); } } static void swap(int[] arr, int a, int b) { int tmp = arr[a]; arr[a] = arr[b]; arr[b] = tmp; } 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] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } for(int i = 2; i <= n; i++) { if(prime[i] == true) System.out.print(i + " "); } } static long gcd1(int a,int b) { if(b==0) return a; return gcd(b,a%b); } static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } static boolean isprime(int n) { if(n<=1) return false; if(n<=3) return true; if(n%2==0||n%3==0) return false; for(int i=5;i*i<=n;i=i+6) { if(n%i==0||n%(i+2)==0) return false; } return true; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
f923acb6bfd5469f6fb928bc7a0747a5
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Anubhav */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BQualityVsQuantity solver = new BQualityVsQuantity(); solver.solve(1, in, out); out.close(); } static class BQualityVsQuantity { public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); long ar[] = in.nextLongArray(n); for (int i = 0; i < n; i++) { int j = (int) (((double) i) * (Math.random())); long v = ar[j]; ar[j] = ar[i]; ar[i] = v; } Arrays.sort(ar); long a[] = new long[n]; long b[] = new long[n]; long s = 0; for (int i = 0; i < n; i++) { s += ar[i]; a[i] = s; } s = 0; for (int i = n - 1; i >= 0; i--) { s += ar[i]; b[i] = s; } int c = 0; int lo = 0; int hi = n - 1; int f = 0; while (lo <= hi) { if (lo == hi) f++; if (f > 1) break; int i = (lo + hi) / 2; long s1 = b[i]; int t1 = (n) - i; int end = t1; if (end >= i) { lo = i + 1; continue; } long s2 = a[t1]; if (s1 <= s2) { hi = i - 1; } else { c++; break; } } if (c > 0) out.println("Yes"); else out.println("No"); } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { 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 isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } 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 println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
18234c26600d8f0812fa18d38f03b507
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int o=0;o<t;o++){ long n=sc.nextLong(); long a[]=new long[(int)n]; for(int i=0;i<n;i++){ a[i]=sc.nextLong(); } Long[] b=new Long[(int)n]; for(int i=0;i<n;i++){ b[i]=new Long(a[i]); } int f=0; Arrays.sort(b); Long s1=b[a.length-1]; Long s=b[0]; int j=b.length-2; for(int i=1;i<=j;i++){ s=s+b[i]; if(s<s1){ f=1; break; }else{ s1=s1+b[j]; j--; } } if(f==1){ System.out.println("YES"); }else{ System.out.println("NO"); } }}}
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
36810b57583c542d4aade70277fde16c
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import static java.lang.System.out; public class Round_780_Div_3 { static Scanner str = new Scanner(System.in); static ArrayList<Integer> list; public static void main(String[] args) { int t = str.nextInt(); while (t-- > 0) { solve(); } } static void solve() { list = new ArrayList<>(); int n = str.nextInt(); long ans1 = 0; long ans2 = 0; for (int i = 0; i < n; i++) { list.add(str.nextInt()); } Collections.sort(list); ans1 += list.get(0) + list.get(1); ans2 += list.get(n - 1); if (ans1 < ans2) { out.println("YES"); return; } int x = n - 2; for (int i = 2; i <= x; i++, x--) { ans1 += list.get(i); ans2 += list.get(x); if (ans1 < ans2) { out.println("YES"); return; } } out.println("NO"); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
393e88e81632fa2c215b335d413761c8
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static Object[] num; public static void main(String[] args) throws IOException { int qwe = in.nextInt(); while (qwe-->0) { solve(); } } static void solve(){ int n = in.nextInt(); long[] num = new long[n]; for (int i = 0; i < n; i++) { num[i]=in.nextInt(); } gbSort(num,0,n-1); long red = 0; long blue = 0; int i,j; blue = num[0]; for (i=1,j=n-1;i<j;i++,j--) { red += num[j]; blue += num[i]; if (blue<red){ System.out.println("YES"); return; } } System.out.println("NO"); } public static long cnm(int a, int b) { long sum = 1; int i = a, j = 1; while (j <= b) { sum = sum * i / j; i--; j++; } return sum; } public static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } public static void gbSort(long[] a, int l, int r) { if (l < r) { int m = (l + r) >> 1; gbSort(a, l, m); gbSort(a, m + 1, r); long[] t = new long[r - l + 1]; int idx = 0, i = l, j = m + 1; while (i <= m && j <= r) if (a[i] <= a[j]) t[idx++] = a[i++]; else t[idx++] = a[j++]; while (i <= m) t[idx++] = a[i++]; while (j <= r) t[idx++] = a[j++]; for (int z = 0; z < t.length; z++) a[l + z] = t[z]; } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in), 16384); eat(""); } public void eat(String s) { st = new StringTokenizer(s); } public String nextLine() { try { return br.readLine(); } catch (IOException e) { return null; } } public boolean hasNext() { while (!st.hasMoreTokens()) { String s = nextLine(); if (s == null) return false; eat(s); } return true; } public String next() { hasNext(); return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static FastScanner in = new FastScanner(System.in); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
1404a6f7b6dc7f74fdf65536c888ac6c
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
//package com.company; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class CF { public static void main(String[] args)throws Exception { Reader1.init(System.in); int t = Reader1.nextInt(); while (t-- > 0) { int n = Reader1.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); for (int i=0;i<n;i++) { arr.add(Reader1.nextInt()); } Collections.sort(arr); long blue = arr.get(0) + arr.get(1); long red = arr.get(arr.size()-1); int i = 2; int j = arr.size()-2; int c = 0; while (i<j) { if (blue<red) { c = 1; break; } blue = blue + arr.get(i); red = red + arr.get(j); i++; j--; } if (blue<red) { c = 1; } if (c==1) { System.out.println("YES"); } else { System.out.println("NO"); } } } } class Reader1 { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static long nextLong() throws IOException{ return Long.parseLong(next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
bbfbfcd22128edc609adc2bc87fdf75b
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Rough { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t=s.nextInt(); while(t-->0) { int a=s.nextInt(); Long[] ar=new Long[a]; for(int i=0;i<a;++i) { ar[i]=s.nextLong(); } Arrays.sort(ar); boolean doer=false; long sumf=ar[0]+ar[1]; long sumb=ar[a-1]; if(sumf<sumb) { pw.println("YES"); continue; } int k=2; int l=a-2; while(k<l){ sumf+=ar[k]; sumb+=ar[l]; if(sumf<sumb) { doer=true; break; } k++; l--; } if(doer)pw.println("YES"); else pw.println("NO"); } pw.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
66ee3340ad99623be3b3d6b4dde3399e
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class qualityquantity{ public static int t, n; public static Integer[] arr; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); t = Integer.parseInt(br.readLine()); for(int test = 0; test < t; test++) { n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); arr = new Integer[n]; String ans = "NO"; for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(st.nextToken()); Arrays.sort(arr); int right = n - 1; int left = 1; long rs = arr[n-1]; long ls = arr[0] + arr[1]; while(right > left) { if(rs > ls) { ans = "YES"; break; } else { rs += arr[--right]; ls += arr[++left]; } } pw.println(ans); } pw.flush(); pw.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
f0864b1cb31734b49c0c0f2ad31f72f6
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class qualityquantity{ public static int t, n; public static Integer[] arr; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); t = Integer.parseInt(br.readLine()); for(int test = 0; test < t; test++) { n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); arr = new Integer[n]; String ans = "NO"; for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(st.nextToken()); Arrays.sort(arr); int right = n - 1; int left = 1; long rs = arr[n-1]; long ls = arr[0] + arr[1]; while(right > left) { if(rs > ls) { ans = "YES"; break; } else { rs += arr[right - 1]; ls += arr[left + 1]; right--; left++; } } pw.println(ans); } pw.flush(); pw.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
eb2212a75d3727e0f6bc3769c452a3ca
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.lang.*; public class Solution{ static long mod=(long)1e9+7; static long mod1=998244353l; static int[] cost=new int[(int)1005]; static StringBuffer ans1=new StringBuffer(""); static FastScanner sc = new FastScanner(); public static void solve(){ int n=sc.nextInt(); int[] a=sc.readArray(n); if (solve(a)) { System.out.println("YES"); }else{ System.out.println("NO"); } } static boolean solve(int[] a) { int[] sorted = Arrays.stream(a).boxed().sorted().mapToInt(x -> x).toArray(); long lowerSum = sorted[0]; long upperSum = 0; for (int i = 1, j = sorted.length - 1; i < j; ++i, --j) { lowerSum += sorted[i]; upperSum += sorted[j]; } return lowerSum < upperSum; } public static void main(String[] args) { int t = sc.nextInt(); // int t=1; for (int i=2;i<cost.length;i++) cost[i]=cost[i-1]+1; for (int i=2;i<cost.length;i++) { // cost[i]=i-1; for (int j=1;j<=i/2+1;j++) { if((i+i/j)<=1004) cost[i+i/j]=min(cost[i+i/j],cost[i]+1); } // if (i%2==0) { // cost[i]=cost[i/2]+1; // }else{ // cost[i]=cost[i-1]; // } } outer: for (int tt = 0; tt < t; tt++) { solve(); } System.out.println(ans1); } static boolean isSubSequence(String str1, String str2, int m, int n) { int j = 0; for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == str2.charAt(i)) j++; return (j == m); } static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static int[] LPS(String s){ int[] lps=new int[s.length()]; int i=0,j=1; while (j<s.length()) { if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; j++; continue; }else{ if (i==0) { j++; continue; } i=lps[i-1]; while(s.charAt(i)!=s.charAt(j) && i!=0) { i=lps[i-1]; } if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; } j++; } } return lps; } static long getPairsCount(int n, double sum,int[] arr) { HashMap<Double, Integer> hm = new HashMap<>(); for (int i = 0; i < n; i++) { if (!hm.containsKey((double)arr[i])) hm.put((double)arr[i], 0); hm.put((double)arr[i], hm.get((double)arr[i]) + 1); } long twice_count = 0; for (int i = 0; i < n; i++) { if (hm.get(sum - arr[i]) != null) twice_count += hm.get(sum - arr[i]); if (sum - (double)arr[i] == (double)arr[i]) twice_count--; } return twice_count / 2l; } static boolean[] sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } prime[1]=false; return prime; } static long power(long x, long y, long p) { long res = 1l; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y>>=1; x = (x * x) % p; } return res; } public static int log2(int N) { int result = (int)(Math.log(N) / Math.log(2)); return result; } //////////////////////////////////////////////////////////////////////////////////// ////////////////////DO NOT READ AFTER THIS LINE ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// static long modFact(int n, int p) { if (n >= p) return 0; long result = 1l; for (int i = 3; i <= n; i++) result = (result * i) % p; return result; } static boolean isPalindrom(char[] arr, int i, int j) { boolean ok = true; while (i <= j) { if (arr[i] != arr[j]) { ok = false; break; } i++; j--; } return ok; } static int max(int a, int b) { return Math.max(a, b); } static int min(int a, int b) { return Math.min(a, b); } static long max(long a, long b) { return Math.max(a, b); } static long min(long a, long b) { return Math.min(a, b); } static int abs(int a) { return Math.abs(a); } static long abs(long a) { return Math.abs(a); } static void swap(long arr[], int i, int j) { long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int arr[], int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static int maxArr(int arr[]) { int maxi = Integer.MIN_VALUE; for (int x : arr) maxi = max(maxi, x); return maxi; } static int minArr(int arr[]) { int mini = Integer.MAX_VALUE; for (int x : arr) mini = min(mini, x); return mini; } static long maxArr(long arr[]) { long maxi = Long.MIN_VALUE; for (long x : arr) maxi = max(maxi, x); return maxi; } static long minArr(long arr[]) { long mini = Long.MAX_VALUE; for (long x : arr) mini = min(mini, x); return mini; } static int lcm(int a,int b){ return (int)(((long)a*b)/(long)gcd(a,b)); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } public static int binarySearch(int a[], int target) { int left = 0; int right = a.length - 1; int mid = (left + right) / 2; int i = 0; while (left <= right) { if (a[mid] <= target) { i = mid + 1; left = mid + 1; } else { right = mid - 1; } mid = (left + right) / 2; } return i-1; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] read2dArray(int n, int m) { int arr[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = nextInt(); } } return arr; } ArrayList<Integer> readArrayList(int n) { ArrayList<Integer> arr = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { int a = nextInt(); arr.add(a); } return arr; } long nextLong() { return Long.parseLong(next()); } } static class Pair { int fr,sc; Pair(int fr, int sc) { this.fr = fr; this.sc = sc; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
7231e2bbf1601c5c0da7018d4003ffa7
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
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 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 int p,q; public static void main(String[] args) { FastReader sc = new FastReader(); int tt=sc.nextInt(); while(tt--!=0) { int n=sc.nextInt(); ArrayList<Long> a=new ArrayList<>(); long sum=0; for(int i=0;i<n;i++) { long p=sc.nextLong(); a.add(p); sum+=p; } Collections.sort(a); int s=1; int e=n-1; long blue=a.get(0)+a.get(1); long red=a.get(n-1); boolean b=false; while(s<e) { if(blue<red) { b=true; break; } else { s++; blue+=a.get(s); e--; red+=a.get(e); } } if(b) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
27d4b0fd9c3ed6d0d4ddf86b78af82ba
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class ProblemA{ static long mod = 1000000007L; static MyScanner sc = new MyScanner(); //code here static void solve(){ int n = sc.nextInt(); ArrayList<Long> a = new ArrayList<>(); for(int i=0;i<n;i++) { a.add(sc.nextLong()); } Collections.sort(a); long red = 0,blue = a.get(0); boolean flag = false; for(int i=1;i<=n/2;i++) { red += a.get(n-i); blue += a.get(i); if(blue<red) { flag = true; break; } } if(flag) { out.println("YES"); }else out.println("NO"); } // code ends static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static boolean isPali(String str){ int i = 0; int j = str.length()-1; while(i<j){ if(str.charAt(i)!=str.charAt(j)){ return false; } i++; j--; } return true; } static void priArr(int[] a) { for(int i=0;i<a.length;i++) { out.print(a[i] + " "); } out.println(); } static long gcd(long a,long b){ if(b==0) return a; return gcd(b,a%b); } static String reverse(String str){ char arr[] = str.toCharArray(); int i = 0; int j = arr.length-1; while(i<j){ char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } String st = new String(arr); return st; } static boolean isprime(int n){ if(n==1) return false; if(n==3 || n==2) return true; if(n%2==0 || n%3==0) return false; for(int i = 5;i*i<=n;i+= 6){ if(n%i== 0 || n%(i+2)==0){ return false; } } return true; } static class Pair implements Comparable<Pair>{ int val; int ind; int ans; Pair(int v,int f){ val = v; ind = f; } public int compareTo(Pair p){ return p.val - this.val; } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ // solve(); solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i=0; i<arr.length; i++){ list.add(arr[i]); } Collections.sort(list); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
4b906835c92082ef207722c2a7021624
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
//package com.company; import java.io.*; import java.util.*; public class Main{ static boolean[] primecheck; static ArrayList<Integer>[] adj; static int[] vis; static int[] parent; static int[] rank; static int mod = (int)1e9 + 7; public static void main(String[] args) { OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); PROBLEM solver = new PROBLEM(); int t = 1; t = in.ni(); pre(); for (int i = 0; i < t; i++) { //out.print("Case #" + (i+1) + ": "); solver.solve(in, out); } out.close(); } static TreeSet<Long> hs = new TreeSet<>(); static void pre(){ long c = 1; long cur = 1; while(c <= (long)1e12){ hs.add(c); cur++; c*=cur; } } static class PROBLEM { public void solve(FastReader in, PrintWriter out) { int n = in.ni(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.ni(); } a = mergeSort(a); int mid = n/2; long ls = 0, rs = 0; for (int i = 0; i <= mid; i++) { ls += a[i]; } for (int i = n-1; i > mid; i--) { rs += a[i]; } if((n&1) == 0) ls -= a[mid]; output(rs>ls, out); // long n = in.nl(); // // long p = (long)(Math.log(n)/Math.log(2D)); // long a = (long)Math.pow(2, p); // long b = 0; // for(long i:hs){ // if(i < n) b = i; // else break; // } // // int k = 0, f = 0; // long y = n; // // while(n > 0){ // if(n-a < n-b || f == 1){ // n-=a; // k++; // p = (long)(Math.log(n)/Math.log(2D)); // a = (long)Math.pow(2, p); // if(f == 0) { // for (long i : hs) { // if (i < n) b = i; // else break; // } // } // if(b < 6) f = 1; // }else{ // n-=b; // if(b == 6) f = 1; // k++; // if(f == 0) { // for (long i : hs) { // if (i < n) b = i; // else break; // } // } // p = (long)(Math.log(n)/Math.log(2D)); // a = (long)Math.pow(2, p); // } // //out.println("n = " + n + " p = " + p + " a = " + a + " b = " + b); // } // if(n == 0) out.println(k); // else out.println(-1); } } static int find(int u){ if(u == parent[u]) return u; return parent[u] = find(parent[u]); } static void union(int u, int v){ int a = find(u), b = find(v); if(a == b) return; if(rank[a] > rank[b]){ parent[b] = a; rank[a] += rank[b]; }else{ parent[a] = b; rank[b] += rank[a]; } } static void dsu(){ for (int i = 1; i < 101; i++) { parent[i] = i; rank[i] = 1; } } static boolean isPalindrome(char[] s){ boolean b = true; for (int i = 0; i < s.length / 2; i++) { if(s[i] != s[s.length-1-i]){ b = false; break; } } return b; } static void output(boolean b, PrintWriter out){ if(b) System.out.println("YES"); else System.out.println("NO"); } static void pa(int[] a, PrintWriter out){ for (int j : a) { out.print(j + " "); } out.println(); } static void pa(long[] a, PrintWriter out){ for (long j : a) { out.print(j + " "); } out.println(); } public static void sortbyColumn(int arr[][], int col) { // Using built-in sort function Arrays.sort Arrays.sort(arr, new Comparator<int[]>() { @Override // Compare values according to columns public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator if (entry1[col] > entry2[col]) return 1; else return -1; } }); // End of function call sort(). } static boolean isPoT(long n){ return ((n&(n-1)) == 0); } static void dfs(int i){ vis[i] = 1; for(int j : adj[i]) { if (vis[j] == 0) { dfs(j); } } } static long sigmaK(long k){ return (k*(k+1))/2; } static void swap(int[] a, int l, int r) { int temp = a[l]; a[l] = a[r]; a[r] = temp; } static int binarySearch(int[] a, int l, int r, int x){ if(r>=l){ int mid = l + (r-l)/2; if(a[mid] == x) return mid; if(a[mid] > x) return binarySearch(a, l, mid-1, x); else return binarySearch(a,mid+1, r, x); } return -1; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b){ return (a / gcd(a, b)) * b; } static int ceil(int a, int b){ return (a+b-1)/b; } static long ceil(long a, long b){ return (a+b-1)/b; } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static long fast_pow(long a, long b) { //Jeel bhai OP if(b == 0) return 1L; long val = fast_pow(a, b / 2); if(b % 2 == 0) return val * val % mod; else return val * val % mod * a % mod; } static int exponentMod(int A, int B, int C) { // Base cases if (A == 0) return 0; if (B == 0) return 1; // If B is even long y; if (B % 2 == 0) { y = exponentMod(A, B / 2, C); y = (y * y) % C; } // If B is odd else { y = A % C; y = (y * exponentMod(A, B - 1, C) % C) % C; } return (int) ((y + C) % C); } // static class Pair implements Comparable<Pair>{ // // int x; // int y; // // Pair(int x, int y){ // this.x = x; // this.y = y; // } // // public int compareTo(Pair o){ // // int ans = Integer.compare(x, o.x); // if(o.x == x) ans = Integer.compare(y, o.y); // // return ans; // //// int ans = Integer.compare(y, o.y); //// if(o.y == y) ans = Integer.compare(x, o.x); //// //// return ans; // } // } static class Tuple implements Comparable<Tuple>{ int x, y, id; Tuple(int x, int y, int id){ this.x = x; this.y = y; this.id = id; } public int compareTo(Tuple o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int hashCode() { return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<U, V> p = (Pair<U, V>) o; return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); } public int compareTo(Pair<U, V> b) { int cmpU = x.compareTo(b.x); return cmpU != 0 ? cmpU : y.compareTo(b.y); } public int compareToY(Pair<U, V> b) { int cmpU = y.compareTo(b.y); return cmpU != 0 ? cmpU : x.compareTo(b.x); } public String toString() { return String.format("(%s, %s)", x.toString(), y.toString()); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } char nc() { return next().charAt(0); } boolean nb() { return !(ni() == 0); } // boolean nextBoolean(){return Boolean.parseBoolean(next());} String nline() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] ra(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = ni(); return array; } } private static int[] mergeSort(int[] array) { //array.length replaced with ctr int ctr = array.length; if (ctr <= 1) { return array; } int midpoint = ctr / 2; int[] left = new int[midpoint]; int[] right; if (ctr % 2 == 0) { right = new int[midpoint]; } else { right = new int[midpoint + 1]; } for (int i = 0; i < left.length; i++) { left[i] = array[i]; } for (int i = 0; i < right.length; i++) { right[i] = array[i + midpoint]; } left = mergeSort(left); right = mergeSort(right); int[] result = merge(left, right); return result; } private static int[] merge(int[] left, int[] right) { int[] result = new int[left.length + right.length]; int leftPointer = 0, rightPointer = 0, resultPointer = 0; while (leftPointer < left.length || rightPointer < right.length) { if (leftPointer < left.length && rightPointer < right.length) { if (left[leftPointer] < right[rightPointer]) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } else if (leftPointer < left.length) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } return result; } public static void Sieve(int n) { Arrays.fill(primecheck, true); primecheck[0] = false; primecheck[1] = false; for (int i = 2; i * i < n + 1; i++) { if (primecheck[i]) { for (int j = i * 2; j < n + 1; j += i) { primecheck[j] = false; } } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
a24caef2254f03fe94b9a79ddc311e1d
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.BigDecimal; import java.math.*; // public class Main{ private static int[] input() { int n=in.nextInt(); int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } private static int inte() { return in.nextInt(); } private static long lon() { return in.nextLong(); } public static void main(String[] args) { TaskA solver = new TaskA(); int t = in.nextInt(); for (int i = 1; i <= t ; i++) { solver.solve(t, in, out); } // solver.solve(1, in, out); out.flush(); out.close(); } static ArrayList<Integer>[]graph;static int[]arr; static long[][] dp; static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int[]arr=input(); int n= arr.length; sort(arr);long total1=0;long total2=0; long sum1=arr[0]+arr[1];long sum2=arr[n-1]; if(sum2>sum1) {println("YES");return;} int i=2;int j=n-2; while(i<j) { sum2+=arr[j];sum1+=arr[i]; if(sum2>sum1) { println("YES");return; } i++;j--; } println("NO"); } } public static boolean valid(int tim) { String ti=String.valueOf(tim); char[]time=ti.toCharArray(); for(int i=0;i<time.length;i++) { if(time[i]!='1'&&time[i]!='0'&&time[i]!='2'&&time[i]!='5'&&time[i]!='8') { return false; } } return true; } private static int opp(int x) { if(x==1||x==8||x==0) {return x;} else if(x==2) {return 5;} {return 2;} } public static int getFirstSetBitPos(int n) { return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1; } public static long rec(int i,int j,int[]arr) { if(arr.length==1) {return 0;} if(dp[i][j]!=0) {return dp[i][j];} else if(j-i==1) {dp[i][j]=arr[j]-arr[i];return dp[i][j];} else { dp[i][j]=Math.min(rec(i+1,j,arr),rec(i,j-1,arr))+arr[j]-arr[i]; return dp[i][j]; } } private static boolean isPalindrome(String s) { StringBuilder sb=new StringBuilder(s); if(sb.reverse().toString().equals(s)) return true; return false; } private static void dfs(int root,Pair[]p,int parent,int[][]dp) { int ans1=0;int ans2=0; for(int i:graph[root]) { if(i!=parent) { dfs(i,p,root,dp); } } for(int i:graph[root]) { if(i!=parent) { int val1=Math.abs(p[root].first-p[i].first)+dp[i][0]; int val2=Math.abs(p[root].first-p[i].second)+dp[i][1]; ans1+=Math.max(val1, val2); } } for(int i:graph[root]) { if(i!=parent) { int val1=Math.abs(p[root].second-p[i].first)+dp[i][0]; int val2=Math.abs(p[root].second-p[i].second)+dp[i][1]; ans2+=Math.max(val1, val2); } } dp[root][0]=ans1;dp[root][1]=ans2; } private static void printArr(int[] arr) { for (int i = 0; i < arr.length; i++) { print(arr[i] + " "); } print("\n"); } private static String rev(String s) { String st=""; for(int i=s.length()-1;i>=0;i--) { st+=s.charAt(i); } return st; } private static int[] rev(int[]arr) { int[]a=arr.clone(); for(int i=0;i<arr.length;i++) { a[i]=arr[arr.length-i-1]; } return arr; } // for (Map.Entry<Integer,ArrayList<Integer>> entry : hm.entrySet()) { // ArrayList<Integer>a=entry.getValue(); // // } static long ceil(long a,long b) { return (a/b + Math.min(a%b, 1)); } static long pow(long b, long e) { long ans = 1; while (e > 0) { if (e % 2 == 1) ans = ans * b % mod; e >>= 1; b = b * b % mod; } return ans; } static void sortDiff(Pair arr[]) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if(p1.first==p2.first) { return (p1.second-p1.first)-(p2.second-p1.first); } return (p1.second-p1.first)-(p2.second-p2.first); } }); } static void sortF(Pair arr[]) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if(p1.first==p2.first) { return p1.second-p2.second; } return p1.first - p2.first; } }); } static long[] fac; static long mod = (long) 1000000007; static void initFac(long n) { fac = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) { fac[i] = (fac[i - 1] * i) % mod; } } static long nck(int n, int k) { if (n < k) return 0; long den = inv((int) (fac[k] * fac[n - k] % mod)); return fac[n] * den % mod; } static long inv(long x) { return pow(x, mod - 2); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) { Queue<Integer>q=new LinkedList<>(); q.add(source); visited[source]=true; int distance=0; while(!q.isEmpty()) { int curr=q.poll(); distance++; for(int neighbour:a[curr]) { if(!visited[neighbour]) { visited[neighbour]=true; q.add(neighbour); } } } return distance; } public static Set<Integer>factors(int n){ Set<Integer>ans=new HashSet<>(); ans.add(1); for(int i=2;i*i<=n;i++) { if(n%i==0) { ans.add(i); ans.add(n/i); } } return ans; } public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) { boolean[]visited=new boolean[a.length]; int[]parent=new int[a.length]; Queue<Integer>q=new LinkedList<>(); int distance=0; q.add(source); visited[source]=true; parent[source]=-1; while(!q.isEmpty()) { int curr=q.poll(); if(curr==destination) { break; } for(int neighbour:a[curr]) { if(neighbour!=-1&&!visited[neighbour]) { visited[neighbour]=true; q.add(neighbour); parent[neighbour]=curr; } } } int cur=destination; while(parent[cur]!=-1) { distance++; cur=parent[cur]; } return distance; } static int bs(int size,int[]arr) { int x = -1; for (int b = size/2; b >= 1; b /= 2) { while (!ok(arr)); } int k = x+1; return k; } static boolean ok(int[]x) { return false; } public static int solve1(ArrayList<Integer> A) { long[]arr =new long[A.size()+1]; int n=A.size(); for(int i=1;i<=A.size();i++) { arr[i]=((i%2)*((n-i+1)%2))%2; arr[i]%=2; } int ans=0; for(int i=0;i<A.size();i++) { if(arr[i+1]==1) { ans^=A.get(i); } } return ans; } public static String printBinary(long a) { String str=""; for(int i=31;i>=0;i--) { if((a&(1<<i))!=0) { str+=1; } if((a&(1<<i))==0 && !str.isEmpty()) { str+=0; } } return str; } public static String reverse(long a) { long rev=0; String str=""; int x=(int)(Math.log(a)/Math.log(2))+1; for(int i=0;i<32;i++) { rev<<=1; if((a&(1<<i))!=0) { rev|=1; str+=1; } else { str+=0; } } return str; } //////////////////////////////////////////////////////// static void sortS(Pair arr[]) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return p1.second - p2.second; } }); } static class Pair implements Comparable<Pair> { int first ;int second ; public Pair(int x, int y) { this.first = x ;this.second = y ; } @Override public boolean equals(Object obj) { if(obj == this)return true ; if(obj == null)return false ; if(this.getClass() != obj.getClass()) return false ; Pair other = (Pair)(obj) ; if(this.first != other.first)return false ; if(this.second != other.second)return false ; return true ; } @Override public int hashCode() { return this.first^this.second ; } @Override public String toString() { String ans = "" ;ans += this.first ; ans += " "; ans += this.second ; return ans ; } @Override public int compareTo(Main.Pair o) { { if(this.first==o.first) { return this.second-o.second; } return this.first - o.first; } } } ////////////////////////////////////////////////////////////////////////// static int nD(long num) { String s=String.valueOf(num); return s.length(); } static int CommonDigits(int x,int y) { String s=String.valueOf(x); String s2=String.valueOf(y); return 0; } static int lcs(String str1, String str2, int m, int n) { int L[][] = new int[m + 1][n + 1]; int i, j; // Following steps build L[m+1][n+1] in // bottom up fashion. Note that L[i][j] // contains length of LCS of str1[0..i-1] // and str2[0..j-1] for (i = 0; i <= m; i++) { for (j = 0; j <= n; j++) { if (i == 0 || j == 0) L[i][j] = 0; else if (str1.charAt(i - 1) == str2.charAt(j - 1)) L[i][j] = L[i - 1][j - 1] + 1; else L[i][j] = Math.max(L[i - 1][j], L[i][j - 1]); } } // L[m][n] contains length of LCS // for X[0..n-1] and Y[0..m-1] return L[m][n]; } ///////////////////////////////// boolean IsPowerOfTwo(int x) { return (x != 0) && ((x & (x - 1)) == 0); } //////////////////////////////// static long power(long a,long b,long m ) { long ans=1; while(b>0) { if(b%2==1) { ans=((ans%m)*(a%m))%m; b--; } else { a=(a*a)%m;b/=2; } } return ans%m; } /////////////////////////////// public static boolean repeatedSubString(String string) { return ((string + string).indexOf(string, 1) != string.length()); } static int search(char[]c,int start,int end,char x) { for(int i=start;i<end;i++) { if(c[i]==x) {return i;} } return -2; } //////////////////////////////// static int gcd(int a, int b) { while (b != 0) { int t = b; b = a % b; a = t; } return a; } static long fac(long a) { if(a== 0L || a==1L)return 1L ; return a*fac(a-1L) ; } static ArrayList al() { ArrayList<Integer>a =new ArrayList<>(); return a; } static HashSet h() { return new HashSet<Integer>(); } static void debug(long[][]a) { int n= a.length; for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) { out.print(a[i][j]+" "); } out.print("\n"); } } static void debug(int[]a) { out.println(Arrays.toString(a)); } static void debug(ArrayList<Integer>a) { out.println(a.toString()); } static boolean[]seive(int n){ boolean[]b=new boolean[n+1]; for (int i = 2; i <= n; i++) b[i] = true; for(int i=2;i*i<=n;i++) { if(b[i]) { for(int j=i*i;j<=n;j+=i) { b[j]=false; } } } return b; } static int longestIncreasingSubseq(int[]arr) { int[]sizes=new int[arr.length]; Arrays.fill(sizes, 1); int max=1; for(int i=1;i<arr.length;i++) { for(int j=0;j<i;j++) { if(arr[j]<arr[i]) { sizes[i]=Math.max(sizes[i],sizes[j]+1); max=Math.max(max, sizes[i]); } } } return max; } public static ArrayList primeFactors(long n) { ArrayList<Long>h= new ArrayList<>(); // Print the number of 2s that divide n if(n%2 ==0) {h.add(2L);} // n must be odd at this point. So we can // skip one element (Note i = i +2) for (long i = 3; i <= Math.sqrt(n); i+= 2) { if(n%i==0) {h.add(i);} } if (n > 2) h.add(n); return h; } static boolean Divisors(long n){ if(n%2==1) { return true; } for (long i=2; i<=Math.sqrt(n); i++){ if (n%i==0 && i%2==1){ return true; } } return false; } static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); public static void superSet(int[]a,ArrayList<String>al,int i,String s) { if(i==a.length) { al.add(s); return; } superSet(a,al,i+1,s); superSet(a,al,i+1,s+a[i]+" "); } public static long[] makeArr() { long size=in.nextInt(); long []arr=new long[(int)size]; for(int i=0;i<size;i++) { arr[i]=in.nextInt(); } return arr; } public static long[] arr(int n) { long []arr=new long[n+1]; for(int i=1;i<n+1;i++) { arr[i]=in.nextLong(); } return arr; } public static void sort(long arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } } static void println(long x) { out.println(x); } static void print(long c) { out.print(c); } static void print(int c) { out.print(c); } static void println(int x) { out.println(x); } static void print(String s) { out.print(s); } static void println(String s) { out.println(s); } public static void merge(long arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long[n1]; long R[] = new long[n2]; //Copy data to temp arrays for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } public static void reverse(int[] array) { int n = array.length; for (int i = 0; i < n / 2; i++) { int temp = array[i]; array[i] = array[n - i - 1]; array[n - i - 1] = temp; } } public static long nCr(int n,int k) { long ans=1L; k=k>n-k?n-k:k; for( int j=1;j<=k;j++,n--) { if(n%j==0) { ans*=n/j; }else if(ans%j==0) { ans=ans/j*n; }else { ans=(ans*n)/j; } } return ans; } static int searchMax(int index,long[]inp) { while(index+1<inp.length &&inp[index+1]>inp[index]) { index+=1; } return index; } static int searchMin(int index,long[]inp) { while(index+1<inp.length &&inp[index+1]<inp[index]) { index+=1; } return index; } public class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } static class Pairr implements Comparable<Pairr>{ private int index; private int cumsum; private ArrayList<Integer>indices; public Pairr(int index,int cumsum) { this.index=index; this.cumsum=cumsum; indices=new ArrayList<Integer>(); } public int compareTo(Pairr other) { return Integer.compare(cumsum, other.cumsum); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
45f82f645ec64dbcad1f489de1e26f52
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.util.stream.Collectors; import java.io.*; import static java.util.stream.Collectors.*; public class codefo { public static void main(String[] args)throws IOException { Scanner sc=new Scanner(System.in); int t=sc.nextInt();; while(t-->0) { int n=sc.nextInt(); List<Integer> arr=new ArrayList<Integer>(); for(int i=0;i<n;i++) { arr.add(sc.nextInt()); } Collections.sort(arr); int j=n-2; int i=2; long sumred=arr.get(n-1); long sumblue=arr.get(0)+arr.get(1); int f=0; while(i<j) { sumred+=arr.get(j); sumblue+=arr.get(i); i++; j--; } if(sumred>sumblue) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
74b9bc5e0078538b47c5003fdb888456
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static long mod = (int)1e9+7; static PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc =new FastReader(); int t=sc.nextInt(); // int t=1; O : while(t-->0) { int n=sc.nextInt(); int a[]=sc.readArray(n); radixSort2(a); long sumr=0,sumb=0; sumr+=a[n-1]; sumb+=a[0]+a[1]; int i1=2,i2=n-2; while(i1<i2) { if(sumr>sumb) { printY(); continue O; } sumb+=a[i1]; sumr+=a[i2]; i1++; i2--; } if(sumr>sumb) printY(); else printN(); } out.flush(); } static void printN() { System.out.println("NO"); } static void printY() { System.out.println("YES"); } static int findfrequencies(int a[],int n) { int count=0; for(int i=0;i<a.length;i++) { if(a[i]==n) { count++; } } return count; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } static int[] EvenOddArragement(int a[]) { ArrayList<Integer> list=new ArrayList<>(); for(int i=0;i<a.length;i++) { if(a[i]%2==0) { list.add(a[i]); } } for(int i=0;i<a.length;i++) { if(a[i]%2!=0) { list.add(a[i]); } } for(int i=0;i<a.length;i++) { a[i]=list.get(i); } return a; } static int gcd(int a, int b) { while (b != 0) { int t = a; a = b; b = t % b; } return a; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static int DigitSum(int n) { int r=0,sum=0; while(n>=0) { r=n%10; sum=sum+r; n=n/10; } return sum; } static boolean checkPerfectSquare(int number) { double sqrt=Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean isPowerOfTwo(int n) { if(n==0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static boolean isPrime2(int n) { if (n <= 1) { return false; } if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) { if (n % i == 0) { return false; } } return true; } static String minLexRotation(String str) { int n = str.length(); String arr[] = new String[n]; String concat = str + str; for(int i=0;i<n;i++) { arr[i] = concat.substring(i, i + n); } Arrays.sort(arr); return arr[0]; } static String maxLexRotation(String str) { int n = str.length(); String arr[] = new String[n]; String concat = str + str; for (int i = 0; i < n; i++) { arr[i] = concat.substring(i, i + n); } Arrays.sort(arr); return arr[arr.length-1]; } static class P implements Comparable<P> { int i, j; public P(int i, int j) { this.i=i; this.j=j; } public int compareTo(P o) { return Integer.compare(i, o.i); } } static int binary_search(int a[],int value) { int start=0; int end=a.length-1; int mid=start+(end-start)/2; while(start<=end) { if(a[mid]==value) { return mid; } if(a[mid]>value) { end=mid-1; } else { start=mid+1; } mid=start+(end-start)/2; } return -1; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
e05227b7edab37af8cbc95d88157efa3
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class Solution { 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 sort(int a[]){ // int -> long ArrayList<Integer> arr=new ArrayList<>(); // Integer -> Long for(int i=0;i<a.length;i++) arr.add(a[i]); Collections.sort(arr); for(int i=0;i<a.length;i++) a[i]=arr.get(i); } private static long gcd(long a, long b){ if(b==0)return a; return gcd(b,a%b); } private static long pow(long x,long y){ if(y==0)return 1; long temp = pow(x, y/2); if(y%2==1){ return x*temp*temp; } else{ return temp*temp; } } static long powM(long a, long b) { if (b == 0) return 1; long res = pow(a, b / 2); res = (res%mod * res%mod) % 1_000_000_007; if (b % 2 == 1) { res = (res%mod * a%mod) % 1_000_000_007; } return res%mod; } static int log(long n){ int res = 0; while(n>0){ res++; n/=2; } return res; } static int mod = (int)1e9+7; static PrintWriter out; static FastReader sc ; public static void main(String[] args) throws IOException { sc = new FastReader(); out = new PrintWriter(System.out); // primes(); // ________________________________ StringBuilder output = new StringBuilder(); int test =sc.nextInt(); while (test-- > 0) { //System.out.println(mdh+" "+nhc); int n = sc.nextInt(); ArrayList<Integer>al = new ArrayList<>(); for(int i =0;i<n;i++) { al.add(sc.nextInt()); } solver(n,al); } // solver(s); // int n = sc.nextInt(); // out.println(solver()); // ________________________________ out.flush(); } static class Edge { int u, v; Edge(int u, int v) { this.u = u; this.v = v; } } static class Pair implements Comparable <Pair>{ int l, r; Pair(int l, int r) { this.l = l; this.r = r; } public int compareTo(Pair o) { return this.l-o.l; } } static int [][] dp; public static void solver( int n, ArrayList<Integer>al) { Collections.sort(al); long blue = al.get(0)+al.get(1); long red = al.get(n-1); int i =2; int j =n-2; boolean flag =false; while(i<j) { if(red>blue) flag = true; blue+=al.get(i); red+=al.get(j); i++; j--; if(flag) break; } if(red>blue) flag = true; if(flag) System.out.println("YES"); else System.out.println("NO"); //System.out.println(red+" "+blue); } public static int Mex(int []a, int i, int j) { boolean [] vis = new boolean[a.length+2]; int mex =0; for(int k=i;k<j;k++) { if(a[k]<vis.length) { vis[a[k]] = true; } } while(vis[mex]==true) { mex++; } return mex; } public static long log2(long N) { // calculate log2 N indirectly // using log() method long result = (long)(Math.log(N) / Math.log(2)); return result; } static long highestPowerof2(long x) { // check for the set bits x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; // Then we remove all but the top bit by xor'ing the // string of 1's with that string of 1's shifted one to // the left, and we end up with just the one top bit // followed by 0's. return x ^ (x >> 1); } public static void rotate(int [] arr, int s, int n) { int x = arr[n], i; for (i = n; i > s; i--) arr[i] = arr[i-1]; arr[s] = x; // for(int j=s;j<=n;j++) // System.out.print(arr[j]+" "); // System.out.println(); } static int lower_bound(int[] a , long x) { int i = 0; int j = a.length-1; //if(arr[i] > key)return -1; if(a[j] < x)return a.length; while(i<j) { int mid = (i+j)/2; if(a[mid] == x) { j = mid; } else if(a[mid] < x) { i = mid+1; } else j = mid-1; } return i; } int upper_bound(int [] arr , int key) { int i = 0; int j = arr.length-1; if(arr[j] <= key)return j+1; while(i<j) { int mid = (i+j)/2; if(arr[mid] <= key) { i = mid+1; } else j = mid; } return i; } static void reverseArray(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
f420b79b1d5a5e7b9aa8649313cad8c0
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class QualVQuan { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numCases = sc.nextInt(); for (int i = 0; i < numCases; i++) { int amt = sc.nextInt(); Integer[] arr = new Integer[amt]; for (int a = 0; a < amt; a++) { arr[a] = sc.nextInt(); } Arrays.sort(arr); long redSum = 0; long blueSum = arr[0]; boolean poss = false; for (int k = 0; k <= amt/2 - 1; k++) { redSum += arr[arr.length - 1 - k]; blueSum += arr[k+1]; if (redSum > blueSum) { poss = true; break; } } System.out.println(poss ? "YES" : "NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
1993e8a9a5cfeabde74174a1e328849c
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.Arrays; public class B { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(reader.readLine()); String[] res = new String[T]; for(int t = 0; t < T; t++) { int N = Integer.parseInt(reader.readLine()); String[] line = reader.readLine().split(" "); Long[] nums = new Long[N]; for(int i = 0; i < N; i++) { nums[i] = Long.parseLong(line[i]); } Arrays.sort(nums); long max = nums[N - 1]; long min = nums[0] + nums[1]; for(int i = 2; i < N / 2 + 1; i++) { if (max > min) { break; } max += nums[N - i]; min += nums[i]; } if (max > min) res[t] = "YES"; else res[t] = "NO"; } BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); for(String s : res) { writer.write(s); writer.newLine(); } writer.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
1a888b5bd8106d3b549d8bca115c9e47
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class CodeForces1646B { public static void main(String[] args) { Scanner input = new Scanner(System.in); int numTest = input.nextInt(); for (int i = 0; i < numTest; i++) { int seqLength = input.nextInt(); Long[] seqAsArr = new Long[seqLength]; for (int j = 0; j < seqLength; j++) { seqAsArr[j] = input.nextLong(); } if (seqLength > 2) { System.out.println(validateSequence(seqLength, seqAsArr) ? "YES" : "NO"); } else { System.out.println("NO"); } } } private static boolean validateSequence(int seqLength, Long[] array) { // Sort array from smallest to largest // Ints on the left will be preferentially painted blue, ints on the right red Arrays.sort(array); // For a valid sequence to exist we need at least 3 ints, however if they are identical the sequence cannot be valid if (array[0] == array[seqLength - 1]) { return false; } // Hard-code paint the last int red and first two blue. The ints are considered "unavailable" // Start the counters and sums. int redCount = 1; Long redSum = array[seqLength - 1]; int blueCount = 2; Long blueSum = array[0] + array[1]; // My strategy involves trying to paint the next available int on the left of sorted array blue // This variable keeps track of the next possible blue int int indexPosition = 2; // The loop will try to paint cells blue or red if there are ints left to paint && a valid combination has not been found while ((indexPosition < seqLength - redCount) && !(blueCount > redCount && blueSum < redSum)) { // Check if the int at indexPosition could be painted blue while keeping the redSum larger than blueSum if (blueSum + array[indexPosition] < redSum) { blueSum += array[indexPosition]; blueCount++; // If the condition above has been satisfied, check if blueCount is also satisfied. If so, exit the loop if (blueCount > redCount) { break; } // If the sum is valid but the count isn't, advance indexPosition to possibly paint that int blue too indexPosition++; // If the int can't be blue, paint the next available int on the right red // This could be int at indexPosition, that's ok the loop condition will be false then } else{ redSum += array[seqLength - (redCount + 1)]; redCount++; } } // Return true if the final blueCount is larger than redCount and blueSum is smaller than redSum return blueCount > redCount && blueSum < redSum; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
47a7a0d5f5319e3621f21a430ff9f213
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
// package div_2_774; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class b{ public static void main(String[] args){ FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int a[]=sc.fastArray(n); sort(a); // print(a); long prefix[]=new long [n]; prefix[0]=a[0]; for(int i=1;i<n;i++)prefix[i]=prefix[i-1]+a[i]; long suffix[]=new long [n]; suffix[n-1]=a[n-1]; for(int i=n-2;i>=0;i--)suffix[i]=suffix[i+1]+a[i]; boolean pos=false; for(int i=1;i<n;i++) { int x=n-i; if(i>=x)break; if(suffix[x]>prefix[i]) { // System.out.println(x+" "+i); // System.out.println(suffix[x]+" "+prefix[i]); pos=true; break; } } System.out.println(pos?"yes":"no"); } } static void sort(int a[]) { ArrayList<Integer> ans= new ArrayList<>(); for(int i:a)ans.add(i); Collections.sort(ans); for(int i=0;i<a.length;i++)a[i]=ans.get(i); } static int pow(int a,int b) { if(b==0)return 1; if(b==1)return a; return a*pow(a,b-1); } static class pair { int x;int y; pair(int x,int y){ this.x=x; this.y=y; } } static ArrayList<Integer> primeFac(int n){ ArrayList<Integer>ans = new ArrayList<Integer>(); int lp[]=new int [n+1]; Arrays.fill(lp, 0); //0-prime for(int i=2;i<=n;i++) { if(lp[i]==0) { for(int j=i;j<=n;j+=i) { if(lp[j]==0) lp[j]=i; } } } int fac=n; while(fac>1) { ans.add(lp[fac]); fac=fac/lp[fac]; } print(ans); return ans; } static ArrayList<Long> prime_in_given_range(long l,long r){ ArrayList<Long> ans= new ArrayList<>(); int n=(int)Math.sqrt(r)+1; int prime[]=sieve_of_Eratosthenes(n); long res[]=new long [(int)(r-l)+1]; for(int i=0;i<=r-l;i++) { res[i]=i+l; } for(int i=0;i<prime.length;i++) { if(prime[i]==1) { System.out.println(2); for(int j=Math.max((int)i*i, (int)(l+i-1)/i*i);j<=r;j+=i) { res[j-(int)l]=0; } } } for(long i:res) if(i!=0)ans.add(i); return ans; } static int [] sieve_of_Eratosthenes(int n) { int prime[]=new int [n]; Arrays.fill(prime, 1); // 1-prime | 0-not prime prime[0]=prime[1]=0; for(int i=2;i<n;i++) { if(prime[i]==1) { for(int j=i*i;j<n;j+=i) { prime[j]=0; } } } return prime; } static long binpow(long a,long b) { long res=1; if(b==0)return 1; if(a==0)return 0; while(b>0) { if((b&1)==1) { res*=a; } a*=a; b>>=1; } return res; } static void print(int a[]) { System.out.println(a.length); for(int i:a) { System.out.print(i+" "); } System.out.println(); } static void print(long a[]) { System.out.println(a.length); for(long i:a) { System.out.print(i+" "); } System.out.println(); } static long rolling_hashcode(String s ,int st,int end,long Hashcode,int n) { if(end>=s.length()) return -1; int mod=1000000007; Hashcode=Hashcode-(s.charAt(st-1)*(long)Math.pow(27,n-1)); Hashcode*=10; Hashcode=(Hashcode+(long)s.charAt(end))%mod; return Hashcode; } static long hashcode(String s,int n) { long code=0; for(int i=0;i<n;i++) { code+=((long)s.charAt(i)*(long)Math.pow(27, n-i-1)%1000000007); } return code; } static void print(ArrayList<Integer> a) { System.out.println(a.size()); for(long i:a) { System.out.print(i+" "); } System.out.println(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } int [] fastArray(int n) { int a[]=new int [n]; for(int i=0;i<n;i++) { a[i]=nextInt(); } return a; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
289f5e7969cbe0e35f0f8076c8cc90ff
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class B { public static int[] v; public static int[] a; public static void main(String[] args) { Scanner go = new Scanner(System.in); int t = go.nextInt(); while (t-->0){ int n = go.nextInt(); a = new int[n]; long sum = 0; for (int i=0; i<n; i++){ a[i] = go.nextInt(); sum += a[i]; } long l = 0; long r = 0; boolean g = false; // v = new int[n]; mergeSort(a,n); if (n %2 == 0){ for (int i=0; i<n/2; i++){ l += a[i]; } r = sum - l - a[n/2]; }else { for (int i=0; i<=n/2; i++){ l += a[i]; } r = sum - l; } // for (int i=1; i<n; i++){ // if (i >= n-i){ // break; // }else { // l += a[i]; // r += a[n-i]; // if (r > l){ // g = true; // break; // } // } // } if (r > l){ System.out.println("Yes"); }else { System.out.println("No"); } } } public static void mergeSort(int[] a, int n) { if (n < 2) { return; } int mid = n / 2; int[] l = new int[mid]; int[] r = new int[n - mid]; for (int i = 0; i < mid; i++) { l[i] = a[i]; } for (int i = mid; i < n; i++) { r[i - mid] = a[i]; } mergeSort(l, mid); mergeSort(r, n - mid); merge(a, l, r, mid, n - mid); } public static void merge(int[] a, int[] l, int[] r, int left, int right) { int i = 0, j = 0, k = 0; while (i < left && j < right) { if (l[i] <= r[j]) { a[k++] = l[i++]; } else { a[k++] = r[j++]; } } while (i < left) { a[k++] = l[i++]; } while (j < right) { a[k++] = r[j++]; } } } // 6 // 0 1 2
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
9ee6523633a7d9f4856c30653abd8892
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.io.File; import java.io.FileInputStream; import java.util.*; public class Main { // static final File ip = new File("input.txt"); // static final File op = new File("output.txt"); // static { // try { // System.setOut(new PrintStream(op)); // System.setIn(new FileInputStream(ip)); // } catch (Exception e) { // } // } static final int mod = 1_000_000_007; static boolean isValid(long[] a) { int n = a.length; long[] s = new long[n+1]; for (int i = 1; i < n; i++) { s[i] = s[i - 1] + a[i]; } for (int i = 0; i < n; i++) { s[i + 1] = s[i] + a[i]; } for (int i = 0; i + i + 1 <= n; i++) { if (s[i + 1] < s[n] - s[n - i]) { return true; } } return false; } public static void main(String[] args) { FastReader sc = new FastReader(); int test = 1; test = sc.nextInt(); while (test-- > 0) { int n = sc.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = sc.nextLong(); sortL(a); if (isValid(a) == true) System.out.println("YES"); else System.out.println("NO"); } } static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } public static double log2(long N) { double result = (double) (Math.log(N) / (double) Math.log(2)); return result; } public static int countSetBits(long number) { int count = 0; while (number > 0) { ++count; number &= number - 1; } return count; } static int lower_bound(long target, long[] a, int pos) { if (pos >= a.length) return -1; int low = pos, high = a.length - 1; while (low < high) { int mid = low + (high - low) / 2; if (a[mid] < target) low = mid + 1; else high = mid; } return a[low] >= target ? low : -1; } private static void swap(long[] a, int i, int j) { long tmp = a[i]; a[i] = a[j]; a[j] = tmp; } static class pair { long a; long b; pair(long x, long y) { this.a = x; this.b = y; } } static class first implements Comparator<pair> { public int compare(pair p1, pair p2) { if (p1.a > p2.a) return 1; else if (p1.a < p2.a) return -1; return 0; } } static class second implements Comparator<pair> { public int compare(pair p1, pair p2) { if (p1.b > p2.b) return 1; else if (p1.b < p2.b) return -1; return 0; } } private static long getSum(int[] array) { long sum = 0; for (int value : array) { sum += value; } return sum; } private static boolean isPrime(Long x) { if (x < 2) return false; for (long d = 2; d * d <= x; ++d) { if (x % d == 0) return false; } return true; } static long[] reverse(long a[]) { int n = a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } return a; } private static boolean isPrimeInt(int x) { if (x < 2) return false; for (int d = 2; d * d <= x; ++d) { if (x % d == 0) return false; } return true; } public static String reverse(String input) { StringBuilder str = new StringBuilder(""); for (int i = input.length() - 1; i >= 0; i--) { str.append(input.charAt(i)); } return str.toString(); } private static int[] getPrimes(int n) { boolean[] used = new boolean[n + 1]; used[0] = used[1] = true; // int size = 0; for (int i = 2; i <= n; ++i) { if (!used[i]) { // ++size; for (int j = 2 * i; j <= n; j += i) { used[j] = true; } } } int[] primes = new int[n + 1]; for (int i = 0; i <= n; ++i) { if (!used[i]) { primes[i] = 1; } } return primes; } static long expo(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = (res * a) % mod; a = (a * a) % mod; b = b >> 1; } return res; } static long mminvprime(long a, long b) { return expo(a, b - 2, b); } static long mod_add(long a, long b, long m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; } static long mod_mul(long a, long b, long m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; } static long mod_sub(long a, long b, long m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; } static long mod_div(long a, long b, long m) { a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m; } private static long lcm(long a, long b) { return a / gcd(a, b) * b; } private static long gcd(long a, long b) { return (a == 0 ? b : gcd(b % a, a)); } static void sortI(int[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } Arrays.sort(arr); } static void shuffleList(ArrayList<Long> arr) { int n = arr.size(); Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = arr.get(i); int randomPos = i + rnd.nextInt(n - i); arr.set(i, arr.get(randomPos)); arr.set(randomPos, tmp); } } static void factorize(long n) { int count = 0; while (!(n % 2 > 0)) { n >>= 1; count++; } if (count > 0) { // System.out.println("2" + " " + count); } long i = 0; for (i = 3; i <= (long) Math.sqrt(n); i += 2) { count = 0; while (n % i == 0) { count++; n = n / i; } if (count > 0) { // System.out.println(i + " " + count); } } if (n > 2) { // System.out.println(i + " " + count); } } static void sortL(long[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } Arrays.sort(arr); } ////////////////////////////////// DSU START /////////////////////////// static class DSU { int[] parent, rank, total_Elements; DSU(int n) { parent = new int[n + 1]; rank = new int[n + 1]; total_Elements = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; rank[i] = 1; total_Elements[i] = 1; } } int find(int u) { if (parent[u] == u) return u; return parent[u] = find(parent[u]); } void unionByRank(int u, int v) { int pu = find(u); int pv = find(v); if (pu != pv) { if (rank[pu] > rank[pv]) { parent[pv] = pu; total_Elements[pu] += total_Elements[pv]; } else if (rank[pu] < rank[pv]) { parent[pu] = pv; total_Elements[pv] += total_Elements[pu]; } else { parent[pu] = pv; total_Elements[pv] += total_Elements[pu]; rank[pv]++; } } } boolean unionBySize(int u, int v) { u = find(u); v = find(v); if (u != v) { parent[u] = v; total_Elements[v] += total_Elements[u]; total_Elements[u] = 0; return true; } return false; } } ////////////////////////////////// DSU END ///////////////////////////// static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public boolean hasNext() { return false; } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
ba47aac2541d103585290d3294311cae
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; /** * * @author eslam */ public class IncreaseSubarraySums { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException { FastReader input = new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t = input.nextInt(); while (t-- > 0) { int n = input.nextInt(); Long a[] = new Long[n]; for (int i = 0; i < n; i++) { a[i] = input.nextLong(); } Arrays.sort(a); long sumb = a[0]+a[1]; long sumr = a[n-1]; int p1 = n-2; int p2 = 2; while(p1>p2){ sumb+=a[p2++]; sumr+=a[p1--]; if(sumr>sumb)break; } if (sumr>sumb) { log.write("YES\n"); } else { log.write("NO\n"); } } log.flush(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
ac7b7defa5fefbab15243f6b1449e483
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class D { 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(); ArrayList<Long> l= new ArrayList<>(); for(int i=0;i<n;i++) l.add(sc.nextLong()); Collections.sort(l); long suma=l.get(0)+l.get(1); long sumb=l.get(n-1); int i=2,j=n-2; int z=0; if(sumb>suma) System.out.println("YES"); else { while(i<j) { suma+=l.get(i); sumb+=l.get(j); if(sumb>suma) { System.out.println("YES"); z=1;break; } i++;j--; } if(z==0) System.out.println("NO"); } } sc.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
17abd8c3c215428ee326b353d7ae4031
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class a { static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) throws java.lang.Exception { int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); ArrayList<Integer> ls = new ArrayList<>(); for(int i = 0; i < n; i++){ ls.add(sc.nextInt()); } Collections.sort(ls); long rsum = 0,bsum = ls.get(0); int start = 1,end = n-1; while(start < end){ bsum += ls.get(start); rsum += ls.get(end); if(rsum > bsum){ break; } start++; end--; } if(rsum > bsum){ out.println("YES"); }else{ out.println("NO"); } } // discipline is doing what needs to be done even if you don't want to do it. out.flush(); } } class FastReader{ BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
8f14c9e0b39dce2bedad13ac73c6f8aa
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import static java.util.Arrays.asList; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * B. Quality vs Quantity * @see <a href="https://codeforces.com/contest/1646/problem/B">https://codeforces.com/contest/1646/problem/B</a> */ public class Main { private final InputStream in; private final PrintStream out; public Main( final Boolean sample, final InputStream in, final PrintStream out) { this.in = in; this.out = out; } private void handleTestCase(final Integer i, final FastScanner sc) { final int n = sc.nextInt(); final List<Integer> a = new ArrayList<>(n); for (int j = 0; j < n; j++) { a.add(sc.nextInt()); } a.sort(null); String ans = "NO"; if (a.get(0) != a.get(n - 1)) { long l = a.get(0); long r = 0; for (int j = 1, k = n - 1; j < k; j++, k--) { l += a.get(j); r += a.get(k); if (r > l) { ans = "YES"; break; } } } this.out.println(ans); } public void solve() { try (final FastScanner sc = new FastScanner(this.in)) { final int numberOfTestCases = sc.nextInt(); for (int i = 0; i < numberOfTestCases; i++) { handleTestCase(i, sc); } } } public static void main(final String[] args) throws IOException, URISyntaxException { final boolean sample = isSample(); final InputStream is; final PrintStream out; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); long timerStart = 0; if (sample) { is = Main.class.getResourceAsStream("sample.in"); out = new PrintStream(baos, true); timerStart = System.nanoTime(); } else { is = System.in; out = System.out; } new Main(sample, is, out).solve(); out.flush(); if (sample) { final long timeSpent = (System.nanoTime() - timerStart) / 1_000; final double time; final String unit; if (timeSpent < 1_000) { time = timeSpent; unit = "µs"; } else if (timeSpent < 1_000_000) { time = timeSpent / 1_000.0; unit = "ms"; } else { time = timeSpent / 1_000_000.0; unit = "s"; } final Path path = Paths.get(Main.class.getResource("sample.out").toURI()); final List<String> expected = Files.readAllLines(path); final List<String> actual = asList(baos.toString().split("\\r?\\n")); if (!expected.equals(actual)) { throw new AssertionError(String.format( "Expected %s, got %s", expected, actual)); } actual.forEach(System.out::println); System.out.println(String.format("took: %.3f %s", time, unit)); } } private static boolean isSample() { try { return "sample".equals(System.getProperty("codeforces")); } catch (final SecurityException e) { return false; } } private static final class FastScanner implements Closeable { private final BufferedReader br; private StringTokenizer st; public FastScanner(final InputStream in) { this.br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (final IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextIntArray(final int n) { final int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } @Override public void close() { try { this.br.close(); } catch (final IOException e) { // ignore } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
4e57c572e4ded1ee5250934972db318c
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.BigInteger; public class Main { InputStream is; PrintWriter out = new PrintWriter(System.out); ; String INPUT = ""; void run() throws Exception { is = System.in; solve(); out.flush(); out.close(); } public static void main(String[] args) throws Exception { new Main().run(); } public byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; public int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } public double nd() { return Double.parseDouble(ns()); } public char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private int ni() { return (int)nl(); } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-') { minus = true; b = readByte(); } while(true) { if(b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } class Pair { int first; int second; Pair(int a, int b) { first = a; second = b; } } // KMP ALGORITHM void KMPSearch(String pat, String txt) { int M = pat.length(); int N = txt.length(); int lps[] = new int[M]; int j = 0; computeLPSArray(pat, M, lps); int i = 0; while (i < N) { if (pat.charAt(j) == txt.charAt(i)) { j++; i++; } if (j == M) { j = lps[j - 1]; } else if (i < N && pat.charAt(j) != txt.charAt(i)) { if (j != 0) j = lps[j - 1]; else i = i + 1; } } } void computeLPSArray(String pat, int M, int lps[]) { int len = 0; int i = 1; lps[0] = 0; while (i < M) { if (pat.charAt(i) == pat.charAt(len)) { len++; lps[i] = len; i++; } else { if (len != 0) { len = lps[len - 1]; } else { lps[i] = len; i++; } } } } int FirstAndLastOccurrenceOfAnElement(int[] arr, int target, boolean findStartIndex) { int ans = -1; int n = arr.length; int low = 0; int high = n-1; while(low <= high) { int mid = low + (high - low)/2; if(arr[mid] > target) high = mid-1; else if(arr[mid] < target) low = mid+1; else { ans = mid; if(findStartIndex) high = mid-1; else low = mid+1; } } return ans; } int[] na(int n) { int[] arr = new int[n]; for(int i=0; i<n; i++) arr[i]=ni(); return arr; } long[] nal(int n) { long[] arr = new long[n]; for(int i=0; i<n; i++) arr[i]=nl(); return arr; } void solve() { int t = ni(); while(t-- > 0) { int n = ni(); Long[] arr = new Long[n]; for (int i = 0; i < n; i++) { arr[i] = nl(); } Arrays.sort(arr); long sumR = arr[n - 1], sumB = arr[0] + arr[1]; int l=2, r = n-2; while(l<r && sumR <= sumB) { sumB += arr[l++]; sumR += arr[r--]; } out.println(sumR > sumB ? "YES":"NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
9ee629c6db465e624f3f7a9caec2a444
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
//package com.company; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Reader.init(System.in); int t = Reader.nextInt(); for (int i = 0; i < t; i++) { int k = Reader.nextInt(); Long [] s = new Long[k]; for (int j = 0; j < k; j++) { s[j] = Reader.nextLong(); } Arrays.parallelSort(s); long sum1 = 0; long sum2 = 0; for (int j = 0; j <= k/2; j++) { sum1 += s[j]; } for (int j = k/2+1; j < k; j++) { sum2+=s[j]; } if (k%2==0) { sum1-=s[k/2]; if (sum1<sum2) { System.out.println("YES"); } else{ System.out.println("NO"); } } else{ if (sum1<sum2) { System.out.println("YES"); } else{ System.out.println("NO"); } } } } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static long nextLong() throws IOException { return Long.parseLong(next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
ee438953311bedb41f5d1122fc29da00
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class D { 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(); ArrayList<Long> l= new ArrayList<>(); for(int i=0;i<n;i++) l.add(sc.nextLong()); Collections.sort(l); long suma=l.get(0)+l.get(1); long sumb=l.get(n-1); int i=2,j=n-2; int z=0; if(sumb>suma) System.out.println("YES"); else { while(i<j) { suma+=l.get(i); sumb+=l.get(j); if(sumb>suma) { System.out.println("YES"); z=1;break; } i++;j--; } if(z==0) System.out.println("NO"); } } sc.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
0f3a962785fb1af4d7bcceab1c7e1c5c
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
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.*; import java.io.PrintWriter; import java.io.OutputStream; public class Solution{ 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(); Long res[]=new Long[n]; for(int i=0;i<n;i++){ res[i]=sc.nextLong(); } Arrays.sort(res); int n1=n/2; long sum1=0; long sum2=0; for(int i=0;i<=n1;i++){ sum1+=res[i]; } for(int i=n1+1;i<n;i++){ sum2+=res[i]; } if(n%2==0){ sum1-=res[n1]; } if(sum1<sum2){ System.out.println("YES"); } else{ System.out.println("NO"); } } } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
04db5799a9a4bbd29b0ae638d853ff1f
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static PrintWriter out; static Kioken sc; public static void main(String[] args) throws FileNotFoundException { boolean t = true; boolean f = false; if (f) { out = new PrintWriter("output.txt"); sc = new Kioken("input.txt"); } else { out = new PrintWriter((System.out)); sc = new Kioken(); } int tt = 1; tt = sc.nextInt(); while (tt-- > 0) { solve(); } out.flush(); out.close(); } 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);} public static void solve() { int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++){ arr[i] = sc.nextInt(); } ruffleSort(arr); // out.println(" " + Arrays.toString(arr)); // long[] prefix = new long[n+1]; // for(int i = 0; i < n; i++){ // prefix[i+1] = prefix[i] + arr[i]; // } long sum = 0; long sum1 = 0; int i = 1; int j = n - 1; long sum2 = arr[0]; while(i < j){ sum2 += arr[i]; sum1 += arr[j]; if(sum1 > sum2){ out.println("YES"); return; } i++; j--; } out.println("NO"); return; // for(int i = n - 1; i >= 0; i--){ // sum1 += arr[i]; // int cnt = (n - i + 1); // int t = (cnt + n - i); // if(cnt < n+1){ // if(n%2 == 0){ // if(t < n){ // long sum2 = prefix[cnt]; // if(sum1 > sum2){ // out.println("YES"); // return; // } // } // }else{ // if(t <= n){ // long sum2 = prefix[cnt]; // if(sum1 > sum2){ // out.println("YES"); // return; // } // } // } // } // } // out.println("NO"); } public static long gcd(long a, long b) { while (b != 0) { long rem = a % b; a = b; b = rem; } return a; } public static long leftShift(long a) { return (long) Math.pow(2, a); } public static boolean[] sieve(int n) { boolean isPrime[] = new boolean[n + 1]; Arrays.fill(isPrime, true); isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i <= n; i++) { if (!isPrime[i]) continue; for (int j = i * 2; j <= n; j = j + i) { isPrime[j] = false; } } return isPrime; } public static void reverse(int[] arr) { Arrays.sort(arr); int n = arr.length; for (int i = 0; i < arr.length / 2; i++) { int temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } return; } public static int lower_bound(ArrayList<Integer> ar, int k) { int s = 0, e = ar.size(); while (s != e) { int mid = s + e >> 1; if (ar.get(mid) <= k) { s = mid + 1; } else { e = mid; } } return Math.abs(s) - 1; } public static int upper_bound(ArrayList<Integer> ar, int k) { int s = 0; int e = ar.size(); while (s != e) { int mid = s + e >> 1; if (ar.get(mid) < k) { s = mid + 1; } else { e = mid; } } if (s == ar.size()) { return -1; } return s; } static class Kioken { // FileInputStream br = new FileInputStream("input.txt"); BufferedReader br; StringTokenizer st; Kioken(String filename) { try { FileReader fr = new FileReader(filename); br = new BufferedReader(fr); st = new StringTokenizer(""); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } Kioken() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception 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()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } public boolean hasNext() { String next = null; try { next = br.readLine(); } catch (Exception e) { } if (next == null || next.length() == 0) { return false; } st = new StringTokenizer(next); return true; } } class DSU { int[] parent, size; DSU(int n) { parent = new int[n]; size = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; size[i] = 1; } } int findParent(int i) { if (parent[i] == i) { return i; } return parent[i] = findParent(parent[i]); } void Union(int u, int v) { int parent_u = findParent(u); int parent_v = findParent(v); if (parent_u == parent_v) return; // small attached to big, since we want to reduce overall size if (size[parent_u] < size[parent_v]) { parent[parent_u] = parent_v; size[parent_v]++; } else { parent[parent_v] = parent_u; size[parent_u]++; } } } // SEGMENT-TREE static class SegmentTree { int[] arr = new int[4 * 100000]; int[] givenArr; // HINT: This can be updated with ques. int build(int index, int l, int r) { if (l == r) { return arr[index] = givenArr[l]; } int mid = (l + r) / 2; return arr[index] = build(2 * index + 1, l, mid) + build(2 * index + 2, mid + 1, r); } SegmentTree(int[] nums) { givenArr = nums; build(0, 0, nums.length - 1); } // HINT: This can be updated with ques. void update(int index, int l, int r, int diff, int i) { if (i >= arr.length) { return; } if (index >= l && index <= r) { arr[i] = arr[i] + diff; } if (index < l || index > r) { return; } int mid = (l + r) / 2; update(index, l, mid, diff, 2 * i + 1); update(index, mid + 1, r, diff, 2 * i + 2); return; } void update(int index, int val) { int diff = val - givenArr[index]; givenArr[index] = val; update(index, 0, givenArr.length - 1, diff, 0); } int query(int left, int right, int l, int r, int i) { // not overlapping if (r < left || l > right) { return 0; } // total - overlapping if (l >= left && r <= right) { return arr[i]; } // partial overlapping int mid = (l + r) / 2; int le = query(left, right, l, mid, 2 * i + 1); int ri = query(left, right, mid + 1, r, 2 * i + 2); return le + ri; } // HINT: for max sum, can be changed according to ques. int query(int l, int r) { return query(l, r, 0, givenArr.length - 1, 0); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
954a2b21a948a6ee3f330d34b11aa3cc
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Reader scan = new Reader(); int tc = scan.nextInt(); for (int i = 0; i < tc; i++){ int n = scan.nextInt(); ArrayList <Long> arr = new ArrayList <Long>(); for (int j = 0; j < n; j++){ long k = scan.nextLong(); arr.add(k); } System.out.println(solve(arr)); } } public static String solve(ArrayList <Long> arr){ Collections.sort(arr, Collections.reverseOrder()); int len = arr.size(); if (len % 2 == 0) len--; len /= 2; long sumRed = arr.get(0); long sumBlue = arr.get(arr.size()-1) + arr.get(arr.size()-2); if (sumRed > sumBlue) return "YES"; //System.out.println("Sum Red: " + sumRed); //System.out.println("Sum Blue: " + sumBlue); int countRed = 1; int countBlue = 2; while (countRed <= len){ //System.out.println("Sum Red: " + sumRed); //System.out.println("Sum Blue: " + sumBlue); if (sumRed > sumBlue) return "YES"; countRed++; countBlue++; sumRed += arr.get(countRed-1); sumBlue += arr.get(arr.size()-countBlue); } return "NO"; } public static long gcd(long a, long b){ if (b == 0) return a; return gcd(b, a % b); } public static boolean isPrime(long n){ if (n == 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long i = 5; i*i <= n; i += 6){ if (n % i == 0 || n % (i+2) == 0) return false; } return true; } public static boolean isPerfectSquare(long x){ long root = (long)Math.sqrt(x); return ((root *root) == x); } public static long modPow(long x, long n){ long mod = 1000000007; long result = 1; while (n > 0){ if (n % 2 != 0) result = (result % mod) * (x % mod) % mod; x *= x % mod; n /= 2; } return result; } public static void printarr(String[]arr){ for (int i = 0; i < arr.length; i++){ System.out.print(arr[i] + " "); } System.out.println(); } public static void printarr(ArrayList <Integer> arr){ for (int i = 0; i < arr.size(); i++){ System.out.print(arr.get(i) + " "); } System.out.println(); } static class Reader { final private int BUFFER_SIZE = 1 << 64; 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[1000000]; // 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
aa2edab595cfeb8fbef3644215215c52
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Map.Entry; public class codeforces { static int mod = 1000000007; public static void main(String[] args) { FastReader sc = new FastReader(); try { StringBuilder ss = new StringBuilder(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long a[] = new long[n]; ArrayList<Long>al = new ArrayList<>(); for(int i = 0 ; i <n;i++) { al.add(sc.nextLong()); } Collections.sort(al); boolean flag = false; long pref[] = new long[n/2+1]; pref[0] = al.get(0); for(int i = 1 ;i <=n/2;i++) { pref[i] = pref[i-1] +al.get(i); } long sum = 0; int index = 1; for(int i = n-1 ; i>n/2 ; i--) { sum+=al.get(i); // System.out.println(sum +" "+pref[index]); if(sum> pref[index]) { flag = true; break; } index++; } if(flag) { ss.append("YES" +"\n"); } else { ss.append("NO" +"\n"); } } System.out.println(ss); } catch(Exception e) { System.out.println(e.getMessage()); } } static long abs(long a) { return Math.abs(a); } static void sort(long a[]) { Arrays.parallelSort(a); } static long pow(long a, long b) { long ans = 1; long temp = a; while(b>0) { if((b&1) == 1) { ans*=temp; } temp = temp*temp; b = b>>1; } return ans; } static long ncr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } static long fact(long n) { long res = 1; for (int i = 2; i <= n; i++) { res = (res * i); } return res; } static long gcd(long a, long b) { if(b == 0) { return a; } return gcd(b , a%b); } static ArrayList<Integer> factor(long n) { ArrayList<Integer> al = new ArrayList<>(); for(int i = 1 ; i*i<=n;i++) { if(n%i == 0) { if(n/i == i) { al.add(i); } else { al.add(i); al.add((int) (n/i)); } } } return al; } static class Pair implements Comparable<Pair>{ int a; int b ; Pair(int a, int b){ this.a = a; this.b = b; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return (int)(this.b - o.b); } } static ArrayList<Integer> sieve(int n) { boolean a[] = new boolean[n+1]; Arrays.fill(a, false); for(int i = 2 ; i*i <=n ; i++) { if(!a[i]) { for(int j = 2*i ; j<=n ; j+=i) { a[j] = true; } } } ArrayList<Integer> al = new ArrayList<>(); for(int i = 2 ; i <=n;i++) { if(!a[i]) { al.add(i); } } return al; } static ArrayList<Long> pf(long n) { ArrayList<Long> al = new ArrayList<>(); while(n%2 == 0) { al.add(2l); n = n/2; } for(long i = 3 ; i*i<=n ; i+=2) { while(n%i == 0) { al.add(i); n = n/i; } } if(n>2) { al.add( n); } return al; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
3cf1a0dcbcbc42db2a6c30528fb88d64
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class B { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine().trim()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { int N = Integer.parseInt(br.readLine().trim()); int arr[] = nextIntArray(N, br); sb.append(solve(arr)).append("\n"); } br.close(); System.out.println(sb); } private static String solve(int arr[]) { boolean canMake = false; int countRed = 0, countBlue = 0; long redSum = 0, blueSum = 0; // Arrays.sort(arr); fastSort(arr); // System.out.println(Arrays.toString(arr)); int left = 0, right = arr.length - 1; while (left < right) { countBlue++; blueSum += arr[left]; left++; if (redSum <= blueSum) { countRed++; redSum += arr[right]; right--; } if (countRed < countBlue && blueSum < redSum) { canMake = true; break; } } if (left == right) { countBlue++; blueSum += arr[left]; left++; if (countRed < countBlue && blueSum < redSum) { canMake = true; } } // System.out.println(countBlue + " " + blueSum + " " + countRed + " " + // redSum); if (canMake) return "YES"; return "NO"; } private static void fastSort(int arr[]) { Integer[] temp = Arrays.stream(arr).boxed().toArray(Integer[]::new); Arrays.sort(temp); for (int i = 0; i < arr.length; i++) arr[i] = temp[i]; } private static int[] nextIntArray(int N, BufferedReader br) throws Exception { StringTokenizer st = new StringTokenizer(br.readLine().trim(), " "); int arr[] = new int[N]; for (int i = 0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
2b78fec45674f91c52970a49bf47ed8a
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Test { final static FastReader fr = new FastReader(); final static PrintWriter out = new PrintWriter(System.out) ; static long mod = (long)1e9 + 7 ; static int[] dp; static void solve(){ int n =fr.nextInt(); ArrayList<Long> al = new ArrayList<>() ; for (int i = 0 ; i < n ; i++) al.add(fr.nextLong()) ; Collections.sort(al); long curr1 = al.get(0)+al.get(1) ; long curr2 = al.get(n-1) ; if (curr1 < curr2) { out.println("YES"); return; } int i = 2 , j = n-2 ; while (i < j){ curr1 += al.get(i++); curr2 += al.get(j--) ; if (curr1 < curr2){ out.println("YES"); return; } } out.println("NO"); } public static void main(String[] args) { int testCases = 1 ; testCases = fr.nextInt() ; while (testCases-- > 0) { solve() ; } out.close() ; } static long getMax(long ... a) { long max = Long.MIN_VALUE ; for (long x : a) max = Math.max(x, max) ; return max ; } static long getMin(long ... a) { long max = Long.MAX_VALUE ; for (long x : a) max = Math.min(x, max) ; return max ; } static long fastPower(double a, long b) { double ans = 1 ; while (b > 0) { if ((b & 1) != 0) ans *= a ; a *= a ; b >>= 1 ; } return (long)(ans + 0.5) ; } static long fastPower(long a, long b, long mod) { long ans = 1 ; while (b > 0) { if ((b&1) != 0) ans = (ans%mod * a%mod) %mod; b >>= 1 ; a = (a%mod * a%mod)%mod ; } return ans ; } static int lower_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key) ; if (pos < 0) { pos = - (pos + 1) ; } return pos ; } static int upper_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key); pos++ ; if (pos < 0) { pos = -(pos) ; } return pos ; } static int upper_bound(int arr[], int key) { int start = 0 , end = arr.length - 1 ; int ans = -1 ; while (start <= end) { int mid = start + ((end - start) >> 1) ; if (arr[mid] == key) ans = mid ; if (arr[mid] <= key) start = mid + 1 ; else end = mid-1 ; } return ans ; } static int lower_bound(int arr[], int key) { int start = 0 , end = arr.length -1; int ans = -1 ; while (start <= end) { int mid = start + ((end - start )>>1) ; if (arr[mid] == key) { ans = mid ; } if (arr[mid] >= key){ end = mid - 1 ; } else start = mid + 1 ; } return ans ; } static class Pair{ long x; long y ; Pair(long x, long y){ this.x = x ; this.y= y ; } } static long gcd(long a, long b) { if (b == 0) return a ; return gcd(b, a%b) ; } static long lcm(long a, long b) { long lcm = a/gcd(a, b)*b ; return lcm ; } static List<Long> seive(int n) { // all are false by default // false -> prime, true -> composite int nums[] = new int[n+1] ; for (int i = 2 ; i <= Math.sqrt(n); i++) { if (nums[i] == 0) { for (int j = i*i ; j <= n ; j += i) { nums[j] = 1 ; } } } long freq[] = new long[1000001] ; freq[2] = 1 ; for (int i = 2 ; i <= n ; i++) { if (nums[i] == 0) freq[i] = freq[i-1]+1 ; else freq[i] = freq[i-1] ; } ArrayList<Long>primes = new ArrayList<>() ; for (int i = 2 ; i <=n ; i++) { if (nums[i] == 0) primes.add(i*1l) ; } return primes ; } static boolean isVowel(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true ; return 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; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
0b0e09b81afc0d7a02302de7332cfc20
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class P1646B { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); for (int i = 0; i < count; i++) { solve(scanner); } } public static void solve(Scanner sc) throws Exception { int n = sc.nextInt(); long[] arr = new long[n]; ArrayList<Long> arrl = new ArrayList<Long>(); for (int i = 0; i < n; i++) { arrl.add(sc.nextLong()); } Collections.sort(arrl); long blueSum = arrl.get(0) + arrl.get(1); long redSum = arrl.get(arrl.size()-1); long redCount = 1; long blueCount = 2; int i = 1; while (redCount + blueCount < n && redCount < blueCount) { if (redSum > blueSum) { System.out.println("YES"); return; } redCount++; redSum += arrl.get(arrl.size()-1 - i); blueCount++; blueSum += arrl.get(1 + i); i++; } if (redSum > blueSum) { System.out.println("YES"); } else { System.out.println("NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
05d11892f27b73e18b258b4e07f5a739
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class d1 { static int n; static int N = (int)1e6 + 14; static int[] cnt = new int[N]; static long[] ps = new long[N]; static boolean poss; static HashSet<Integer> set; static ArrayList<Integer> all; public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st; st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); outer: while(t-->0){ st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); ArrayList<Integer> al = new ArrayList<>(); for(int i = 0;i<n;i++){ al.add(Integer.parseInt(st.nextToken())); } Collections.sort(al); long[] prefixsum = new long[n]; long[] suffixsum = new long[n]; prefixsum[0] = al.get(0); for(int i = 1;i<n;i++){ prefixsum[i] =al.get(i) + prefixsum[i-1]; } suffixsum[n-1] = al.get(n-1); for(int i = n-2;i>=0;i--){ suffixsum[i] = al.get(i)+suffixsum[i+1]; } for(int i = 1;i<n;i++){ if(prefixsum[i] < suffixsum[n-i]){ bw.write("YES\n"); continue outer; } } bw.write("NO\n"); } bw.flush(); } public static boolean check(String s){ HashSet<Character> set = new HashSet<>(); for(char c : s.toCharArray()){ set.add(c); } if(set.size() == 1){ return true; } return false; } public static void subset(ArrayList<Integer> al,int ans,int cur){ if(cur == al.size()){ set.add(ans); return; } subset(al, ans+al.get(cur), 1+cur); subset(al, ans, cur+1); } public static boolean subset1(ArrayList<Integer> al,int cur,int req,int ans){ if(cur == al.size()){ if(set.contains((req-ans))){ return true; } return false; } boolean b1 = subset1(al, 1+cur,req,ans+al.get(cur)); if(b1){ return b1; } boolean b2 = subset1(al, cur+1,req,ans); return b1|b2; } public static int ceil(ArrayList<Integer> al,int k){ int low = 0; int high = al.size()-1; int ans = 0; int max = al.get(al.size()-1); if(k > max){ return Integer.MAX_VALUE; } if(al.size() == 1){ if(k <= max){ return max; } } while(low <= high){ int mid = (low+high)/2; if(al.get(mid) < k){ low = mid+1; } else if(al.get(mid) >= k){ high = mid-1; ans = al.get(mid); } } return ans; } public static void dfs1(ArrayList<ArrayList<Integer>> graph,int cur,boolean[] visited){ visited[cur] = true; // System.out.print(cur+1+" "); all.add(cur+1); for(int i : graph.get(cur)){ if(visited[i] == false){ dfs1(graph,i, visited); // System.out.print(cur+1+" "); all.add(cur+1); } } } public static boolean back(int[] a,int[]b ,int cur,int pos,int n,int k){ if(pos == n){ //System.out.println("yes"); return true; } boolean b1 = false,b2 = false; if(Math.abs(a[pos]-cur) <= k){ b1 = back(a, b, a[pos], pos+1, n, k); if(b1 == true){ return true; } } if(Math.abs(b[pos]-cur) <= k){ b2 = back(a, b, b[pos], pos+1, n, k); if(b2 == true){ return true; } } return false; } public static boolean prime(long p){ for(long i = 2;i*i <= p;i++){ if(p%i == 0){ return false; } } return true; } public static boolean palin(char[] arr,int i,int j){ while(i < j){ if(arr[i] != arr[j]){ return false; } i++; j--; } return true; } public static long gcd(long a,long b){ if(b == 0){ return a; } return gcd(b, a%b); } public static void dfs(int[][] mat,int i,int j,int[][] dist,int cur,int max,boolean[][] visited){ if(i<0 || j<0 || i >= mat.length || j >= mat[0].length || visited[i][j] == true){ return; } visited[i][j] = true; dist[i][j] = Math.min(dist[i][j],cur); dfs(mat,i+1,j,dist,cur+1,max,visited); dfs(mat,i-1,j,dist,cur+1,max,visited); dfs(mat,i,j+1,dist,cur+1,max,visited); dfs(mat,i,j-1,dist,cur+1,max,visited); dfs(mat,i+1,j+1,dist,cur+1,max,visited); dfs(mat,i-1,j-1,dist,cur+1,max,visited); dfs(mat,i+1,j-1,dist,cur+1,max,visited); dfs(mat,i-1,j+1,dist,cur+1,max,visited); } /* public static void bfs(int[][] mat,int i1,int j1,int[][] dist,int max,boolean[][] visited){ Queue<pair> queue = new LinkedList<pair>(); queue.add(new pair(i1,j1,0)); int val = 0; while(!queue.isEmpty()){ int len = queue.size(); // System.out.println(len); for(int s = 0;s<len;s++){ pair p1 = queue.poll(); val = p1.k+1; dist[p1.a][p1.b] = Math.min(dist[p1.a][p1.b],p1.k); visited[p1.a][p1.b] = true; int i = p1.a; int j = p1.b; if(check2(mat, i+1, j, visited)){ queue.add(new pair(i+1, j, val)); } if(check2(mat, i-1, j, visited)){ queue.add(new pair(i-1, j, val)); } if(check2(mat, i, j+1, visited)){ queue.add(new pair(i, j+1, val)); } if(check2(mat, i, j-1, visited)){ queue.add(new pair(i, j-1, val)); } if(check2(mat, i+1, j+1, visited)){ queue.add(new pair(i+1, j+1, val)); } if(check2(mat, i-1, j-1, visited)){ queue.add(new pair(i-1, j-1, val)); } if(check2(mat, i+1, j-1, visited)){ queue.add(new pair(i+1, j-1, val)); } if(check2(mat, i-1, j+1, visited)){ queue.add(new pair(i-1, j+1, val)); } } val++; } }*/ public static boolean check2(int[][] mat,int i,int j,boolean[][] visited){ if(i<0 || j<0 || i >= mat.length || j >= mat[0].length || visited[i][j] == true){ return false; } visited[i][j] = true; return true; } static class pair{ int a;int b; pair(int a,int b){ this.a= a; this.b = b; } } public static boolean check1(String s){ if(s.length() == 0){ return false; } for(int i = 0;i<s.length();i++){ if(s.charAt(i) >= 'a' && s.charAt(i) <= 'z' || s.charAt(i) >= 'A' && s.charAt(i) <= 'Z' || s.charAt(i) == '.'){ return false; } } if(s.contains("0")){ if(s.indexOf("0") == 0 && s.length() != 1){ return false; } } return true; } public static boolean check(ArrayList<Integer> al,int n){ int curlen = 2; int sum = n; for(int i = al.size()-1;i>=0;i--){ sum += al.get(i); if(sum%curlen == 0){ return false; } curlen++; } return true; } public static boolean evenbits(int n){ int count = 0; while(n!=0){ if(n%2 != 0){ count++; } n /= 2; } return (count%2 == 0)?true:false; } public static long calc(long oddc,long evenc){ long ans = 0L; ans = (oddc)*(oddc-1)/2; ans *= evenc; ans += evenc*(evenc-1)*(evenc-2)/6L; return ans; } public static long fastpow(long a,long b,long m){ long res = 1L; while(b>0){ if(b%2 == 1L){ res = (res*a)%m; } b /= 2; a = (a*a)%m; } return res; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
e52f8f410b3dda7275a9271e7f4b93d0
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class RedvsBlue { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int[] arr= new int[n]; for(int i = 0; i < n; i++){ arr[i] = s.nextInt(); } arr=Arrays.stream(arr).boxed().sorted().mapToInt(p -> p).toArray(); if (n % 2 == 0) { long Blue = 0; long Red = 0; for(int i = 0; i < n / 2; i++) { Blue += arr[i]; } for(int i = n / 2 + 1; i < n; i++) { Red += arr[i]; } if (Red > Blue) { System.out.println("yes"); } else { System.out.println("no"); } } else { long Blue = 0; long Red = 0; for(int i = 0; i <= n / 2; i++) { Blue += arr[i]; } for(int i = (int) (n / 2) + 1; i < n; i++) { Red += arr[i]; } if (Red > Blue) { System.out.println("yes"); } else { System.out.println("no"); } } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
8c7c3a3de08fe7e8ad8d008c12af42b3
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.StringTokenizer; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.lang.reflect.Array; import java.io.IOException; import java.io.BufferedReader; import java.io.BufferedWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class p2 { BufferedReader br; StringTokenizer st; BufferedWriter bw; public static void main(String[] args)throws Exception { new p2().run(); } void run()throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); bw=new BufferedWriter(new OutputStreamWriter(System.out)); solve(); } void solve() throws IOException { short t=ns(); while(t-->0) { int n=ni(); Integer a[]=nai(n); Arrays.sort(a); if(s(a)) bw.write("YES\n"); else bw.write("NO\n"); } bw.flush(); } private boolean s(Integer[] a) { int n=a.length; long sumr=0,sumb=a[0]; int r=n-1, b=1; while(b<r) { sumr+=a[r--]; sumb+=a[b++]; if(sumr>sumb) return true; } return false; } public int gcd(int a, int b) { if(a==0) return b; else return gcd(b%a,a); } Integer[] nai(int n) { Integer a[]=new Integer[n]; for(int i=-1;++i<n;)a[i]=ni(); return a;} long[] nal(int n) { long a[]=new long[n]; for(int i=-1;++i<n;)a[i]=nl(); return a;} char[] nac() {char c[]=nextLine().toCharArray(); return c;} char [][] nmc(int n) {char c[][]=new char[n][]; for(int i=-1;++i<n;)c[i]=nac(); return c;} String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } byte nb() { return Byte.parseByte(next()); } short ns() { return Short.parseShort(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public int[] primeNO(long limit) { int size=(int)Math.sqrt(limit)+1; int size1=size/2; boolean composite[]=new boolean[size1]; int zz=(int)Math.sqrt(size-1); for(int i=3;i<=zz;) { for(int j=(i*i)/2;j<size1;j+=i) composite[j]=true; for(i+=2;composite[i/2];i+=2); } int prime[]=new int[3401]; prime[0]=2; int p=1; for(int i=1;i<size1;i++) { if(!composite[i]) prime[p++]=2*i+1; } //////////////////////////////////////////////////////////////////////////////////////////////////////// // System.out.println(p); //////////////////////////////////////////////////////////////////////////////////////////////////////// prime=Arrays.copyOf(prime, p); return prime; } public static class queue { public static class node { node next; int val; public node(int val) { this.val=val; } } node head,tail; public void add(int val) { node a=new node(val); if(head==null) { head=tail=a; return; } tail.next=a; tail=a; } public int remove() { int a=head.val; head=head.next; if(head==null) tail=null; return a; } } public static class stack { public static class node { node next; int val; public node(int val) { this.val=val; } } node head; public void add(int val) { node a=new node(val); a.next=head; head=a; } public int remove() { int a=head.val; head=head.next; return a; } } public static class data { int a,b; public data(int a, int b) { this.a=a; this.b=b; } } public data[] dataArray(int n) { data d[]=new data[n]; for(int i=-1;++i<n;) d[i]=new data(ni(), ni()); return d; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
0481872ffc8d2308199e400a2d4c21c1
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) { Scanner in = new Scanner(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int t = 0; t < T; t++) { int n = in.nextInt(); List<Integer> a = new ArrayList<>(n); for (int i = 0; i < n; i++) { a.add(in.nextInt()); } Collections.sort(a); long b = 0; long r = 0; int bi = 0; int ri = n - 1; while (bi <= ri) { if (b >= r) { r += a.get(ri); ri--; } else if (bi <= n - 1 - ri) { b += a.get(bi); bi++; } else { break; } } if (b < r && bi > n - 1 - ri) { out.println("YES"); } else { out.println("NO"); } } out.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
7448a843298e6da1d705c07655afcb81
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int t = 0; t < T; t++) { int n = in.nextInt(); List<Integer> a = new ArrayList<>(n); for (int i = 0; i < n; i++) { a.add(in.nextInt()); } Collections.sort(a); long b = 0; long r = 0; int bi = 0; int ri = a.size() - 1; while (bi <= ri) { if (b >= r) { r += a.get(ri); ri--; } else if (bi <= a.size() - 1 - ri) { b += a.get(bi); bi++; } else { break; } } if (b < r && bi > a.size() - 1 - ri) { out.println("YES"); } else { out.println("NO"); } } out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 1 << 15); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
a342eac7c4591ac68b87aa3fa02925dc
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Rough { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t=s.nextInt(); while(t-->0) { int a=s.nextInt(); Long[] ar=new Long[a]; for(int i=0;i<a;++i) { ar[i]=s.nextLong(); } Arrays.sort(ar); boolean doer=false; long sumf=ar[0]+ar[1]; long sumb=ar[a-1]; if(sumf<sumb) { pw.println("YES"); continue; } int k=2; int l=a-2; while(k<l){ sumf+=ar[k]; sumb+=ar[l]; if(sumf<sumb) { doer=true; break; } k++; l--; } if(doer)pw.println("YES"); else pw.println("NO"); } pw.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
cb7084ae9e1dfc38f4705e1605be3602
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class practice { public static void main(String[] args) { Scanner scan = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int t = scan.nextInt(); while (t --> 0) { int n = scan.nextInt(); Integer arr[] = new Integer[n]; for (int i = 0; i < n; i++) arr[i] = scan.nextInt(); Arrays.sort(arr); int i = 2; int j = n - 2; long sum1 = arr[0] + arr[1]; long sum2 = arr[n - 1]; while (i < j) { if (sum1 < sum2) break; else { sum1 += arr[i++]; sum2 += arr[j--]; } } sb.append((sum1 < sum2 ? "Yes" : "No") + "\n"); } System.out.println(sb.toString().trim()); scan.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
62d30f7ab688af5736778522331f5607
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class HelloWorld { static long mod = 1000000007; static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); int t = sc.nextInt(); while( t-- > 0) { int n=sc.nextInt(); int[]arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } mysort(arr); int i=2; int j=arr.length-2; boolean found=false; long countB=2; long sumB=arr[0]+arr[1]; long sumR=arr[arr.length-1]; long countR=1; if(countB>countR&& sumR>sumB){ out.println("YES"); continue; } while(i<=j){ if(sumR>sumB){ sumB+=arr[i]; countB++; i++; }else{ sumR+=arr[j]; countR++; j--; } if(countB>countR&& sumR>sumB){ found=true; break; } } if(found){ out.println("Yes"); }else{ out.println("No"); } } out.flush(); } /* * WARNING -> DONT EVER USE ARRAYS.SORT() IN ANY WAY. * A B C are easy just dont give up , you can do it! * FIRST AND VERY IMP -> READ AND UNDERSTAND THE QUESTION VERY CAREFULLY. * WARNING -> DONT CODE BULLSHIT , ALWAYS CHECK THE LOGIC ON MULTIPLE TESTCASES AND EDGECASES BEFORE. * SECOND -> TRY TO FIND RELEVENT PATTERN SMARTLY. * WARNING -> IF YOU THINK YOUR SOLUION IS JUST DUMB DONT SUBMIT IT BEFORE RECHECKING ON YOUR END. */ public static boolean ifpowof2(long n ) { return ((n&(n-1)) == 0); } static boolean isprime(long x ) { if( x== 2) { return true; } if( x%2 == 0) { return false; } for( long i = 3 ;i*i <= x ;i+=2) { if( x%i == 0) { return false; } } return true; } static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int)n + 1]; for (int i = 0; i <= n; i++) { prime[i] = true; } for (long p = 2; p * p <= n; p++) { if (prime[(int)p] == true) { for (long i = p * p; i <= n; i += p) prime[(int)i] = false; } } return prime; } public static int[] nextLargerElement(int[] arr, int n) { Stack<Integer> stack = new Stack<>(); int rtrn[] = new int[n]; rtrn[n-1] = -1; stack.push( n-1); for( int i = n-2 ;i >= 0 ; i--){ int temp = arr[i]; int lol = -1; while( !stack.isEmpty() && arr[stack.peek()] <= temp){ if(arr[stack.peek()] == temp ) { lol = stack.peek(); } stack.pop(); } if( stack.isEmpty()){ if( lol != -1) { rtrn[i] = lol; } else { rtrn[i] = -1; } } else{ rtrn[i] = stack.peek(); } stack.push( i); } return rtrn; } static void mysort(int[] arr) { for(int i=0;i<arr.length;i++) { int rand = (int) (Math.random() * arr.length); int loc = arr[rand]; arr[rand] = arr[i]; arr[i] = loc; } Arrays.sort(arr); } static void mySort(long[] arr) { for(int i=0;i<arr.length;i++) { int rand = (int) (Math.random() * arr.length); long loc = arr[rand]; arr[rand] = arr[i]; arr[i] = loc; } Arrays.sort(arr); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long rightmostsetbit(long n) { return n&-n; } static long leftmostsetbit(long n) { long k = (long)(Math.log(n) / Math.log(2)); return k; } static HashMap<Long,Long> primefactor( long n){ HashMap<Long ,Long> hm = new HashMap<>(); long temp = 0; while( n%2 == 0) { temp++; n/=2; } if( temp!= 0) { hm.put( 2L, temp); } long c = (long)Math.sqrt(n); for( long i = 3 ; i <= c ; i+=2) { temp = 0; while( n% i == 0) { temp++; n/=i; } if( temp!= 0) { hm.put( i, temp); } } if( n!= 1) { hm.put( n , 1L); } return hm; } static ArrayList<Integer> allfactors(int abs) { HashMap<Integer,Integer> hm = new HashMap<>(); ArrayList<Integer> rtrn = new ArrayList<>(); for( int i = 2 ;i*i <= abs; i++) { if( abs% i == 0) { hm.put( i , 0); hm.put(abs/i, 0); } } for( int x : hm.keySet()) { rtrn.add(x); } if( abs != 0) { rtrn.add(abs); } return rtrn; } public static int[][] prefixsum( int n , int m , int arr[][] ){ int prefixsum[][] = new int[n+1][m+1]; for( int i = 1 ;i <= n ;i++) { for( int j = 1 ; j<= m ; j++) { int toadd = 0; if( arr[i-1][j-1] == 1) { toadd = 1; } prefixsum[i][j] = toadd + prefixsum[i][j-1] + prefixsum[i-1][j] - prefixsum[i-1][j-1]; } } return prefixsum; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
2c15cd69541639b4da52001de1329d6d
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
//some updates in import stuff import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class Main{ static int mod = (int) (Math.pow(10, 9)+7); static final int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 }; static final int[] dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 }; static final int[] dx9 = { -1, -1, -1, 0, 0, 0, 1, 1, 1 }, dy9 = { -1, 0, 1, -1, 0, 1, -1, 0, 1 }; static final double eps = 1e-10; static List<Integer> primeNumbers = new ArrayList<>(); public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); //code below int test = sc.nextInt(); while(test --> 0){ int n = sc.nextInt(); long[] arr = new long[n]; long sum = 0; for(int i= 0; i < n; i++){ arr[i] = sc.nextLong(); //simple logic sum += arr[i]; } sort(arr); //sorting them (sorting according to some accordance bois) //i have no idea why i am not able to solve this question int l = 1; int r = n-2; long lSum = arr[0]; long rSum = arr[n-1]; int lCount = 1; int rCount = 1; boolean flag = false; while(l < n && r >= 0){ if(lSum >= rSum){ rSum += arr[r]; rCount++; r--; }else{ lSum += arr[l]; l++; lCount++; } if(rSum > lSum && rCount < lCount){ flag = true; break; } } System.out.println(flag ? "YES" : "NO"); } out.close(); } //Updation Required //Fenwick Tree (customisable) //Segment Tree (customisable) //-----CURRENTLY PRESENT-------// //Graph //DSU //powerMODe //power //Segment Tree (work on this one) //Prime Sieve //Count Divisors //Next Permutation //Get NCR //isVowel //Sort (int) //Sort (long) //Binomial Coefficient //Pair //Triplet //lcm (int & long) //gcd (int & long) //gcd (for binomial coefficient) //swap (int & char) //reverse //primeExponentCounts //Fast input and output //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //GRAPH (basic structure) public static class Graph{ public int V; public ArrayList<ArrayList<Integer>> edges; //2 -> [0,1,2] (current) Graph(int V){ this.V = V; edges = new ArrayList<>(V+1); for(int i= 0; i <= V; i++){ edges.add(new ArrayList<>()); } } public void addEdge(int from , int to){ edges.get(from).add(to); edges.get(to).add(from); } } //DSU (path and rank optimised) public static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; Arrays.fill(rank, 1); Arrays.fill(parent,-1); this.n = n; } public int find(int curr){ if(parent[curr] == -1) return curr; //path compression optimisation return parent[curr] = find(parent[curr]); } public void union(int a, int b){ int s1 = find(a); int s2 = find(b); if(s1 != s2){ if(rank[s1] < rank[s2]){ parent[s1] = s2; rank[s2] += rank[s1]; }else{ parent[s2] = s1; rank[s1] += rank[s2]; } } } } //with mod public static long powerMOD(long x, long y) { long res = 1L; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0){ x %= mod; res %= mod; res = (res * x)%mod; } // y must be even now y = y >> 1; // y = y/2 x%= mod; x = (x * x)%mod; // Change x to x^2 } return res%mod; } //without mod public static long power(long x, long y) { long res = 1L; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0){ res = (res * x); } // y must be even now y = y >> 1; // y = y/ x = (x * x); } return res; } public static class segmentTree{ public long[] arr; public long[] tree; public long[] lazy; segmentTree(long[] array){ int n = array.length; arr = new long[n]; for(int i= 0; i < n; i++) arr[i] = array[i]; tree = new long[4*n + 1]; lazy = new long[4*n + 1]; } public void build(int[]arr, int s, int e, int[] tree, int index){ if(s == e){ tree[index] = arr[s]; return; } //otherwise divide in two parts and fill both sides simply int mid = (s+e)/2; build(arr, s, mid, tree, 2*index); build(arr, mid+1, e, tree, 2*index+1); //who will build the current position dude tree[index] = Math.min(tree[2*index], tree[2*index+1]); } public int query(int sr, int er, int sc, int ec, int index, int[] tree){ if(lazy[index] != 0){ tree[index] += lazy[index]; if(sc != ec){ lazy[2*index+1] += lazy[index]; lazy[2*index] += lazy[index]; } lazy[index] = 0; } //no overlap if(sr > ec || sc > er) return Integer.MAX_VALUE; //found the index baby if(sr <= sc && ec <= er) return tree[index]; //finding the index on both sides hehehehhe int mid = (sc + ec)/2; int left = query(sr, er, sc, mid, 2*index, tree); int right = query(sr, er, mid+1, ec, 2*index + 1, tree); return Integer.min(left, right); } //now we will do point update implementation //it should be simple then we expected for sure public void update(int index, int indexr, int increment, int[] tree, int s, int e){ if(lazy[index] != 0){ tree[index] += lazy[index]; if(s != e){ lazy[2*index+1] = lazy[index]; lazy[2*index] = lazy[index]; } lazy[index] = 0; } //no overlap if(indexr < s || indexr > e) return; //found the required index if(s == e){ tree[index] += increment; return; } //search for the index on both sides int mid = (s+e)/2; update(2*index, indexr, increment, tree, s, mid); update(2*index+1, indexr, increment, tree, mid+1, e); //now update the current range simply tree[index] = Math.min(tree[2*index+1], tree[2*index]); } public void rangeUpdate(int[] tree , int index, int s, int e, int sr, int er, int increment){ //if not at all in the same range if(e < sr || er < s) return; //complete then also move forward if(s == e){ tree[index] += increment; return; } //otherwise move in both subparts int mid = (s+e)/2; rangeUpdate(tree, 2*index, s, mid, sr, er, increment); rangeUpdate(tree, 2*index + 1, mid+1, e, sr, er, increment); //update current range too na //i always forget this step for some reasons hehehe, idiot tree[index] = Math.min(tree[2*index], tree[2*index + 1]); } public void rangeUpdateLazy(int[] tree, int index, int s, int e, int sr, int er, int increment){ //update lazy values //resolve lazy value before going down if(lazy[index] != 0){ tree[index] += lazy[index]; if(s != e){ lazy[2*index+1] += lazy[index]; lazy[2*index] += lazy[index]; } lazy[index] = 0; } //no overlap case if(sr > e || s > er) return; //complete overlap if(sr <= s && er >= e){ tree[index] += increment; if(s != e){ lazy[2*index+1] += increment; lazy[2*index] += increment; } return; } //otherwise go on both left and right side and do your shit int mid = (s + e)/2; rangeUpdateLazy(tree, 2*index, s, mid, sr, er, increment); rangeUpdateLazy(tree, 2*index + 1, mid+1, e, sr, er, increment); tree[index] = Math.min(tree[2*index+1], tree[2*index]); return; } } //prime sieve public static void primeSieve(int n){ BitSet bitset = new BitSet(n+1); for(long i = 0; i < n ; i++){ if (i == 0 || i == 1) { bitset.set((int) i); continue; } if(bitset.get((int) i)) continue; primeNumbers.add((int)i); for(long j = i; j <= n ; j+= i) bitset.set((int)j); } } //number of divisors public static int countDivisors(long number){ if(number == 1) return 1; List<Integer> primeFactors = new ArrayList<>(); int index = 0; long curr = primeNumbers.get(index); while(curr * curr <= number){ while(number % curr == 0){ number = number/curr; primeFactors.add((int) curr); } index++; curr = primeNumbers.get(index); } if(number != 1) primeFactors.add((int) number); int current = primeFactors.get(0); int totalDivisors = 1; int currentCount = 2; for (int i = 1; i < primeFactors.size(); i++) { if (primeFactors.get(i) == current) { currentCount++; } else { totalDivisors *= currentCount; currentCount = 2; current = primeFactors.get(i); } } totalDivisors *= currentCount; return totalDivisors; } //primeExponentCounts public static int primeExponentsCount(int n) { if (n <= 1) return 0; int sqrt = (int) Math.sqrt(n); int remainingNumber = n; int result = 0; for (int i = 2; i <= sqrt; i++) { while (remainingNumber % i == 0) { result++; remainingNumber /= i; } } //in case of prime numbers this would happen if (remainingNumber > 1) { result++; } return result; } //now adding next permutation function to java hehe public static boolean next_permutation(int[] p) { for (int a = p.length - 2; a >= 0; --a) if (p[a] < p[a + 1]) for (int b = p.length - 1;; --b) if (p[b] > p[a]) { int t = p[a]; p[a] = p[b]; p[b] = t; for (++a, b = p.length - 1; a < b; ++a, --b) { t = p[a]; p[a] = p[b]; p[b] = t; } return true; } return false; } //finding the value of NCR in O(RlogN) time and O(1) space public static long getNcR(int n, int r) { long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r > 0) { p *= n; k *= r; long m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else { p = 1; } return p; } //is vowel function public static boolean isVowel(char c) { return (c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U'); } //to sort the array with better method 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); } //sort long public 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); } //for calculating binomialCoeff public static int binomialCoeff(int n, int k) { int C[] = new int[k + 1]; // nC0 is 1 C[0] = 1; for (int i = 1; i <= n; i++) { // Compute next row of pascal // triangle using the previous row for (int j = Math.min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1]; } return C[k]; } //Pair with int int public static class Pair{ public int a; public int b; Pair(int a , int b){ this.a = a; this.b = b; } @Override public String toString(){ return a + " -> " + b; } } //Triplet with int int int public static class Triplet{ public int a; public int b; public int c; Triplet(int a , int b, int c){ this.a = a; this.b = b; this.c = c; } @Override public String toString(){ return a + " -> " + b; } } //Shortcut function public static long lcm(long a , long b){ return a * (b/gcd(a,b)); } //let's make one for calculating lcm basically public static int lcm(int a , int b){ return (a * b)/gcd(a,b); } //int version for gcd public static int gcd(int a, int b){ if(b == 0) return a; return gcd(b , a%b); } //long version for gcd public static long gcd(long a, long b){ if(b == 0) return a; return gcd(b , a%b); } //for ncr calculator(ignore this code) public static long __gcd(long n1, long n2) { long gcd = 1; for (int i = 1; i <= n1 && i <= n2; ++i) { // Checks if i is factor of both integers if (n1 % i == 0 && n2 % i == 0) { gcd = i; } } return gcd; } //swapping two elements in an array public static void swap(int[] arr, int left , int right){ int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; } //for char array public static void swap(char[] arr, int left , int right){ char temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; } //reversing an array public static void reverse(int[] arr){ int left = 0; int right = arr.length-1; while(left <= right){ swap(arr, left,right); left++; right--; } } public static long expo(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) == 1L) res = (res * a) % mod; //think about this one for a second a = (a * a) % mod; b = b >> 1; } return res; } //SOME EXTRA DOPE FUNCTIONS public static long mminvprime(long a, long b) { return expo(a, b - 2, b); } public static long mod_add(long a, long b, long m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; } public static long mod_sub(long a, long b, long m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; } public static long mod_mul(long a, long b, long m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; } public static long mod_div(long a, long b, long m) { a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m; } //O(n) every single time remember that public static long nCr(long N, long K , long mod){ long upper = 1L; long lower = 1L; long lowerr = 1L; for(long i = 1; i <= N; i++){ upper = mod_mul(upper, i, mod); } for(long i = 1; i <= K; i++){ lower = mod_mul(lower, i, mod); } for(long i = 1; i <= (N - K); i++){ lowerr = mod_mul(lowerr, i, mod); } // out.println(upper + " " + lower + " " + lowerr); long answer = mod_mul(lower, lowerr, mod); answer = mod_div(upper, answer, mod); return answer; } // long[] fact = new long[2 * n + 1]; // long[] ifact = new long[2 * n + 1]; // fact[0] = 1; // ifact[0] = 1; // for (long i = 1; i <= 2 * n; i++) // { // fact[(int)i] = mod_mul(fact[(int)i - 1], i, mod); // ifact[(int)i] = mminvprime(fact[(int)i], mod); // } //ifact is basically inverse factorial in here!!!!!(imp) public static long combination(long n, long r, long m, long[] fact, long[] ifact) { long val1 = fact[(int)n]; long val2 = ifact[(int)(n - r)]; long val3 = ifact[(int)r]; return (((val1 * val2) % m) * val3) % m; } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
b60dbf4631d54706aea3198c9fda169b
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static int mod = 1000000007; static void read(int arr[], int start, int end, FastReader in) { for (int i = start; i < end; i++) { arr[i] = in.nextInt(); } } static int sumArr(int arr[]) { int sum = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i]; } return sum; } static final int MAX = 10000000; static int prefix[] = new int[MAX + 1]; static void buildPrefix() { // Create a boolean array "prime[0..n]". A // value in prime[i] will finally be false // if i is Not a prime, else true. boolean prime[] = new boolean[MAX + 1]; Arrays.fill(prime, true); for (int p = 2; p * p <= MAX; 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 * 2; i <= MAX; i += p) { prime[i] = false; } } } // Build prefix array prefix[0] = prefix[1] = 0; for (int p = 2; p <= MAX; p++) { prefix[p] = prefix[p - 1]; if (prime[p]) { prefix[p]++; } } } static int query(int L, int R) { return prefix[R] - prefix[L - 1]; } static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } static Long gcd(Long a, Long b) { if (b == 0) { return a; } return gcd(b, a % b); } static int min(int arr[]) { int min = Integer.MAX_VALUE; for (int i = 0; i < arr.length; i++) { min = Math.min(min, arr[i]); } return min; } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<>(); 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); } } static int max(int arr[]) { int max = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) { max = Math.max(max, arr[i]); } return max; } static int max(int a, int b) { return Math.max(a, b); } static long max(long a, long b){ return (a>b)?a:b; } static int min(int a, int b) { return Math.min(a, b); } public static boolean isPrime(long n) { if (n < 2) { return false; } if (n == 2 || n == 3) { return true; } if (n % 2 == 0 || n % 3 == 0) { return false; } long sqrtN = (long) Math.sqrt(n) + 1; for (long i = 6L; i <= sqrtN; i += 6) { if (n % (i - 1) == 0 || n % (i + 1) == 0) { return false; } } return true; } static class Pair { int first; int second; Pair(int f, int s) { first = f; second = s; } @Override public String toString() { return "first: " + first + " second: " + second; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !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()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } void read(int arr[]) { for (int i = 0; i < arr.length; i++) { arr[i] = nextInt(); } } void read(long arr[]) { for (int i = 0; i < arr.length; i++) { arr[i] = nextLong(); } } void read(char arr[][]){ for(int i=0;i<arr.length;i++){ String s=next(); for(int j=0;j<s.length();j++) arr[i][j]=s.charAt(j); } } void read(Pair arr[]) { for (int i = 0; i < arr.length; i++) { int x = nextInt(); int y = nextInt(); arr[i] = new Pair(x, y); } } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void printarr(int arr[]) throws IOException { println(Arrays.toString(arr)); } public void print(Object object) throws IOException { bw.append("" + object); } public void close() throws IOException { bw.close(); } } public static int count(String s, char c) { int count = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == c) { count++; } } return count; } public static int stoi(String s) { return Integer.parseInt(s); } public static String itos(int n) { return Integer.toString(n); } public static int ctoi(char c) { return (int) c - 48; } public static long countSetBits(long n) { long count = 0; while (n != 0) { count += (n & 1); // check last bit n >>= 1; } return count; } static long MOD = (long) (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 countBits(long number) { return (long) (Math.log(number) / Math.log(2) + 1); } static boolean isPowerOfTwo(long n) { if (n == 0) { return false; } while (n != 1) { if (n % 2 != 0) { return false; } n = n / 2; } return true; } public static int LCS(String s1, String s2){ int l1=s1.length(); int l2=s2.length(); int dp[][]=new int[l1+1][l2+1]; for(int i=0;i<=l1;i++){ for(int j=0;j<=l2;j++){ if(i==0 || j==0) dp[i][j]=0; else{ if(s1.charAt(i-1)==s2.charAt(j-1)) dp[i][j]=1+dp[i-1][j-1]; else dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]); } } } // for(var v:dp) // System.out.println(Arrays.toString(v)); return dp[l1][l2]; } public static String LCSstring(String s1, String s2){ int l1=s1.length(); int l2=s2.length(); int dp[][]=new int[l1+1][l2+1]; for(int i=0;i<=l1;i++){ for(int j=0;j<=l2;j++){ if(i==0 || j==0) dp[i][j]=0; else{ if(s1.charAt(i-1)==s2.charAt(j-1)) dp[i][j]=1+dp[i-1][j-1]; else dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]); } } } String ans=""; int i=l1,j=l2; while(i>0 && j>0){ if(s1.charAt(i-1)==s2.charAt(j-1)){ ans=s1.charAt(i-1)+ans; i--; j--; } else if(dp[i-1][j]>dp[i][j-1]){ i--; } else j--; } return ans; } public static int factorial(int n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } public static int nCr(int n, int r,int a) { return factorial(n) / (factorial(r) * factorial(n - r)); } public static boolean[] sieve() { int n=10000000; // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. 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; } } return prime; } static int maxSubArraySum(int a[]) { int size = a.length; int max_so_far = Integer.MIN_VALUE, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } public static int calc(int arr[],int n){ if(n<0 || n<arr[0]) return 0; if(n>=arr[2]) return max(max(1+calc(arr,n-arr[2]),1+calc(arr,n-arr[1])),1+calc(arr,n-arr[0])); else if(n>=arr[1]) return max(1+calc(arr,n-arr[1]),1+calc(arr,n-arr[0])); else if(n>=arr[0]) return 1+calc(arr,n-arr[0]); else return 0; } static int dp[]; public static int calc(int n, int org){ if(n==org) return 0; else if(n>org) return 99999; if(dp[n]!=-1) return dp[n]; return dp[n]=Math.min(1+calc(n+1,org) , 1+calc(2*n,org)); } public static int minOperation(int n) { dp=new int[n+1]; for(int i=0;i<=n;i++) dp[i]=-1; int ans=calc(1,n); return ans+1; } static int nCr(int n, int r) { int mod=1000000007; if(r>n) return 0; int dp[][]=new int[n+1][n+1]; dp[0][0]=1; for(int i=1;i<=n;i++){ for(int j=0;j<=i;j++){ if(j==0 || j==i) dp[i][j]=1; else dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%mod; } } return dp[n][r]; } public static int calc(String s1, String s2){ int arr1[]=new int[26]; int arr2[]=new int[26]; for(char c:s1.toCharArray()) arr1[c-'a']++; for(char c:s2.toCharArray()) arr2[c-'a']++; int sum=0; for(int i=0;i<26;i++) sum+=((arr2[i]-arr1[i])>0)?(arr2[i]-arr1[i]):0; return sum; } // static int equalPartition(int n, int arr[]) // { // int sum=0; // for(int i=0;i<n;i++) // sum+=arr[i]; // if(sum%2 != 0) // return 0; // int wt=sum/2; // boolean dp[][]=new boolean[n+1][wt+1]; // for(int i=0;i<=n;i++){ // for(int j=0;j<=wt;j++){ // if(j==0) // dp[i][j]=true; // else if(i==0) // dp[i][j]=false; // else{ // if(j>=arr[i-1]) // dp[i][j]=(dp[i][j-arr[i-1]] || dp[i-1][j]); // else // dp[i][j]=dp[i-1][j]; // } // } // } // System.out.println(wt+"--"+sum+"--"+n); // for(var v:dp) // System.out.println(Arrays.toString(v)); // System.out.println(dp[n][wt]); // return dp[n][wt]?1:0; // } public static boolean isSorted(int arr[]){ int sor[]=new int[arr.length]; for(int i=0;i<arr.length;i++) sor[i]=arr[i]; sort(sor); boolean check=true; for(int i=0;i<arr.length;i++){ if(sor[i]!=arr[i]){ check=false; break; } } return check; } public static int find(int arr[], int n){ for(int i=0;i<arr.length;i++) if(arr[i]==n) return i; return -1; } public static long calc(long n,long m, long mid,long k){ long ans=0; for(int i=1;i<=n;i++) ans+=Math.min(mid/i,m); return ans; } public static boolean check(int arr[],int k){ int count=0; for(int i=0;i<arr.length;i++) if(arr[i]%(i+1) == 0) count++; return count==k; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int limit=1000000; public static boolean same(String s){ boolean check=true; for(int i=1;i<s.length();i++){ if(s.charAt(i)!=s.charAt(i-1)){ check=false; break; } } return check; } public static void solve(FastReader in,FastWriter out){ try{ int n=in.nextInt(); int arr[]=new int[n]; in.read(arr); sort(arr); long s1=arr[0]; long s2=0; int l=1,r=n-1; boolean found=false; while(l<r){ s1+=arr[l++]; s2+=arr[r--]; if(s1<s2){ found=true; break; } } if(found) out.println("YES"); else out.println("NO"); } catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); int tc=1; tc=in.nextInt(); while(tc-- != 0){ solve(in,out); } out.close(); } catch (Exception e) { e.printStackTrace(); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
747acacb7d0c0fe87282b0c4debdd69e
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Main { 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 void main(String[] args) { Scanner var = new Scanner(System.in); int T = var.nextInt(); for(int tests = 1; tests <= T; tests ++){ int n = var.nextInt(); int[] a = new int[n + 1]; for(int i = 1; i <= n; i ++) { a[i] = var.nextInt(); } if(n <= 2){ System.out.println("NO"); } else{ sort(a); int pos1 = 3, pos2 = n-1, cnt1 =2 , cnt2 = 1; long sum1 = a[1] + a[2], sum2 = a[n]; while(pos1 <= pos2){ if(sum1 < sum2) break; else{ if(cnt1 > cnt2 + 1){ sum2 += a[pos2]; pos2--; cnt2 ++; } else{ cnt1 ++; sum1 += a[pos1]; pos1 ++; } } } if(sum1 >= sum2) System.out.println("NO"); else System.out.println("YES"); } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
1157c0c12f54a8f7ba95219f5dd97f53
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
// No sorcery shall prevail. // import java.util.*; import java.io.*; public class _InVoker_ { //Variables static long mod = 1000000007; static long mod2 = 998244353; static FastReader inp= new FastReader(); static PrintWriter out= new PrintWriter(System.out); public static void main(String args[]) { _InVoker_ g=new _InVoker_(); g.main(); out.close(); } ArrayList<Integer> list[]; //Main void main() { int t=inp.nextInt(); loop: while(t-->0) { int n=inp.nextInt(); long a[]=new long[n]; input(a,n); long sumb=0; sort(a); long sumr=a[0]; for(int i=1;i<n;i++) { if(i>=n-i) break; sumr+=a[i]; sumb+=a[n-i]; if(sumr<sumb) { out.println("YES"); continue loop; } } out.println("NO"); } } /********************************************************************************************************************************************************************************************************* * ti;. .:,:i: :,;;itt;. fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE :,:. f::::. .,ijLGDDDDDDDEEEEEEE* *ti;. .:,:i: .:,;itt;: GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG. .::. f:,...,ijLGDDDDDDDDEEEEEE * *ti;. .:,:i: :,;;iti, :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG .::. .f,::,ijLGDDDDDDDDEEEEEE * *ti;. .:,:i: .,,;iti;. LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj .::. .:L;;ijfGDDDDDDDDDEEEEE * *ti;. .:,:i: .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL .::. .:;LijLGGDDDDDDDDEEEEE * *ti;. .:,:;: :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj .::. :,;jffGGDDDDDDDDDEEEE * *ti;. .:,:i: .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL .::. .:;itDGGDDDDDDDDDEEEE * *ti;. .:::;: :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf .::. :,itfGEDDDDDDDDDDDEE * *ti;. .:::;: :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG .::. .,;jfLGKDLDDDDDDEEDD * *ti;. .:::;: fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::. .,;tfLGDEDDDDDDDDEEE * *ti;. :::;: fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::. .,;tfLGDDDKDDDDDDDDD * *ti;. .::;: fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:. .,;tfLGGDDDKDDDDDDDD * *ti;. .:.;: tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::. .,;tfLGGDDDDEDDDDDDD * *ti;. .::;: fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::. .,;tfLGGDDDDDDEDDDDD * *ti;. .:.;: tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::. .,;tfLGGDDDDDDDEDDDD * *ti;. .:.,. LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:. .,;tfLGGDDDDDDDDEDDD * *ti;. ..:.,. LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,. .,;tfLGGDDDDDDDDDKDD * *tt;. .:.,: jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,: .,;tfLGGDDDDDDDDDDKD * *tii,. .:.,. tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,. .,;tfLGGDDDDDDDDDDDE * *ti;;,:. .:.,: fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,. .,;tfLGGDDDDDDDDDDDD * *tii;,,:.. ...,. ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,: .,itfLGGDDDDDDDDDDDD * *ti;,,,,,:. ...,. LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:. .,itfGGGDDDDDDDDDDDD * *tii,,,,::::. ...,: .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:. .,ijfGGGDDDDDDDDDDDD * *ti;:::::::::.. .:.,: LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,: .,ijLGGGDDDDDDDDDDDD * *tt;. .::::::::.. ...,: :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:. .:,;,:. .,ijLGGDDDDDDDDDDDDD * *tt;. .:::::::.. ...,: GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,. :,,,:...,ijLGGGDDDDDDDDDDDD * *tt;. .....::::.. ...,: fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi. .,;,:::,ijLGGGDDDDDDDDDDDD * *tt;. ....:::::. ...,. iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff. .:,;,,;ijLGGGDDDDDDDDDDDD * *tt;. ....::::.. .:.,: .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG. .:,;;iijLGGGDDDDDDDDDDDD * *tt;. .....:::.. ...,. .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG. :,iitjLGGGDDDDDDDDDDDD * *tti. .....:::.. ...,. GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf. .,;tjfLGGDDDDDDDDDDDD * *tti. ....::::.. ...,. fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf. :;ijfLGGDDDDDDDDDDDD * *tti. ....::::.. ...,. LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf: .,itfLGGDDDDDDDDDDDD * *tti. .....:::.. ...,. fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi .,;tfLGGGDDDDDDDDDDD * *tti. .....:::.. ...,. iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL .,;tjLLGGDDDDDDDDDDD * *tti. ....::::......:. LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG .,;tjLLGGDDDDDDDDDDD * *tti. ...::::::..,. :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL .,;tjLLGGDDDDDDDDDDD * *tti. ....::::::,. GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf .,;tjLLGGDDDDDDDDDDD * *tti. ....:::,,. .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf .:;tjLLGGGDDDDDDDDDD * *tti. ...::,,,:. GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf .:;tjLLGGDDDDDDDDDDD * *jti. ...::,,,,:. .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf: .,;tfLLGGDDDDDDDDDDD * *tti. ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi .,;tfLLGGGDDDDDDDDDD * *tti. ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL .,;tfLGGGDDDDDDDDDDD * *jti. ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG .,;tfLGGGGDDDDDDDDDD * *jti. ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL .,;tfLGGGGDDDDDDDDDD * *jti. ...:. .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf .,;tfGGGGDDDDDDDDDDD * *jti. ...:. ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:. .,;tfGGGGDDDDDDDDDDD * *jti. ...:. GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,: .,;tfGGGGDDDDDDDDDDD * *jti. ...:. GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK, ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:. .,;tfGGGDDDDDDDDDDDD * *jti. ...:. .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:. .,;tfGGGDDDDDDDDDDDD * *jti. ...:. DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD * *jti. ...:. fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG .:,,,:::,;tfGGGDDDDDDDDDDDD * *jti. ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL .:,;,,,;tfGGGDDDDDDDDDDDD * *jti. ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf .:,;;;itfGGGDDDDDDDDDDDD * *jti. ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf .,;iitfGGGDDDDDDDDDDDD * *jti. ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL .:;itfGGGDDDDDDDDDDDD * *jji. ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j. KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf .,;tfGGGDDDDDDDDDDDD * *jji. ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;.................................. . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL, .:;tfGGGDDDDDDDDDDDD * *jji. .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................:: KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj .:;tfGGDDDDDDDDDDDDD * *jji. .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG .:;tfGGGDDDDDDDDDDDD * *jji. . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG .;tjfLLGDDDDDDDDDDDDDDD * *jji. i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL ,fGGGDDDDDDDDEEEDDDDDDDDDD * *jji. .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD * *jji. i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD * *jji. .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD * *jji. .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL; .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD * *jji. :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED * *jji. i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE * *jji. i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD * *jji. .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG * *jjt. :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG * *jji. ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG * *jjt. f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG * *jjt. ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG * *fji. ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL * *fji. t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL * *fjt: .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL * *fjji;:. .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG * *fjjtii;,:. :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG * *fjtiiiii;;:. j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG * *fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG * *fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD * *jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD * *fjt. .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD * *fjt. .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD * *fjt. .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD * *fjt: :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD * *fjt: t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD * *jjt. f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD * *fjt:. ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG * *fjt:. ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; * *fjt:. f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, * *fjt:. .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, * *fjt:. .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, * *fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, * *fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, * *fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; * *fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; * *fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; * ***********************************************************************************************************************************************************************************************************/ void sort(int a[]) { ArrayList<Integer> list=new ArrayList<>(); for(int x: a) list.add(x); Collections.sort(list); for(int i=0;i<a.length;i++) a[i]=list.get(i); } void sort(long a[]) { ArrayList<Long> list=new ArrayList<>(); for(long x: a) list.add(x); Collections.sort(list); for(int i=0;i<a.length;i++) a[i]=list.get(i); } void ruffleSort(int a[]) { Random rand=new Random(); int n=a.length; for(int i=0;i<n;i++) { int j=rand.nextInt(n); int temp=a[i]; a[i]=a[j]; a[j]=temp; } Arrays.sort(a); } void ruffleSort(long a[]) { Random rand=new Random(); int n=a.length; for(int i=0;i<n;i++) { int j=rand.nextInt(n); long temp=a[i]; a[i]=a[j]; a[j]=temp; } Arrays.sort(a); } 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 s=""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } } long fact[]; long invFact[]; void init(int n) { fact=new long[n+1]; invFact=new long[n+1]; fact[0]=1; for(int i=1;i<=n;i++) { fact[i]=mul(i,fact[i-1]); } invFact[n]=power(fact[n],mod-2); for(int i=n-1;i>=0;i--) { invFact[i]=mul(invFact[i+1],i+1); } } long modInv(long x) { return power(x,mod-2); } long nCr(int n, int r) { if(n<r || r<0) return 0; return mul(fact[n],mul(invFact[r],invFact[n-r])); } long mul(long a, long b) { return a*b%mod; } long add(long a, long b) { return (a+b)%mod; } long power(long x, long y) { long gg=1; while(y>0) { if(y%2==1) gg=mul(gg,x); x=mul(x,x); y/=2; } return gg; } // Functions static long gcd(long a, long b) { return b==0?a:gcd(b,a%b); } static int gcd(int a, int b) { return b==0?a:gcd(b,a%b); } void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) out.print(a[i]+" "); out.println(); } void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) out.print(a[i]+" "); out.println(); } //Input Arrays static void input(long a[], int n) { for(int i=0;i<n;i++) { a[i]=inp.nextLong(); } } static void input(int a[], int n) { for(int i=0;i<n;i++) { a[i]=inp.nextInt(); } } static void input(String s[],int n) { for(int i=0;i<n;i++) { s[i]=inp.next(); } } static void input(int a[][], int n, int m) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { a[i][j]=inp.nextInt(); } } } static void input(long a[][], int n, int m) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { a[i][j]=inp.nextLong(); } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
b76b1962ab13252c71fdbba0ea98345b
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import static java.lang.Math.*; import static java.lang.Math.ceil; import static java.util.Arrays.sort; public class Round12 { public static void main(String[] args) { FastReader fastReader = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = fastReader.nextInt(); rsort(a); long prefix[] = new long[n]; prefix[0] = a[0]; for (int i = 1; i < n; i++) prefix[i] = prefix[i - 1] + a[i]; long suffix[] = new long[n]; suffix[n - 1] = a[n-1]; for (int i = n - 2; i >= 0; i--) suffix[i] = suffix[i + 1] + a[i]; int low = 1, high = n - 1; while (low < high) { if (prefix[low] >= suffix[high]) { low ++; high--; } else { break; } } if (low>=high){ out.println("NO"); }else{ out.println("YES"); } } out.close(); } // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final long LMAX = 9223372036854775807L; static Random __r = new Random(); // math util static int minof(int a, int b, int c) { return min(a, min(b, c)); } static int minof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } static long minof(long a, long b, long c) { return min(a, min(b, c)); } static long minof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } static int maxof(int a, int b, int c) { return max(a, max(b, c)); } static int maxof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } static long maxof(long a, long b, long c) { return max(a, max(b, c)); } static long maxof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } static int powi(int a, int b) { if (a == 0) return 0; int ans = 1; while (b > 0) { if ((b & 1) > 0) ans *= a; a *= a; b >>= 1; } return ans; } static long powl(long a, int b) { if (a == 0) return 0; long ans = 1; while (b > 0) { if ((b & 1) > 0) ans *= a; a *= a; b >>= 1; } return ans; } static int fli(double d) { return (int) d; } static int cei(double d) { return (int) ceil(d); } static long fll(double d) { return (long) d; } static long cel(double d) { return (long) ceil(d); } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static int[] exgcd(int a, int b) { if (b == 0) return new int[]{1, 0}; int[] y = exgcd(b, a % b); return new int[]{y[1], y[0] - y[1] * (a / b)}; } static long[] exgcd(long a, long b) { if (b == 0) return new long[]{1, 0}; long[] y = exgcd(b, a % b); return new long[]{y[1], y[0] - y[1] * (a / b)}; } static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static long mix(long x) { x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31); } public static boolean[] findPrimes(int limit) { assert limit >= 2; final boolean[] nonPrimes = new boolean[limit]; nonPrimes[0] = true; nonPrimes[1] = true; int sqrt = (int) Math.sqrt(limit); for (int i = 2; i <= sqrt; i++) { if (nonPrimes[i]) continue; for (int j = i; j < limit; j += i) { if (!nonPrimes[j] && i != j) nonPrimes[j] = true; } } return nonPrimes; } // array util static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
ac4090e192905cc24240e110752feb3a
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class B_Quality_vs_Quantity { public static void main(String[] args) { OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); FastReader f = new FastReader(); int t = f.nextInt(); while(t-- > 0){ int n = f.nextInt(); long arr[] = new long[n]; for(int i = 0; i < n; i++) { arr[i] = f.nextLong(); } sort(arr); long sumL = arr[0] + arr[1]; long sumR = arr[n-1]; if(sumR > sumL) { out.println("YES"); continue; } int l = 2; int r = n-2; boolean flag = false; while(r > l) { sumL += arr[l]; l++; sumR += arr[r]; r--; if(sumR > sumL) { flag = true; break; } } if(flag == true) { out.println("YES"); } else { out.println("NO"); } } out.close(); } public static void sort(long arr[]) { ArrayList<Long> al = new ArrayList<>(); for(long i: arr) { al.add(i); } Collections.sort(al); for(int i = 0; i < arr.length; i++) { arr[i] = al.get(i); } } public static void allDivisors(int n) { for(int i = 1; i*i <= n; i++) { if(n%i == 0) { System.out.println(i + " "); if(i != n/i) { System.out.println(n/i + " "); } } } } public static boolean isPrime(int n) { if(n < 1) return false; if(n == 2 || n == 3) return true; if(n % 2 == 0 || n % 3 == 0) return false; for(int i = 5; i*i <= n; i += 6) { if(n % i == 0 || n % (i+2) == 0) { return false; } } return true; } public static int Gcd(int a, int b) { int dividend = a > b ? a : b; int divisor = a < b ? a : b; while(divisor > 0) { int reminder = dividend % divisor; dividend = divisor; divisor = reminder; } return dividend; } public static int lcm1(int a, int b) { int lcm = Gcd(a, b); int hcf = (a * b) / lcm; return hcf; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } boolean nextBoolean() { return Boolean.parseBoolean(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } /** Dec Char Dec Char Dec Char Dec Char --------- --------- --------- ---------- 0 NUL (null) 32 SPACE 64 @ 96 ` 1 SOH (start of heading) 33 ! 65 A 97 a 2 STX (start of text) 34 " 66 B 98 b 3 ETX (end of text) 35 # 67 C 99 c 4 EOT (end of transmission) 36 $ 68 D 100 d 5 ENQ (enquiry) 37 % 69 E 101 e 6 ACK (acknowledge) 38 & 70 F 102 f 7 BEL (bell) 39 ' 71 G 103 g 8 BS (backspace) 40 ( 72 H 104 h 9 TAB (horizontal tab) 41 ) 73 I 105 i 10 LF (NL line feed, new line) 42 * 74 J 106 j 11 VT (vertical tab) 43 + 75 K 107 k 12 FF (NP form feed, new page) 44 , 76 L 108 l 13 CR (carriage return) 45 - 77 M 109 m 14 SO (shift out) 46 . 78 N 110 n 15 SI (shift in) 47 / 79 O 111 o 16 DLE (data link escape) 48 0 80 P 112 p 17 DC1 (device control 1) 49 1 81 Q 113 q 18 DC2 (device control 2) 50 2 82 R 114 r 19 DC3 (device control 3) 51 3 83 S 115 s 20 DC4 (device control 4) 52 4 84 T 116 t 21 NAK (negative acknowledge) 53 5 85 U 117 u 22 SYN (synchronous idle) 54 6 86 V 118 v 23 ETB (end of trans. block) 55 7 87 W 119 w 24 CAN (cancel) 56 8 88 X 120 x 25 EM (end of medium) 57 9 89 Y 121 y 26 SUB (substitute) 58 : 90 Z 122 z 27 ESC (escape) 59 ; 91 [ 123 { 28 FS (file separator) 60 < 92 \ 124 | 29 GS (group separator) 61 = 93 ] 125 } 30 RS (record separator) 62 > 94 ^ 126 ~ 31 US (unit separator) 63 ? 95 _ 127 DEL */
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
74d240454808f4e47fbfccfa26e0e674
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static int mod = 1000000007; public static void main(String[] args) throws FileNotFoundException { FastScanner fs = new FastScanner(); int t = fs.nextInt(); outer: while (t-- > 0) { int n = fs.nextInt(); int[] a = fs.readArray(n); sort(a); long[] temp = new long[n + 1]; for (int i = 1; i <= n; i++) temp[i] = temp[i - 1] + a[i - 1]; boolean c = false; for (int i = 1; 2 * i + 1 <= n; i++) { if (temp[n] - temp[n - i] > temp[i + 1]) { c = true; break; } } if (c) System.out.println("YES"); else System.out.println("no"); } } static boolean isPrime(int n) { if (n <= 1) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { // suffle int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } // then sort Arrays.sort(a); } static long binpow(long a, long b, long m) { a %= m; long res = 1; while (b > 0) { if (b % 2 == 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } // Use this to input code since it is faster than a Scanner 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()); } double nextDouble() { return Double.parseDouble(next()); } ArrayList<Integer> readList(int n) { ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(nextInt()); return list; } } static class Pair { String name; ArrayList<Integer> val; public Pair(String name, ArrayList<Integer> val) { this.name = name; this.val = val; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
78478d93285a52f072cc553d57c5c489
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- >0) { int n=sc.nextInt(); int[] arr=new int[n]; PriorityQueue<Integer> pq=new PriorityQueue<>(); PriorityQueue<Integer> pq2=new PriorityQueue<>(Collections.reverseOrder()); for(int i=0;i<n;i++) { int val=sc.nextInt(); pq.add(val); pq2.add(val); } boolean ok=false; long sum1=pq.remove(); long sum2=0; int i=1; int j=n-1; while(i<j) { sum1+=pq.remove(); sum2+=pq2.remove(); if(sum1<sum2) { ok=true; break; } j--; i++; } System.out.println(ok?"YES":"NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
d76f0f0411b237c8d921df0df05fbfee
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class quanvqual{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(br.readLine()); for(int tt=1; tt<=test; tt++){ long len = Long.parseLong(br.readLine()); StringTokenizer str = new StringTokenizer(br.readLine()); ArrayList<Long> list = new ArrayList<Long>(); for(int i=0; i<len; i++){ list.add(Long.parseLong(str.nextToken())); } Collections.sort(list); int flag=0; long sumB = list.get(0); long sumR = 0; if(sumB<sumR){ flag =1; } // System.out.println(list); for(int k=1; k<=len/2 && flag ==0; k++){ // System.out.println(k); long countB = k+1; long countR = k; sumB = sumB + list.get(k); sumR = sumR + list.get((int)len-k); // System.out.println("sumB"+sumB); // System.out.println("sumR"+sumR); if(sumR>sumB){ flag =1; break; } } System.out.println(flag==1?"YES":"NO"); // System.out.println(list); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
9e007d9e0358fcfab5655aad85be641b
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class Solution { static int mod= 998244353 ; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer:while(t-->0) { int n = fs.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); for(int i = 0;i < n;i++){ arr.add(fs.nextInt()); } Collections.sort(arr); boolean ans = false; long sum_blue = arr.get(0); long sum_red = 0; for(int i = 1;i <= (n/2);i++){ sum_blue += arr.get(i); sum_red += arr.get(n-i); if(sum_red > sum_blue){ ans = true; break; } } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } out.close(); } static long pow(long a,long b) { if(b<0) return 1; long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); int temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } // Use this to input code since it is faster than a Scanner 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[] readArrayL(int n) { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
7bdabf8ffb168f0827a20c5a2d7b6219
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class B_Quality_vs_Quantity { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int arr[] = sc.readArray(n); randomShuffle(arr); Arrays.sort(arr); long sumR = arr[n - 1], sumB = arr[0] + arr[1]; int l = 2, r = n - 2; while (l < r && sumR <= sumB) { sumB += arr[l++]; sumR += arr[r--]; } out.println(sumR>sumB?"YES":"NO"); } out.close(); } static long[] reverse(long a[], int n) { long[] b = new long[n]; int j = n; for (int i = 0; i < n; i++) { b[j - 1] = a[i]; j = j - 1; } return b; } public static PrintWriter out; public static long mod = (long) 1e9 + 7; static final Random rnd = new Random(); public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void dfs(int root, boolean[] vis, int[] value, ArrayList[] gr, int prev) { vis[root] = true; value[root] = 3 - prev; prev = 3 - prev; for (int i = 0; i < gr[root].size(); i++) { int next = (int) gr[root].get(i); if (!vis[next]) dfs(next, vis, value, gr, prev); } } static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } static int abs(int a) { return a > 0 ? a : -a; } static int max(int a, int b) { return a > b ? a : b; } static int min(int a, int b) { return a < b ? a : b; } static long pow(long n, long m) { if (m == 0) return 1; long temp = pow(n, m / 2); long res = ((temp * temp) % mod); if (m % 2 == 0) return res; return (res * n) % mod; } static void randomShuffle(int[] array) { int n = array.length; for (int i = 0; i < n; i++) { int j = i + rnd.nextInt(n - i); int tmp = array[i]; array[i] = array[j]; array[j] = tmp; } } static class Pair { int u, v; Pair(int u, int v) { this.u = u; this.v = v; } static void sort(Pair[] coll) { List<Pair> al = new ArrayList<>(Arrays.asList(coll)); Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return p1.u - p2.u; } }); for (int i = 0; i < al.size(); i++) { coll[i] = al.get(i); } } } static void sort(int[] a) { ArrayList<Integer> list = new ArrayList<>(); for (int i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static void sort(long a[]) { ArrayList<Long> list = new ArrayList<>(); for (long i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static int[] array(int n, int value) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = value; return a; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
8a9c92d5ec13f8480c7da00bf2bdef48
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; public class PaintNumbers { final static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); final static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException { StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); for (int i = 0; i < n; i++) { st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); List<Integer> list = new ArrayList<>(); for (int j = 0; j < t; j++) { list.add(Integer.parseInt(st.nextToken())); } if (res(list)) { bw.write("YES\n"); } else { bw.write("NO\n"); } bw.flush(); } } private static boolean res(List<Integer> list) { Collections.sort(list); int res = list.get(0); for (int j = 1; j < (list.size() + 1) / 2; j++) { res += list.get(j); res -= list.get(list.size() - j); if (res < 0) { return true; } } return false; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
b89e3216ae2f8e046f37353d8e21ace1
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class B { static class RealScanner { 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()); } public boolean isSorted(List<Long> list) { for (int i = 0; i < list.size() - 1; i++) { if (list.get(i) > list.get(i + 1)) return false; } return true; } } public static void main(String[] args) { RealScanner sc = new RealScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); m: while (t-- > 0) { int n = sc.nextInt(); // int[] arr = new int[n]; //// for (int i = 0; i < n; i++) { //// arr[i] = sc.nextInt(); //// } //// Arrays.sort(arr); //// int low = arr[0] + arr[1]; //// if (low >= arr[n - 1] || n <= 2) { //// System.out.println("NO"); //// } else { //// System.out.println("YES"); //// } List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } Collections.sort(list); int i = 2, j = n - 2; long blue = list.get(0) + list.get(1), red = list.get(n - 1); while (i < j) { red += list.get(j); blue += list.get(i); i++; j--; } if (red > blue) { out.println("YES"); } else { out.println("NO"); } } out.flush(); out.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
c1ae6d67bdfa869f891ee02bb921f5c2
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; //-------------------------------///////////////****/////////******////////// //------------------------------------///**********//*****//********//*****// //-----------------------------------///**********//*****//********//*****// //----------------------------------///**********//*****//********//*****// //---------------------------------///**********//*****//********//*****// //--------------------------------///**********//*****//********//*****// //--------------------------///**///**********//*****//********//*****// //---------------------------/////***********/////////*******////////// public class CodeForces { final static String no = "NO"; final static String yes = "YES"; static long count = 0; static public OutputWriter w = new OutputWriter(System.out); static public FastScanner sc = new FastScanner(); static HashMap<Integer, Integer> map = new HashMap<>(); static Scanner fc = new Scanner(System.in); //*******************************************Be SANSA*********************************** //************************************Don't stick to single approach******************** //*****************************************You are a slow learner But you learn********* //***************************************Don't fall in rating trap********************** //**********************************Pain in temporary, regret remains forever*********** //////////////////////////////////////////////////////////////////////////////////////////// public static void main(String[] args) { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[]ar = sc.readArray(n); sort(ar); boolean ans = false; long low = ar[0]; long high = 0; int i=1; int j=n-1; while(i<j) { low+=ar[i]; high +=ar[j]; if(low<high) { ans = true; break; } else { i++; j--; } } if(ans) { w.writer.println(yes); }else { w.writer.println(no); } } w.writer.flush(); } ////////////////////////////////////////////////////////////////////////////////////////// static ArrayList<Integer> primes = new ArrayList<>(); static boolean[]sieve = new boolean[(int)1e5+1]; static void sieve(int n) { sieve[0] = sieve[1] = true; primes.add(2); for(int i=3;i<=(int)n;i+=2) { if(!sieve[i]) { primes.add(i); for(int j=i*2;j<=(int)n;j+=i) { sieve[j]= true; } } } } static int floorPowerOf2(int n) { int p = (int)(Math.log(n) / Math.log(2)); return (int)Math.pow(2, p); } static int ceilPowerOf2(int n) { int p = (int)(Math.log(n) / Math.log(2)); return (int)Math.pow(2, p+1); } static int[] reverseArray(int[] arr, int begin, int end) { if (arr.length == 1) { return arr; } while (begin < end) { int tmp = arr[begin]; arr[begin++] = arr[end]; arr[end--] = tmp; } return arr; } static String reverse(String s) { return new StringBuilder(s).reverse().toString(); } static int printCubes(int a, int b) { // Find cube root of both a and b int acrt = (int) Math.cbrt(a); int bcrt = (int) Math.cbrt(b); int cnt = 0; // Print cubes between acrt and bcrt for (int i = acrt; i <= bcrt; i++) if (i * i * i >= a && i * i * i <= b && !(checkPerfectSquare(i))) cnt++; return cnt; } static double countSquares(int a, int b) { return (Math.floor(Math.sqrt(b)) - Math.ceil(Math.sqrt(a)) + 1); } static boolean checkPerfectSquare(int n) { // If ceil and floor are equal // the number is a perfect // square if (Math.ceil((double) Math.sqrt(n)) == Math.floor((double) Math.sqrt(n))) { return true; } else { return false; } } static boolean perfectCube(int N) { int cube_root; cube_root = (int) Math.round(Math.cbrt(N)); // If cube of cube_root is equals to N, // then print Yes Else print No if (cube_root * cube_root * cube_root == N) { //System.out.println("Yes"); return true; } else { // System.out.println("NO"); return false; } } static List<Integer> printDivisors(int n) { // Note that this loop runs till square root List<Integer> sl = new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { // If divisors are equal, print only one if (n / i == i) sl.add(i); else // Otherwise print both { sl.add(i); sl.add(n / i); } } } return sl; } static boolean isPrime(int n) { if (n <= 1) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static class Pair { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } } static public boolean checkBit(int n, int i) { if ((n >> i & 1) == 1) { return true; } else { return false; } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static boolean isPowerOfTwo(long n) { if (n == 0) return false; return (long) (Math.ceil((Math.log(n) / Math.log(2)))) == (long) (Math.floor(((Math.log(n) / Math.log(2))))); } // method to return LCM of two numbers static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long getPairsCount(long[] arr, long sum) { Map<Long, Long> hm = new HashMap<>(); int n = arr.length; long count = 0; for (int i = 0; i < n; i++) { if (hm.containsKey(sum - arr[i])) { count += hm.get(sum - arr[i]); } if (hm.get(arr[i]) != null) { hm.put(arr[i], hm.get(arr[i]) + 1); } else { hm.put(arr[i], 1l); } } return count; } static boolean isEqualList(ArrayList<Integer> arr, ArrayList<Integer> temp) { for (int i = 0; i < arr.size(); i++) { if (arr.get(i) != temp.get(i)) { return true; } } return false; } static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sort(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static String mulStr(String s,int n) { StringBuilder sv = new StringBuilder(); for(int i=0;i<n;i++) { sv.append(s); } return sv.toString(); } static void sortDec(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static void sortDec(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static int[] countInversions(int[] arr, int low, int high) { if (low == high) { int base[] = new int[1]; base[0] = arr[low]; return base; } int mid = low + (high - low) / 2; int left[] = countInversions(arr, low, mid); int right[] = countInversions(arr, mid + 1, high); int[] merged = merge(left, right); return merged; } static int[] merge(int first[], int[] next) { int i = 0; int j = 0; int k = 0; int[] merged = new int[first.length + next.length]; while (j < first.length && k < next.length) { if (first[j] <= next[k]) { merged[i++] = first[j++]; } else { count += first.length - j; merged[i++] = next[k++]; } } while (j < first.length) { merged[i++] = first[j++]; } while (k < next.length) { merged[i++] = next[k++]; } return merged; } 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()); } long[] longArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } } static public 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(); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
4efa51dcad4d47418c4c61f40763eec8
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; //import java.math.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; //import java.math.BigInteger; import java.util.*; public class codeforces { final static String no = "NO"; final static String yes = "YES"; static int count = 0; static public OutputWriter w = new OutputWriter(System.out); static public FastScanner sc = new FastScanner(); class Pair{ int x ,y; public Pair(int x,int y) { this.x = x; this.y = y; } } /* static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } static long[] readArr2(int N, BufferedReader infile, StringTokenizer st) throws Exception { long[] arr = new long[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Long.parseLong(st.nextToken()); return arr; } */ static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } static long lcm (long a, long b) { return (a*b)/gcd(a,b); } static long findGCD(int arr[], int n) { long result = arr[0]; for (int element: arr){ result = gcd(result, element); if(result == 1) { return 1; } } return result; } static void sortss(int arr[],int arr2[]) { int n = arr.length; // One by one move boundary of unsorted subarray for (int i = 0; i < n-1; i++) { // Find the minimum element in unsorted array int min_idx = i; for (int j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element with the first // element int temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp; int temp1 = arr2[min_idx]; arr2[min_idx] = arr2[i]; arr2[i] = temp1; } } static int countOdd(int L, int R) { int N = (R - L) / 2; if (R % 2 != 0 || L % 2 != 0) N++; return N; } public static void main(String[]args) { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long a[] = readArr2(n); sort(a); int num = (n-1)/2; long red[] = new long[num]; long blue [] = new long[n-num]; blue[0] = a[0]; int x=num, y=n-num; for(int i=1; i<y; i++) { blue[i] = a[i]+blue[i-1]; } red[0] = a[n-1]; int k=1; for(int i=n-2; i>=y; i--) { red[k] = red[k-1]+a[i]; k++; } //iterate(red); //iterate(blue); int i=0,j=0; boolean flag=false; while(i<x && j<y) { if(i<=j) { i++; } if(red[j]<=blue[i]) { j++; } if(i>j && red[j]>blue[i]) { flag=true; break; } } if(flag) w.writer.println(yes); else w.writer.println(no); } w.writer.flush(); } static int[] readArr(int x) { int arr[] = new int[x]; for(int i=0; i<x; i++) { arr[i] = sc.nextInt(); } return arr; } static long[] readArr2(int x) { long arr[] = new long[x]; for(int i=0; i<x; i++) { arr[i] = sc.nextLong(); } return arr; } static void iterate(long arr[]) { for(int i=0; i<arr.length; i++) { w.writer.print(arr[i]+" "); } w.writer.println(); } static int[] compress(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for(int x: arr) ls.add(x); Collections.sort(ls); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int boof = 1; //min value for(int x: ls) if(!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for(int i=0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } /* static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } */ static void sort(int[] arr) { //because Arrays.sort() uses quicksort which is dumb //Collections.sort() uses merge sort 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); } static void sort(long[] arr) { //because Arrays.sort() uses quicksort which is dumb //Collections.sort() uses merge sort ArrayList<Long> ls = new ArrayList<Long>(); for(long x: arr) ls.add(x); Collections.sort(ls); for(int i=0; i < arr.length; i++) arr[i] = ls.get(i); } static void sortDec(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static void sortDec(long[] arr) { int n = arr.length; sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static int[] countInversions(int[]arr,int low,int high){ if(low==high) { int base[] = new int[1]; base[0] = arr[low]; return base; } int mid = low+(high-low)/2; int left[] = countInversions(arr,low,mid); int right[] = countInversions(arr,mid+1,high); int[]merged = merge(left,right); return merged; } static int[] merge(int first[], int[]next) { int i = 0; int j = 0; int k = 0; int[]merged = new int[first.length+next.length]; while(j<first.length && k<next.length) { if(first[j]>=next[k]) { merged[i++] = first[j++]; }else { merged[i++] = next[k++]; count += first.length -j; } } while(j<first.length) { merged[i++] = first[j++]; } while(k<next.length) { merged[i++] = next[k++]; } return merged; } 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()); } long [] longArray(int n) { long[] a=new long[n]; for(int i=0 ; i<n ; i++) a[i]=nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } } static public 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(); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
0c824eda18c1dc6bc64b1a3942fc6254
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.*; public class Solution { 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 class Pair { int x; int y; // Constructor public Pair(int x, int y) { this.x = x; this.y = y; } // @Override // public int hashCode() { // return this.x ^ this.y; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // Pair other = (Pair) obj; // if (x != other.x) // return false; // if (y != other.y) // return false; // return true; // } } static class Trip { long a; long b; long c; // Constructor public Trip(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } } static class Quad { String a; String b; String c; String d; // Constructor public Quad(String a, String b, String c, String d) { this.a = a; this.b = b; this.c = c; this.d = d; } } public static void swap(int i, long[] arr) { long temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (long 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 (a == 0) return b; return gcd(b % a, a); } static int factorial(int n) { // single line to find factorial return (n == 1 || n == 0) ? 1 : (n * factorial(n - 1))/1000000007; } // Function to convert decimal to fraction public static void SubString(String str, int n, HashSet<String> hs) { for (int i = 0; i < n; i++) for (int j = i+1; j <= n; j++) // Please refer below article for details // of substr in Java // https://www.geeksforgeeks.org/java-lang-string-substring-java/ hs.add(str.substring(i, j)); } static class TrieNode{ TrieNode children[]; boolean isEnd; TrieNode(){ this.children = new TrieNode[26]; this.isEnd = false; } } static void subStrings(String s,HashSet<String> hs) { // To store distinct output subStrings HashSet<String> us = new HashSet<String>(); // Traverse through the given String and // one by one generate subStrings beginning // from s[i]. for (int i = 0; i < s.length(); ++i) { // One by one generate subStrings ending // with s[j] String ss = ""; for (int j = i; j < s.length(); ++j) { ss = ss + s.charAt(j); us.add(ss); } } // Print all subStrings one by one for (String str : us) { hs.add(str); } } static boolean isSubSequence(String str1, String str2, int m, int n) { int j = 0; // Traverse str2 and str1, and compare // current character of str2 with first // unmatched char of str1, if matched // then move ahead in str1 for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == str2.charAt(i)) j++; // If all characters of str1 were found // in str2 return (j == m); } static int onesComplement(int n) { // Find number of bits in the // given integer int number_of_bits = (int)(Math.floor(Math.log(n) / Math.log(2))) + 1; // XOR the given integer with poe(2, // number_of_bits-1 and print the result return ((1 << number_of_bits) - 1) ^ n; } static int binarySearch(HashSet<Integer> hs,HashMap<Integer,Integer> hm, int l, int r, int a, int b) { if(l==r) { //System.out.println(l); if(hs.contains(l)) return b; else return a; } if (r > l) { int mid = l + (r - l) / 2; // If the element is present at the // middle itself int cnt=hm.get(r)-hm.get(l-1); if(cnt==0) return a; else { int x = binarySearch(hs,hm, mid + 1, r, a, b)+binarySearch(hs,hm, l, mid, a, b); int y = cnt*(r-l+1)*b; return Math.min(x, y); } } // We reach here when element is not present // in array return -1; } public static boolean[] sieveOfEratosthenes(int n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. 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; } } // Print all prime numbers return prime; } static long x, y; static long gcd_extend(long a, long b) { // Base Case if (b == 0) { x = 1; y = 0; return a; } // Recursively find the gcd else { long g = gcd_extend(b, a % b); long x1 = x, y1 = y; x = y1; y = x1 - ((a / b)%1000000000000000000L * y1%1000000000000000000L)%1000000000000000000L; return g; } } static long first, second; static void print2Smallest(long arr[]) { long arr_size = arr.length; /* There should be atleast two elements */ if (arr_size < 2) { System.out.println(" Invalid Input "); return; } first = second = Long.MAX_VALUE; for (int i = 0; i < arr_size ; i ++) { /* If current element is smaller than first then update both first and second */ if (arr[i] < first) { second = first; first = arr[i]; } /* If arr[i] is in between first and second then update second */ else if (arr[i] < second) second = arr[i]; } } public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-- > 0) { long n = sc.nextLong(); long[] arr =new long[(int) n]; long tot=0; for(int i=0;i<n;i++) { arr[i]=sc.nextLong(); tot+=arr[i]; } PriorityQueue<Long> pqq = new PriorityQueue<>(); for(int i=0;i<n;i++) { pqq.add(arr[i]); } for(int i=0;i<n;i++) { arr[i]=pqq.remove(); } long sum1=0;long sum2=0;boolean b=false; sum1 = arr[0] + arr[1]; sum2 = arr[(int) (n-1)]; int l=1;int r=(int) (n-1); while(sum1>=sum2 && l<r) { l++; r--; if(l>=r) break; sum1 = sum1 + arr[l]; sum2 = sum2 + arr[r]; } if(sum1<sum2) { System.out.println("YES"); } else { System.out.println("NO"); } } //output.flush(); } } //long n = sc.nextLong(); //HashSet<Long> hs = new HashSet<>(); //long prod=1; //for(int i=1;i<=16;i++) { // prod*=i; // hs.add(prod); //} //int cnt=0; //while(n!=0) { // if(hs.contains(n)) { // cnt++;break; // } // int pow=0; // while(Math.pow(2, pow)<n) { // pow++; // } // pow--;cnt++; // n=(long) (n-Math.pow(2, pow)); //} //System.out.println(cnt);
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
5fa5d71c7f8877d032172a9e2d916390
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here FastReader s = new FastReader(); 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[] asum = new long[n]; asum[0] = a[0]; for(int i = 1;i<n;i++){ asum[i] = asum[i-1]+a[i]; } boolean ans = false; long sie = 0; for(int i = n-1;i>=(n/2)+1;i--){ sie+=a[i]; long sis = 0; sis = asum[n-i]; if(sie>sis){ // System.out.println(i+" "+sie+" "+sis); ans = true; break; } } if(ans){ System.out.println("Yes"); } else{ System.out.println("No"); } // for(int i = 0;i<n;i++){ // System.out.print(a[i]+" "); // } // System.out.println(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
02669f6a68de27c80655ef16f7a53cdc
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static final long mod = 998244353; public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); FastScanner fs = new FastScanner(); int T = fs.nextInt(); while (T-- > 0) { int n = fs.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = fs.nextInt(); sort(arr); int i = 0, j = arr.length - 1; long sum1 = arr[0], sum2 = arr[arr.length - 1]; int rc = 0, bc = 0; boolean flag = false; while (i < j) { if (sum1 < sum2 && bc > rc) { flag = true; break; } if (bc <= rc) { i++; sum1 += arr[i]; bc++; } if (sum1 >= sum2) { j--; sum2 += arr[j]; rc++; } } out.println(flag ? "YES" : "NO"); } 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 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(); } String readLine() { String s = ""; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
bd15f90004c16a4dad21826a3a9bffd9
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while(t-- > 0){ int n = sc.nextInt(); sc.nextLine(); ArrayList<Long> arr = new ArrayList<>(); for(int i = 0; i<n; i++){ Long x = sc.nextLong(); arr.add(x); } Collections.sort(arr); long sum1 = arr.get(0) + arr.get(1); long sum2 = arr.get(n-1); int i = 1, j = n-1; boolean ans = false; while(i<j){ if(sum1<sum2){ ans = true; break; } else{ sum1 += arr.get(++i); sum2 += arr.get(--j); } } if(ans){ System.out.println("YES"); } else{ System.out.println("NO"); } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
42567a7b0116907417ea4962411f8b70
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Quality_Vs_Quantity { 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(); Long arr[] = new Long[n]; for(int i=0;i<n;i++) { arr[i] = sc.nextLong(); } Arrays.sort(arr); long sum1 = arr[0]; long sum2 = arr[n-1]; boolean flag = false; int i=0,j=n-1; while(i<j) { int x = i+1; int y = n-j; if(x<=y) { i++; sum1+=arr[i]; }else { if(sum2>sum1) { flag = true; System.out.println("YES"); break; }else { j--; sum2+= arr[j]; } } } if(!flag) System.out.println("NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 11
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
853d28ba29996edbc56323d9d8286abc
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Solution solution = new Solution(); for (int i = 0; i < t; i++) { int n = cin.nextInt(); long[] a = new long[n]; for (int j = 0; j < n; j++) { a[j] = cin.nextLong(); } System.out.println(solution.func(a)); } } } class Solution { public String func(long[] a) { int n = a.length; shuffleArray(a); Arrays.sort(a); long sumR = 0; long sumB = a[0]; int r = n - 1; int b = 1; while (b < r) { sumB += a[b]; sumR += a[r]; if (sumR > sumB) { return "YES"; } b++; r--; } return "NO"; } void shuffleArray(long[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
dd4e5da0b1d53929e4b456419e5b0dac
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Solution solution = new Solution(); for (int i = 0; i < t; i++) { int n = cin.nextInt(); long[] a = new long[n]; for (int j = 0; j < n; j++) { a[j] = cin.nextLong(); } System.out.println(solution.func(a)); } } } class Solution { public String func(long[] arr) { int n = arr.length; Long[] a = new Long[n]; for (int i = 0; i < arr.length; i++) { a[i] = arr[i]; } Arrays.sort(a); long sumR = 0; long sumB = a[0]; int r = n - 1; int b = 1; while (b < r) { sumB += a[b]; sumR += a[r]; if (sumR > sumB) { return "YES"; } b++; r--; } return "NO"; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
3a27633dbecd4f626482b7eab6d5e10a
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Solution solution = new Solution(); for (int i = 0; i < t; i++) { int n = cin.nextInt(); Integer[] a = new Integer[n]; for (int j = 0; j < n; j++) { a[j] = cin.nextInt(); } System.out.println(solution.func(a)); } } } class Solution { public String func(Integer[] a) { int n = a.length; Arrays.sort(a); long sumR = 0; long sumB = a[0]; int r = n - 1; int b = 1; while (b < r) { sumB += a[b]; sumR += a[r]; if (sumR > sumB) { return "YES"; } b++; r--; } return "NO"; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
e285d6687b1d6529b18471502acd090f
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Solution solution = new Solution(); for (int i = 0; i < t; i++) { int n = cin.nextInt(); Long[] a = new Long[n]; for (int j = 0; j < n; j++) { a[j] = cin.nextLong(); } System.out.println(solution.func(a)); } } } class Solution { public String func(Long[] a) { int n = a.length; Arrays.sort(a); long sumR = 0; long sumB = a[0]; int r = n - 1; int b = 1; while (b < r) { sumB += a[b]; sumR += a[r]; if (sumR > sumB) { return "YES"; } b++; r--; } return "NO"; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
6c9b3e1d15f27736df57306d77e759cb
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
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.Scanner; import java.util.StringTokenizer; public class Main { public static void main2(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Solution solution = new Solution(); for (int i = 0; i < t; i++) { int n = cin.nextInt(); long[] a = new long[n]; for (int j = 0; j < n; j++) { a[j] = cin.nextLong(); } System.out.println(solution.func(a)); } } public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(f.readLine()); Solution solution = new Solution(); for (int q = 1; q <= t; q++) { int n = Integer.parseInt(f.readLine()); StringTokenizer st = new StringTokenizer(f.readLine()); Long[] array = new Long[n]; for (int k = 0; k < n; k++) { array[k] = Long.parseLong(st.nextToken()); } out.println(solution.func2(array)); } out.close(); } } class Solution { public String func(long[] a) { int n = a.length; Arrays.sort(a); long sumR = 0; long sumB = a[0]; int r = n - 1; int b = 1; while (b < r) { if (a[b] == a[r]) { return "NO"; } sumB += a[b]; sumR += a[r]; if (sumR > sumB) { return "YES"; } b++; r--; } return "NO"; } public String func2(Long[] array) { int n = array.length; Arrays.sort(array); int l = 1; int r = n - 1; long red = 0L; long blue = array[0]; boolean found = false; while (l < r) { red += array[r]; blue += array[l]; if (red > blue) { found = true; break; } l++; r--; } if (found) { return "YES"; } else { return "NO"; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
a09924d0a810044c18c657474c21a6f1
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
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.Scanner; import java.util.StringTokenizer; public class Main { public static void main2(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Solution solution = new Solution(); for (int i = 0; i < t; i++) { int n = cin.nextInt(); int[] a = new int[n]; for (int j = 0; j < n; j++) { a[j] = cin.nextInt(); } System.out.println(solution.func(a)); } } public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(f.readLine()); for (int q = 1; q <= t; q++) { int n = Integer.parseInt(f.readLine()); StringTokenizer st = new StringTokenizer(f.readLine()); Long[] array = new Long[n]; for (int k = 0; k < n; k++) { array[k] = Long.parseLong(st.nextToken()); } Arrays.sort(array); int l = 1; int r = n - 1; long red = 0L; long blue = array[0]; boolean found = false; while (l < r) { red += array[r]; blue += array[l]; if (red > blue) { found = true; break; } l++; r--; } if (found) { out.println("YES"); } else { out.println("NO"); } } out.close(); } } class Solution { public String func(int[] a) { int n = a.length; Arrays.sort(a); long sumR = 0; long sumB = a[0]; int r = n - 1; int b = 1; while (b < r) { if (a[b] == a[r]) { return "NO"; } sumB += a[b]; sumR += a[r]; if (sumR > sumB) { return "YES"; } b++; r--; } return "NO"; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
87c7933d571b33231330df2850cd5fbd
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class B774{ public static void main(String[] args)throws IOException{ BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(f.readLine()); for(int q = 1; q <= t; q++){ int n = Integer.parseInt(f.readLine()); StringTokenizer st = new StringTokenizer(f.readLine()); Long[] array = new Long[n]; for(int k = 0; k < n; k++){ array[k] = Long.parseLong(st.nextToken()); } Arrays.sort(array); int l = 1; int r = n-1; long red = 0L; long blue = array[0]; boolean found = false; while(l < r){ red += array[r]; blue += array[l]; if(red > blue){ found = true; break; } l++; r--; } if(found){ out.println("YES"); } else { out.println("NO"); } } out.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
b8dfa66341bb97c8f795c912099e05fb
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } 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 [] arrayIn(int n) throws IOException { int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } } // static Scanner sc = new Scanner(System.in); static FastReader sc = new FastReader(); public static void reverse(int[] arr, int l, int r) { int d = (r - l + 1) / 2; for (int i = 0; i < d; i++) { int t = arr[l + i]; arr[l + i] = arr[r - i]; arr[r - i] = t; } } public static void shuffle(int a[], int n) { for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index int x = a[t]; a[t] = a[i]; a[i] = x; } } public static void main(String[] args) { // if (System.getProperty("ONLINE_JUDGE") == null) { // try { // System.setOut(new PrintStream( // new FileOutputStream("output.txt"))); // sc = new Scanner(new File("input.txt")); // } catch (Exception e) { // } // } int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { // solve(); 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 red = arr[n - 1]; long blue = arr[0] + arr[1]; int i = 2, j = n - 2; boolean flag = false; while (j > i) { if (red > blue) { flag = true; break; } red += arr[j]; j--; blue += arr[i]; i++; } if (red > blue) flag = true; if (flag) sb.append("YES \n"); //System.out.println("YES"); else sb.append("NO \n");//System.out.println("NO"); } System.out.println(sb.toString()); } static void solve() { int n = sc.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); boolean flag = false; long sum = 0; for (int i = 0; i < n && (i + 1) < (n - i - 1); i++) { sum += arr[n - i - 1] - arr[i]; if (sum > arr[i + 1]) { flag = true; break; } } if (flag == true) { System.out.println("YES"); } else { System.out.println("NO"); } // System.out.println(flag == true ? "YES" : "NO"); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
6cf00c8c44c426700fcbf2c630c54ed1
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import static java.lang.System.out; public class app { public static void main(String[] args) { Scanner ds=new Scanner(System.in); int s = ds.nextInt(); for (int j = 0; j < s; j++) { int d = ds.nextInt(); List<Long> gg = new ArrayList<>(); for (int i = 0; i < d; i++) { gg.add(ds.nextLong()); } Collections.sort(gg); int v1 = 1; int v2 = d-1; long b1 = gg.get(0) + gg.get(1); long b2 = gg.get(d-1); boolean g=false; while(v1<v2){ if(b1<b2){ g=true; out.println("yes"); break; } b1+=gg.get(++v1); b2+=gg.get(--v2); } if(g==false){ out.println("no"); } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
8735b18f5dd32fec5df691ba38ee10f6
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; //import javafx.util.*; public class Main { static FastReader in = new FastReader(); 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(); ArrayList<Integer> arr = new ArrayList<>(); for(int i = 0;i < n;i++){ arr.add(sc.nextInt()); } Collections.sort(arr); boolean ans = false; int count_red = 1; long sum_red = arr.get(n-1); int count_blue = 1; long sum_blue = arr.get(0); int tracker = n-2; int i = 1; while(i <= tracker){ if(count_blue <= count_red){ sum_blue += arr.get(i); count_blue++; if(sum_blue < sum_red){ ans = true; break; } i++; }else{ if(sum_blue >= sum_red){ sum_red += arr.get(tracker); count_red++; tracker--; }else{ ans = true; break; } } } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } } 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; Character c; Pair(int x, Character c){ this.x = x; this.c = c; } } 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
46ca2d11494ed0ec58509e01f1103c78
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; //import javafx.util.*; public class Main { 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(); ArrayList<Integer> arr = new ArrayList<>(); for(int i = 0;i < n;i++){ arr.add(sc.nextInt()); } Collections.sort(arr); boolean ans = false; long sum_blue = arr.get(0); long sum_red = 0; for(int i = 1;i <= (n/2);i++){ sum_blue += arr.get(i); sum_red += arr.get(n-i); if(sum_red > sum_blue){ ans = true; break; } } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
49112d2c5815e6272f6378f13ccf7425
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-- > 0){ int a = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < a; i++) { list.add(in.nextInt()); } Collections.sort(list); boolean b = false; int len = list.size()-1; long sum = list.get(0); long sum2 = 0; for (int i = 1; i < a; i++) { sum+=list.get(i); sum2+=list.get(len); // System.out.println(sum+" "+sum2); len--; if(sum < sum2){ b = true; break; } if(a/2 == len) break; } if(b) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
a1a96b7713bf31580febc94e7a2c5903
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Program { static int currMin = Integer.MAX_VALUE; static String result = ""; static Map<String, Integer> mem = new HashMap(); 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 { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } // code FastReader sc = new FastReader(); int t = sc.nextInt(); for(int tt=0; tt<t; tt++) { int n = sc.nextInt(); int[] arr = new int[n]; for(int i=0;i<n;i++) { arr[i] = sc.nextInt(); } find(arr, n); } return; } public static int find(int[] arr, int n) { if(arr.length<3) { System.out.println("NO"); return 0; } int red = arr.length/2; if(arr.length%2==0) red--; int blue = red+1; long sum_blue_curr = FirstKelementsRev(arr, arr.length, blue); long sum_red_curr = FirstKelements(arr, arr.length, red); // System.out.println(sum_red_curr+"XX"+sum_blue_curr); if(sum_red_curr>sum_blue_curr) { System.out.println("YES"); return 0; } System.out.println("NO"); return 0; } public static long FirstKelements(int arr[], int size, int k) { long sum = 0; // Creating Min Heap for given // array with only k elements // Create min heap with priority queue PriorityQueue<Integer> minHeap = new PriorityQueue<>(); for(int i = 0; i < k; i++) { minHeap.add(arr[i]); } // Loop For each element in array // after the kth element for(int i = k; i < size; i++) { // If current element is smaller // than minimum ((top element of // the minHeap) element, do nothing // and continue to next element if (minHeap.peek() > arr[i]) continue; // Otherwise Change minimum element // (top element of the minHeap) to // current element by polling out // the top element of the minHeap else { minHeap.poll(); minHeap.add(arr[i]); } } // Now min heap contains k maximum // elements, Iterate and print Iterator iterator = minHeap.iterator(); while (iterator.hasNext()) { sum=sum+(int)iterator.next(); } return sum; } public static long FirstKelementsRev(int arr[], int size, int k) { long sum = 0; // Creating Min Heap for given // array with only k elements // Create min heap with priority queue PriorityQueue<Integer> minHeap = new PriorityQueue<>(Collections.reverseOrder()); for(int i = 0; i < k; i++) { minHeap.add(arr[i]); } // Loop For each element in array // after the kth element for(int i = k; i < size; i++) { // If current element is smaller // than minimum ((top element of // the minHeap) element, do nothing // and continue to next element if (minHeap.peek() < arr[i]) continue; // Otherwise Change minimum element // (top element of the minHeap) to // current element by polling out // the top element of the minHeap else { minHeap.poll(); minHeap.add(arr[i]); } } // Now min heap contains k maximum // elements, Iterate and print Iterator iterator = minHeap.iterator(); while (iterator.hasNext()) { sum=sum+(int)iterator.next(); } return sum; } public static void print(int[] arr) { for(int i=0;i<arr.length;i++) { System.out.print(arr[i]+" "); } System.out.println(""); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
87e6a41d4bd54969a7767eab972e0b19
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class B { static class Pair { int f;int s; // Pair(){} Pair(int f,int s){ this.f=f;this.s=s;} } static class Fast { BufferedReader br; StringTokenizer st; public Fast() { 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()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArray1(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (IOException e) { e.printStackTrace(); } return str; } } /* static long noOfDivisor(long a) { long count=0; long t=a; for(long i=1;i<=(int)Math.sqrt(a);i++) { if(a%i==0) count+=2; } if(a==((long)Math.sqrt(a)*(long)Math.sqrt(a))) { count--; } return count; }*/ static boolean isPrime(long a) { for (long i = 2; i <= (long) Math.sqrt(a); i++) { if (a % i == 0) return false; } return true; } static void primeFact(int n) { int temp = n; HashMap<Integer, Integer> h = new HashMap<>(); for (int i = 2; i * i <= n; i++) { if (temp % i == 0) { int c = 0; while (temp % i == 0) { c++; temp /= i; } h.put(i, c); } } if (temp != 1) h.put(temp, 1); } static void reverseArray(int a[]) { int n = a.length; for (int i = 0; i < n / 2; i++) { a[i] = a[i] ^ a[n - i - 1]; a[n - i - 1] = a[i] ^ a[n - i - 1]; a[i] = a[i] ^ a[n - i - 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); } public static void main(String args[]) throws IOException { Fast sc = new Fast(); PrintWriter out = new PrintWriter(System.out); int t1 = sc.nextInt(); while (t1-- > 0) { int n=sc.nextInt(); int a[]=sc.readArray(n); sort(a); long s1=0; long s2=0; int f=0; for (int i=0; i<n; i++) { if (i<=n/2) s1+=a[i]; else s2+=a[i]; } if (n%2==0) { s1-=a[n/2]; } if(s2>s1) out.println("YES"); else out.println("NO"); /* long p[]=new long[n+1]; Arrays.fill(p,0); for(int i=1;i<=n;i++) { p[i]=p[i-1]+a[i]; } // long s1=p[1]; // long s2=p[n+1]-p[n]; for(int i=2;i<n+1;i++) { if(i>n-i+2) break; s1=p[i]; s2=p[n]-p[n+1-i]; if(s1<s2) { f=1; break; } } if(f==1) out.println("YES"); else out.println("NO"); /* if((n&1)==0)//even { int idx=n/2+1; long s1=0; long s2=0; for(int i=0;i<idx;i++) s1+=a[i]; for(int i=idx;i<n;i++) s2+=a[i]; if(s2>s1) out.println("YES"); else { long s11=a[0]+a[1]; long s12=a[n-1]; if(s12>s11) out.println("YES"); else out.println("NO"); } } else { int idx=(n+1)/2; long s1=0; long s2=0; for(int i=0;i<idx;i++) s1+=a[i]; for(int i=idx;i<n;i++) s2+=a[i]; if(s2>s1) out.println("YES"); else { long s11=a[0]+a[1]; long s12=a[n-1]; if(s12>s11) out.println("YES"); else out.println("NO"); } }*/ } out.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
5e763dea05b00be0c5a6772483cb7e08
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class MyClass { static FastReader in=new FastReader(); static final Random random=new Random(); static long mod=1000000007L; public static void main (String[] args) throws java.lang.Exception { int t=in.nextInt(); StringBuilder res=new StringBuilder(); while(t-->0) solve(); } static void solve() { int n = in.nextInt(); ArrayList<Integer> a = new ArrayList<>(); for(int i=0; i<n; i++) a.add(in.nextInt()); Collections.sort(a); long sum = a.get(0); int j = n-1; boolean flag = false; for(int i=1; i<=n/2; i++) { sum += a.get(i); sum -= a.get(j); if(sum<0) { System.out.println("YES"); return; } j--; } if(!flag && sum<0) System.out.println("YES"); else System.out.println("NO"); } static int max(int a, int b) { if(a<b) return b; return a; } static void ruffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static < E > void print(E res) { System.out.println(res); } static int gcd(int a,int b) { if(b==0) { return a; } return gcd(b,a%b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int abs(int a) { if(a<0) return -1*a; return a; } 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 [] readintarray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++)res[i] = nextInt(); return res; } long [] readlongarray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
a30ab6a44d9745a9fc1e3e16ef168027
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class QualityVQuantity { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int size = sc.nextInt(); ArrayList<Integer> list=new ArrayList<>(); for (int i = 0; i < size; i++) list.add(sc.nextInt()); Collections.sort(list); long a = list.get(0) +list.get(1); long b = list.get(size - 1); int i = 2; int j = size - 2; while (i < size && j > -1 && a >= b) { a += list.get(i); b += list.get(j); i += 1; j -= 1; } System.out.println(a<b?"YES":"NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
f663dde26bee5a8084565282c1696b3c
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class QualityVQuantity { public static void main(String[] args) throws IOException { FastReader fr=new FastReader(); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); int t = fr.nextInt(); while (t-- > 0) { int size =fr.nextInt(); ArrayList<Integer> list=new ArrayList<>(); for (int i = 0; i < size; i++) list.add( fr.nextInt()); Collections.sort(list); long a = list.get(0)+ list.get(1); long b = list.get(size - 1); int i = 2; int j = size - 2; while (i < size && j > -1 && a >= b) { a += list.get(i); b += list.get(j); i += 1; j -= 1; } bw.write(a<b?"YES\n":"NO\n"); bw.flush(); } bw.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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
323dd65fde383c54245307d820fd7880
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; import java.io.*; public class CodeForces{ public static void main(String[] args) throws FileNotFoundException { FastScanner fs = new FastScanner(); int t = fs.nextInt(); while(t-- > 0) { int n = fs.nextInt(); Long[] a = new Long[n]; for(int i = 0; i < n; i++) { a[i] = fs.nextLong(); } Arrays.sort(a); long red = 0, blue = a[0]; boolean flag = false; int i = 1, j = n-1; while(i < j) { red += a[j]; blue += a[i]; i++; j--; if(red > blue) { flag = true; break; } } if(flag) { System.out.println("YES"); }else { System.out.println("NO"); } } } 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[] readArrayLong(int n) { long[] a=new long[n]; for(int i = 0; i < n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
5dffcf9438b2dc4ddba1672e24abd62e
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; public class QualityVsQuantity { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int tests = sc.nextInt(); for(int test = 0; test < tests; test++){ int n = sc.nextInt(); Integer[] seqs = new Integer[n]; for(int i = 0; i < n;i++){ seqs[i] = sc.nextInt(); } Arrays.sort(seqs); long redSum = seqs[n-1], blueSum = seqs[0] + seqs[1]; int i = 2, j = n - 2; boolean found = false; while(i < j){ if(redSum > blueSum){ found = true; break; } redSum += seqs[j]; blueSum += seqs[i]; i++; j--; } if(found || redSum > blueSum) out.println("YES"); else out.println("NO"); } // Start writing your solution here. ------------------------------------- /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String int result = 3*n; out.println(result); // print via PrintWriter */ // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int 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
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
cd2582b3561a8cd8286d4b2610b3b565
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.awt.image.ImageProducer; import java.util.*; public class Solution { static boolean prime[] = new boolean[1000001]; static Set<Long> cubes=new HashSet<>(); static { long N = 1000000000000L; // // // for(int i=1;i*i<=n;i++) // { // long x=i*i; // set.add(x); // } for (long i = 1; i * i * i <= N; i++) { cubes.add(i * i * i); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n= sc.nextInt(); ArrayList<Long > al = new ArrayList<>(); for(int i=0 ; i< n ; i++) { al.add( sc.nextLong()); } Collections.sort(al); long sumblue =al.get(0); long sumred = 0; int c=0; for(int i=1 ; i<=n/2 ;i++) { sumblue+=al.get(i); sumred+=al.get(n-i); if(sumred > sumblue) { System.out.println("YES"); c++; break; } } if(c==0) System.out.println("NO"); c=0; } } // public static int[] reverse(int arr[],int start,int end) // { // for(int i=start;i<=end;i++) // { // int temp=arr[i]; // arr[i]=arr[i+1]; // arr[i+1]=temp; // } // return arr; // } static void sieveOfEratosthenes(int n) { for(int i=0;i<=n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers // for(int i = 2; i <= n; i++) // { // if(prime[i] == true) // System.out.print(i + " "); // } } public static boolean isPrime(int n) { for(int i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
313c4b3f01bd42b62ae1f0a9d822c5be
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Ac { static int MOD = 998244353; static int MAX = (int)1e8; static Random rand = new Random(); static FastReader in = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int t = i(); // out.println(); // out.println(); // randArr(10, 10, 10); while (t-- > 0){ // int[] ans = sol(); // for (int i = 0; i < ans.length; i++){ // out.print(ans[i] + " "); // } // out.println(); boolean ans = sol(); if (ans){ out.println("YES"); }else{ out.println("NO"); } } out.flush(); out.close(); } static boolean sol(){ int n = i(); long[] arr = inputL(n); shuffle(arr, n); Arrays.sort(arr); int mid = n >> 1; long b = 0, r = 0; if (n % 2 == 0){ for (int i = 0; i < mid; i++){ b += arr[i]; } for (int i = mid + 1; i < n; i++){ r += arr[i]; } }else{ for (int i = 0; i <= mid; i++){ b += arr[i]; } for (int i = mid + 1; i < n; i++){ r += arr[i]; } } // out.println(r + " " + b); return r > b; } static void randArr(int num, int n, int val){ for (int i = 0; i < num; i++){ int len = rand.nextInt(n + 1); System.out.println(len); for (int j = 0; j < len; j++){ System.out.print(rand.nextInt(val) + 1 + " "); } System.out.println(); } } static void shuffle(long a[], int n){ for (int i = 0; i < n; i++) { int t = (int)Math.random() * a.length; long x = a[t]; a[t] = a[i]; a[i] = x; } } static int gcd(int a, int b){ return a % b == 0 ? a : gcd(b, a % b); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static double d() { return in.nextDouble(); } static String s(){ return in.nextLine(); } static int[] inputI(int n) { int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = i(); } return nums; } static long[] inputL(int n) { long[] nums = new long[n]; for (int i = 0; i < n; i++) { nums[i] = l(); } return nums; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
576aabcaea81e28c214c207466f2d36f
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Ac { static int MOD = 998244353; static int MAX = (int)1e8; static Random rand = new Random(); static FastReader in = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int t = i(); // out.println(); // out.println(); // randArr(10, 10, 10); while (t-- > 0){ // int[] ans = sol(); // for (int i = 0; i < ans.length; i++){ // out.print(ans[i] + " "); // } // out.println(); boolean ans = sol(); if (ans){ out.println("YES"); }else{ out.println("NO"); } } out.flush(); out.close(); } static boolean sol(){ int n = i(); int[] arr = inputI(n); shuffle(arr, n); Arrays.sort(arr); // for (int i : arr){ // out.print(i + " "); // } // out.println(); int mid = n >> 1; long b = 0, r = 0; int l = 1, rr = n - 1; b += 0; r += arr[0]; while (l < rr){ b += arr[rr--]; r += arr[l++]; if (b > r){ return true; } } // out.println(r + " " + b); return false; } static void randArr(int num, int n, int val){ for (int i = 0; i < num; i++){ int len = rand.nextInt(n + 1); System.out.println(len); for (int j = 0; j < len; j++){ System.out.print(rand.nextInt(val) + 1 + " "); } System.out.println(); } } static void shuffle(int a[], int n){ for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index int x = a[t]; a[t] = a[i]; a[i] = x; // Arrays.sort(a); } } static int gcd(int a, int b){ return a % b == 0 ? a : gcd(b, a % b); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static double d() { return in.nextDouble(); } static String s(){ return in.nextLine(); } static int[] inputI(int n) { int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } return nums; } static long[] inputL(int n) { long[] nums = new long[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextLong(); } return nums; } static Integer[] arrI(int n) { Integer[] nums = new Integer[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } return nums; } static long[] arrl(int n) { long nums[] = new long[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextLong(); } return nums; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
a1f894d9ecc85899ecaffe04f152711e
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
//package CodingRound; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class Div774 { static long mod = 1000000007; static long power(long x, long y) { long res = 1; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-- != 0) { int n = sc.nextInt(); int a[] = new int [n]; for(int i = 0 ;i < n ; i++) { a[i] = sc.nextInt(); } ArrayList<Integer> l = new ArrayList<>(); for(int num: a) { l.add(num); } Collections.sort(l); for(int i = 0 ; i < n ; i++) { a[i] = l.get(i); } int sPtr = 2; int ePtr = n-2; long sSum = a[0] + a[1]; long eSum = a[n-1]; boolean isAns = false; while(sPtr < ePtr) { // System.out.println(sSum + " " + eSum); if(sSum < eSum) { isAns = true; break; }else { sSum += a[sPtr]; eSum += a[ePtr]; sPtr++; ePtr--; } } if(sSum < eSum) { isAns = true; } System.out.println(isAns ? "Yes": "No"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
f346601359eeb9d4559a0c76222a5880
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.io.*; import java.util.*; import java.util.Collections; public class cp{ //1.) program to find all factor of all number till n public static void findAllFactor(int[][] div,int n){ int divCnt[] = new int[n+1];int ptr[] = new int[n+1];for(int i = n; i >= 1; --i) {for(int j = i; j <= n; j += i) divCnt[j]++;} for(int i = 1; i <= n; ++i) div[i] = new int[divCnt[i]];for(int i = n; i >= 1; --i) {for(int j = i; j <= n; j += i) div[j][ptr[j]++] = i;} } public static void main(String[] args){ Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t-->0){ int n=scn.nextInt(); ArrayList<Long> list=new ArrayList<>(); for(int i=0;i<n;i++){ list.add(scn.nextLong()); } Collections.sort(list); long red=list.get(n-1),blue=list.get(0)+list.get(1); int i=2,j=n-2,id=0; while(i<=j){ if(red>blue){ System.out.println("YES"); id=1; break; }else{ if(i!=j){ red+=list.get(j);blue+=list.get(i); }else{ blue+=list.get(i); } } i++;j--; } if(id==0&&red>blue){ System.out.println("YES"); }else if(id==0){ System.out.println("NO"); } } scn.close(); } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
b606d1c51c448d5b03f6b0a6a761b55d
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
// package CF.R774; import java.io.*; import java.util.*; import java.math.*; public class B { static Random random = new Random(); static long[] tmp = new long[200010]; public static void main(String[] args) { FastReader in = new FastReader(); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = in.nextLong(); // shulle(arr); // Arrays.sort(arr); mergeSort(arr, 0, n - 1); long red = 0, blue = arr[0]; boolean ok = false; for (int i = 1, j = n - 1; i < j; i++, j--) { red += arr[j]; blue += arr[i]; if (red > blue) { ok = true; break; } } System.out.println(ok ? "YES" : "NO"); } } public static void mergeSort(long[] arr, int l, int r) { if (l >= r) return; int mid = l + r >> 1; mergeSort(arr, l, mid); mergeSort(arr, mid + 1, r); int i = l, j = mid + 1; for (int k = l; k <= r; k++) { tmp[k] = arr[k]; } for (int k = l; k <= r; k++) { if (i == mid + 1) { arr[k] = tmp[j++] ; } else if (j == r + 1 || tmp[i] <= tmp[j]) { arr[k] = tmp[i++]; } else { arr[k] = tmp[j++]; } } } public static void shulle(long[] arr) { for (int i = 0; i < arr.length; i++) { int idx = random.nextInt(arr.length); long t = arr[i]; arr[i] = arr[idx]; arr[idx] = t; } } static class FastReader { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
62c06b98958ca26d3c2567dfd726f342
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
// package CF.R774; import java.io.*; import java.util.*; import java.math.*; public class B { static Random random = new Random(); public static void main(String[] args) { FastReader in = new FastReader(); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = in.nextLong(); shulle(arr); Arrays.sort(arr); long red = 0, blue = arr[0]; boolean ok = false; for (int i = 1, j = n - 1; i < j; i++, j--) { red += arr[j]; blue += arr[i]; if (red > blue) { ok = true; break; } } System.out.println(ok ? "YES" : "NO"); } } public static void shulle(long[] arr) { for (int i = 0; i < arr.length; i++) { int idx = random.nextInt(arr.length); long t = arr[i]; arr[i] = arr[idx]; arr[idx] = t; } } static class FastReader { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
ec13a66b0dd2143db0032ee1aec76dff
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int o = 0; o < t; o++) { int n = sc.nextInt(); Integer[] arr = new Integer[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); long sumL = arr[0] + arr[1]; long sumR = arr[n - 1]; int r = n - 2; for (int l = 2; l < r && sumL >= sumR; l++, r--) { sumL += arr[l]; sumR += arr[r]; } System.out.println(sumR > sumL ? "YES" : "NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output
PASSED
4523bfc42fe6be29c93d64650276f6db
train_110.jsonl
1646408100
$$$ \def\myred#1{\color{red}{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $$$ $$$\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}}$$$You are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\RED$$$ or $$$\BLUE$$$ (but not both), or leave it unpainted. For a color $$$c$$$, $$$\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.For example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\myblue{2}, 8, \myred{6}, \myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\text{Sum}(\RED)=6$$$, $$$\text{Sum}(\BLUE)=2+3=5$$$, $$$\text{Count}(\RED)=1$$$, and $$$\text{Count}(\BLUE)=2$$$.Determine if it is possible to paint the sequence so that $$$\text{Sum}(\RED) &gt; \text{Sum}(\BLUE)$$$ and $$$\text{Count}(\RED) &lt; \text{Count}(\BLUE)$$$.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int o = 0; o < t; o++) { int n = sc.nextInt(); ArrayList<Integer> arr = new ArrayList<>(n); for (int i = 0; i < n; i++) { arr.add(sc.nextInt()); } Collections.sort(arr); long sumL = arr.get(0) + arr.get(1); long sumR = arr.get(n - 1); int r = n - 2; for (int l = 2; l < r && sumL >= sumR; l++, r--) { sumL += arr.get(l); sumR += arr.get(r); } System.out.println(sumR > sumL ? "YES" : "NO"); } } }
Java
["4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000"]
2 seconds
["NO\nYES\nNO\nNO"]
NoteIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myblue{1},\myblue{2},\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$, but $$$\text{Sum}(\RED)=3 \ngtr \text{Sum}(\BLUE)=3$$$. So, this is not a possible way to paint the sequence.In the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\text{Sum}(\RED)=6 &gt; \text{Sum}(\BLUE)=5$$$ and $$$\text{Count}(\RED)=1 &lt; \text{Count}(\BLUE)=2$$$.In the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\myred{3},\myred{5},\myblue{4}, \myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\text{Sum}(\RED) = 8 &gt; \text{Sum}(\BLUE) = 6$$$ but $$$\text{Count}(\RED) = 2 \nless \text{Count}(\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.In the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.
Java 8
standard input
[ "brute force", "constructive algorithms", "greedy", "sortings", "two pointers" ]
4af59df1bc56ca8eb5913c2e57905922
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\le n\le 2\cdot 10^5$$$) — the length of the given sequence. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the given sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
800
For each test case, print YES if it is possible to paint the given sequence satisfying the above requirements, and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
standard output