exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
0fbf180c47ead9b08d67ae642c9b48a5
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; public class even_subset_problem { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T=in.nextInt(); while(T-->0) { int n=in.nextInt(); int arr[]=new int[n]; boolean bool=false; int even=0; ArrayList<Integer> indices = new ArrayList<Integer>(); for(int i=0;i<n;i++) { arr[i]=in.nextInt(); if(arr[i]%2==0) { bool=true; even=i+1; } else { indices.add(i); } } if(bool==true) { System.out.println("1"); System.out.println(even); } else { int till=indices.size()/2; System.out.println(till==0 ? "-1":till*2); for(int i=0;till>0;till--,i=i+2) { int a=indices.get(i); int b=indices.get(i+1); System.out.println((a+1)+" "+(b+1)); } } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
05ba2e9e808929c4727061342b7a07bd
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.StringTokenizer; public class Solution{ static long mod = 998244353L; public static void main(String[] args) throws Exception{ FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int tt = fs.nextInt(); while(tt-->0) { int n = fs.nextInt(); int[] a = fs.readArray(n); ArrayList<Integer> odd = new ArrayList<Integer>(); int ans = -1; for(int i=0;i<n;i++) { if((a[i]&1)==0) { ans = i; } else { odd.add(i); } } if(ans!=-1) { out.println(1); out.println(ans+1); continue; } if(odd.size()<2) { out.println(-1); continue; } out.println(2); out.println((odd.get(0)+1)+" "+ (odd.get(1)+1)); } out.close(); } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next(){ while(!st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt(){ return Integer.parseInt(next()); } public int[] readArray(int n){ int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } public long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
2e442720c796df3edd3caa5c90210e9e
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author unknown */ 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); AEvenSubsetSumProblem solver = new AEvenSubsetSumProblem(); solver.solve(1, in, out); out.close(); } static class AEvenSubsetSumProblem { public void solve(int testNumber, InputReader in, OutputWriter out) { int ntc = in.nextInt(); while ((ntc--) > 0) { int n = in.nextInt(); int[] arr = in.nextIntArray(n); int oddCount = 0; int fp = -1; int sp = -1; boolean ok = false; for (int i = 0; i < n; i++) { if (arr[i] % 2 == 0) { out.println(1); out.println(i + 1); ok = true; break; } else { if (fp == -1) { fp = i; } else { sp = i; } } } if (ok) { continue; } if (fp != -1 && sp != -1) { out.println(2); out.println(fp + 1, sp + 1); } else { out.println(-1); } } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); 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(); } public void println(long i) { writer.println(i); } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
1265ab361c26a76b445accfb59bec352
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.Scanner; public class EvenSubsetSumProblem { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 0; i < t; i++) { int n = scan.nextInt(); int[] arr = new int[n]; int count = 0; for (int j = 0; j < n; j++) { arr[j] = scan.nextInt(); } for (int j = 0; j < n; j++) { if (arr[j] % 2 == 0) { System.out.println(1); System.out.println(j + 1); count++; break; } } if (count == 0) { for (int j = 0; j < n; j++) { for (int z = j + 1; z < n; z++) { if ((arr[j] + arr[z]) % 2 == 0) { System.out.println(2); System.out.println((j + 1) + " " + (z + 1)); count++; break; } } if (count > 0) { break; } } } if (count > 0) { continue; } else { System.out.println(-1); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
21621271f95948f70a80a073c23a2081
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
//package deloar; import java.util.Scanner; public class Deloar { public static void main(String[] args) { Scanner input = new Scanner(System.in); int t=input.nextInt(); for(int i=0;i<t;i++){ int n=input.nextInt(); int a[]=new int[1001]; for(int j=0;j<n;j++){ a[j]=input.nextInt(); } int f=0,ind=0; for(int k=0;k<Math.min(n, 3);k++){ if(a[k]%2==0){ f=1; ind=k+1; break; } } if(n==1 && a[0]%2==0){ System.out.println(1); System.out.println(1); } else if(n==1 && a[0]%2==1){ System.out.println(-1); } else if(f==1){ System.out.println(1); System.out.println(ind); } else{ System.out.println(2); System.out.println(1+" "+2); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
0889a0ffefef10d28ffa322538c65ec9
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0) { int t=sc.nextInt(); int[] x=new int[t]; for(int i=0;i<t;i++) { x[i]=sc.nextInt(); } int q=0,a=0,b=0; for(int i=0;i<t;i++) { if(x[i]%2==0) { System.out.println(1); System.out.println(i+1); break; }else { if(q==0) { a=i+1; q++; }else { b=i+1; System.out.println(2); System.out.println(a+" "+b); break; } } if(i==t-1) System.out.println(-1); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
cfb04cf885630584c4392b1cea37dea9
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.*; public class A1323 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub new A1323(); } A1323() throws IOException { in = new StreamTokenizer(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int t = nextInt(); for(int h = 0;h<t;h++) { int n = nextInt(); int[] a = new int[n]; for(int i = 0;i<n;i++) a[i] = nextInt(); int f = 0, s = 0; boolean ans = false; for(int i = 0;i<n;i++) { if(a[i]==0) continue; if(a[i]%2==0) { ans = true; out.println(1); out.println(i+1); break; } else { if(f!=0){ s = i+1; ans = true; out.println(2); out.println(f+" "+s); break; } else f = i+1; } } if(!ans) out.println(-1); } out.close(); } StreamTokenizer in; PrintWriter out; int nextInt() throws IOException { in.nextToken(); return (int) in.nval; } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
5ff2621f308103aed447ffc2faecb38e
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*;import java.io.*;import java.math.*; public class Main { public static void process()throws IOException { int n=ni(),arr[]=new int[n+1]; for(int i=1;i<=n;i++) arr[i]=ni(); for(int i=1;i<=n;i++){ if(arr[i]%2 == 0){ pn(1); pn(i); return; } } int idx1=0,idx2=0; for(int i=1;i<=n;i++) if((arr[i] & 1)==1){ idx1=i; break; } for(int i=idx1+1;i<=n;i++){ if((arr[i] & 1)==1){ idx2=i; break; } } if(idx1==0 || idx2==0){ pn(-1); return; } pn(2); pn(idx1+" "+idx2); } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc=new AnotherReader(); boolean oj = true; oj = System.getProperty("ONLINE_JUDGE") != null; if(!oj) sc=new AnotherReader(100); long s = System.currentTimeMillis(); int t=ni(); while(t-->0) process(); out.flush(); if(!oj) System.out.println(System.currentTimeMillis()-s+"ms"); System.out.close(); } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);System.out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} static boolean multipleTC=false; ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
ca79ceb377b6838bfa05e5e7a0529202
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t>0){ int n=Integer.parseInt(br.readLine()); String[] s=br.readLine().trim().split(" "); int a=0,b=0,c=0,x=0; while (x<n){ if (Integer.parseInt(s[x])%2==0){ System.out.println("1"); System.out.println(x+1); c=5; break; } else if (Integer.parseInt(s[x])%2!=0 && c==0){ a=x+1; c++; } else if (Integer.parseInt(s[x])%2!=0 && c==1){ System.out.println("2"); System.out.println(a+" "+(x+1)); c++; break; } x++; } if(c==1){ System.out.println("-1"); } t--; } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
c9360aabf381663d59b9783e8eaf2f01
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; import java.math.*; import java.io.*; public class 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 in = new FastReader(); int t = in.nextInt(); while(t-- != 0){ int n = in.nextInt(); int k = 0; String res = ""; for(int i = 0; i < n; i++){ int a = in.nextInt(); if(a % 2 == 0){ k++; res += (i + 1) + " "; } } if(k != 0){ System.out.println(k); System.out.println(res); }else if(n > 1){ System.out.println("2"); System.out.println("1 2"); }else{ System.out.println("-1"); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
cfab26a1769fe71507dab4beb18ecc0c
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; public class A { static Scanner sc = new Scanner(System.in); static InputStreamReader stream = new InputStreamReader(System.in); static BufferedReader br = new BufferedReader(stream); public static void main(String[] args) throws IOException{ int test = sc.nextInt(); while(test-->0) { int n = sc.nextInt(); int[] a = readArraylinesc(n); boolean found = false; for(int i=0 ; i<n ; i++) { if(a[i]%2==0) { found=true; System.out.println(1 +"\n" + (i+1)); break; } } if(!found) { if(n==1) System.out.println(-1); else System.out.println(2 + "\n1 2"); } } } public static int pow(int n, int k) { int pow = 0; while(n%k==0 && n!=1) { n/=k; pow++; } if(n==1) return pow; else return -1; } //BufferedReader Input functions public static int readInt() throws IOException{ return (Integer.parseInt(br.readLine())); } public static int[] readArray(int n) throws IOException{ int[] a = new int[n]; for(int i=0 ; i<n ; i++) { a[i]= readInt(); } return a; } public static int[] readArrayline(int n) throws IOException{ int[] a = new int[n]; String[] s = br.readLine().split(" "); for(int i=0 ; i<n ; i++) { a[i]= Integer.parseInt(s[i]); } return a; } public static int[] readArraylinesc(int n){ int[] a = new int[n]; for(int i=0 ; i<n ; i++) { a[i]= sc.nextInt(); } return a; } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
373b005e6ba0e455d0777c80c3a85f42
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ // QAQAQYSYIOIWIN // outputCopy // 4 // inputCopy // QAQQQZZYNOIWIN // outputCopy // 3 public class Main { static PrintWriter out; static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); } 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; } } // SHIVAM GUPTA : // ASCII = 48 + i ; // SHIVAM GUPTA : public static int min(int a ,int b , int c, int d) { int[] arr = new int[4] ; arr[0] = a; arr[1] = b ; arr[2] = c; arr[3] = d; Arrays.sort(arr) ; return arr[0]; } public static int max(int a ,int b , int c, int d) { int[] arr = new int[4] ; arr[0] = a; arr[1] = b ; arr[2] = c; arr[3] = d; Arrays.sort(arr) ; return arr[3]; } static int sieve = 1000000 ; static boolean[] prime = new boolean[sieve + 1] ; public static void sieveOfEratosthenes() { // TRUE == prime // FALSE == COMPOSITE // FALSE== 1 for(int i=0;i< sieve + 1;i++) prime[i] = true; for(int p = 2; p*p <= sieve; p++) { if(prime[p] == true) { for(int i = p*p; i <= sieve; i += p) prime[i] = false; } } } public static String reverse(String input) { String op = "" ; for(int i = 0; i < input.length() ; i++ ) { op = input.charAt(i)+ op ; } return op ; } public static int[] sortI(int[] arr) { Arrays.sort(arr) ; return arr ; } public static int[] sortD(int[] arr) { Arrays.sort(arr) ; int i =0 ; int j = arr.length -1 ; while( i < j) { int temp = arr[i] ; arr[i] =arr[j] ; arr[j] = temp ; i++ ; j-- ; } return arr ; } public static boolean isPossibleTriangle(int a ,int b , int c) { if( a + b > c && c+b > a && a +c > b) { return true ; } return false ; } public static int gcd(int a, int b ) { if(b==0)return a ; else return gcd(b,a%b) ; } public static int lcm(int a, int b ,int c , int d ) { int temp = lcm(a,b , c) ; int ans = lcm(temp ,d ) ; return ans ; } public static int lcm(int a, int b ,int c ) { int temp = lcm(a,b) ; int ans = lcm(temp ,c) ; return ans ; } public static int lcm(int a , int b ) { int gc = gcd(a,b); return (a*b)/gc ; } static boolean isPrime(int n) { if(n==1) { return false ; } boolean ans = true ; for(int i = 2; i*i <= n ;i++) { if(n% i ==0) { ans = false ;break ; } } return ans ; } static boolean isPowerOfTwo(int n) { if(n==0) return false; if(((n ) & (n-1)) == 0 ) return true ; else return false ; } public static int countDigit(long n) { return (int)Math.floor(Math.log10(n) + 1); } static final int MAXN = 100001; static int spf[] = new int[MAXN]; static void sieve() { spf[1] = 1; for (int i=2; i<MAXN; i++) spf[i] = i; for (int i=4; i<MAXN; i+=2) spf[i] = 2; for (int i=3; i*i<MAXN; i++) { if (spf[i] == i) { for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; } } } // The above code works well for n upto the order of 10^7. // Beyond this we will face memory issues. // Time Complexity: The precomputation for smallest prime factor is done in O(n log log n) // using sieve. // Where as in the calculation step we are dividing the number every time by // the smallest prime number till it becomes 1. // So, let’s consider a worst case in which every time the SPF is 2 . // Therefore will have log n division steps. // Hence, We can say that our Time Complexity will be O(log n) in worst case. static Vector<Integer> getFactorization(int x) { Vector<Integer> ret = new Vector<>(); while (x != 1) { ret.add(spf[x]); x = x / spf[x]; } return ret; } public static void main (String[] args) throws java.lang.Exception { FastReader scn = new FastReader() ; int t = scn.nextInt() ; for(int k = 1; k<= t ; k++) { int n= scn.nextInt() ; // ArrayList<Integer> list = new ArrayList<() ; int val = -1 ; for(int i = 0 ; i < n ; i++) { int temp = scn.nextInt() ; if(temp% 2 ==0) { val = i+1 ; } } if(val != -1) { out.println(1) ; out.println(val) ; } else{ if(n==1) { out.println(-1) ; } else{ out.println(2) ; out.println(1 +" " + 2 ) ; } } } out.flush() ; } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
3a3f65cb669a60d21c8aaaf6f016f6a8
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.Arrays; import java.util.Scanner; public class Evensubsetsumprblm { public static void main(String[] args) { Scanner input=new Scanner(System.in); int q; q=input.nextInt(); for (int k = 0; k <q; k++) { int n,c=0,j=0; n=input.nextInt(); int[] a=new int[n];int[] b=new int[2]; for (int i = 0; i < a.length; i++) { a[i]=input.nextInt(); } for (int i = 0; i <a.length; i++) { if(a[i]%2==0){ System.out.println("1");System.out.println(i+1); j++; break; }else if(n==1 && a[i]%2!=0){ System.out.println("-1"); j++; break; } } if(j==0){ System.out.println("2"); System.out.println("1 2"); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
b6e331a0a1cdd47d6747dd29165a76cf
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.Scanner; public class two { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); for(int i=0;i<n;i++) { int k = sc.nextInt(); int arr[]=new int[k]; int first=-1,second=Integer.MAX_VALUE; for(int j=0;j<k;j++) { arr[j]=sc.nextInt(); if(first==-1 && arr[j]%2!=0) { first=j+1; } else if(arr[j]%2!=0) { second=j+1; } } int flag=0; for(int j=0;j<k;j++) { if(arr[j]%2==0 && j<second) { flag=1; System.out.println(1); System.out.println(j+1); break; } } if(flag==0 && (first==Integer.MAX_VALUE || second==Integer.MAX_VALUE)) { System.out.println(-1); } else if(flag!=1) { System.out.println(2); System.out.println(first+" "+second); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
600c4f0ec89ebc7ab600f45e46ea1d3c
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
/*input 3 3 1 4 3 1 15 2 3 5 */ import java.math.*; import java.io.*; import java.util.*; public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static Reader sc=new Reader(); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String args[])throws IOException { /* * For integer input: int n=inputInt(); * For long input: long n=inputLong(); * For double input: double n=inputDouble(); * For String input: String s=inputString(); * Logic goes here * For printing without space: print(a+""); where a is a variable of any datatype * For printing with space: printSp(a+""); where a is a variable of any datatype * For printing with new line: println(a+""); where a is a variable of any datatype //all four int[] dr = { 1, 0, -1, 0 }; int[] dc = { 0, 1, 0, -1 }; */ int t=inputInt(); while(t-- >0) { int n=inputInt(); int even=0,pos=-1; int odd=0,pos1=-1 , pos2=-1; for(int i=0;i<n;i++) { int x=inputInt(); if(x%2==0) { even=1; pos=i+1; } else { odd++; if(pos1==-1) { pos1=i+1; } else { if(pos2==-1) { pos2=i+1; } } } } if(even==1) { println(1+""); println(pos+""); } else if(odd>=2) { println(2+""); println(pos1+" "+pos2+""); } else { println("-1"); } } bw.flush(); bw.close(); } public static int modulo(int x,int N) { return (x % N + N) %N; } public static long lcm(long a,long b) { return a / gcd(a, b) * b; } public static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } public static int inputInt()throws IOException { return sc.nextInt(); } public static long inputLong()throws IOException { return sc.nextLong(); } public static double inputDouble()throws IOException { return sc.nextDouble(); } public static String inputString()throws IOException { return sc.readLine(); } public static void print(String a)throws IOException { bw.write(a); } public static void printSp(String a)throws IOException { bw.write(a+" "); } public static void println(String a)throws IOException { bw.write(a+"\n"); } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
2fe60629b1425e7ccd1a984b376b08e7
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main (String[] args) throws java.lang.Exception { FastReader fr = new FastReader(); int test_case = fr.nextInt(); while(test_case--!=0){ int n = fr.nextInt(); int arr[] = new int[n]; for(int i=0;i<n;i++){ arr[i] = fr.nextInt(); } int even = 0; int odd = 0; for(int i=0;i<n;i++){ if(arr[i]%2 == 0){ even++; } else{ odd++; } } if(!(even != 0 || odd > 1)){ System.out.println(-1); } else if(even >0){ System.out.println(even); StringBuilder sb = new StringBuilder(); for(int i=0;i<n;i++){ if(arr[i]%2 == 0){ sb.append(i+1); sb.append(" "); } } System.out.println(sb); } else{ System.out.println(2); System.out.println(1+" "+2); } } } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static int lcm(int a, int b){ int g = gcd(a,b); return a*(b/g); } static int exponentMod(int A, int B, int C) { if (A == 0) return 0; if (B == 0) return 1; long y; if (B % 2 == 0) { y = exponentMod(A, B / 2, C); y = (y * y) % C; } else { y = A % C; y = (y * exponentMod(A, B - 1, C) % C) % C; } return (int)((y + C) % C); } static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
88a02aca5e8c19b76da67cdb3c87af7d
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t, n; t = sc.nextInt(); while(t-- > 0){ n = sc.nextInt(); boolean found = false; int c = 0; int[] a = new int[n]; for(int i = 0; i < n; ++i){ a[i] = sc.nextInt(); if(a[i]%2 == 0){ found = true; c = i+1; } } if(found){ System.out.println(1); System.out.println(c); }else{ if(n == 1){ System.out.println(-1); }else{ System.out.println(2); System.out.println(1 + " " + 2); } } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
4495487c6d932bfeaede55bedd043ba2
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
//package Codeforces; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t; t=sc.nextInt(); while(t-->0) { int n; n=sc.nextInt(); int arr[]=new int[n]; int odd=0,even=0; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); if(arr[i]%2==0)even++; else odd++; } if(even>0) { System.out.println(even); for(int i=0;i<n;i++) { if(arr[i]%2==0) { System.out.print((i+1)+" "); } } System.out.println(); } else if(odd>=2) { System.out.println(2); int k=0; for(int i=0;i<n;i++) { if(arr[i]%2==1) { k++; System.out.print((i+1)+" "); } if(k==2)break; } System.out.println(); } else { System.out.println(-1); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
ef38db3652814e802f6ef6b3d64dab50
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.*; import java.math.*; import java.util.*; public class test { /* * array list * * ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers * * BigInteger a=new BigInteger(); BigInteger b=new BigInteger(); * * hash map * * HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int * i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) { * hm.put(ar[i],1); } else { hm.put(ar[i],++c); } } * * while loop * * int t=sc.nextInt(); while(t>0) { t--; } * * array input * * int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length; * i++) { ar[i] = sc.nextInt(); } */ 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 first, second; public Pair(int first, int second) { this.first = first; this.second = second; } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } private static final Scanner sc = new Scanner(System.in); private static final FastReader fs = new FastReader(); private static final OutputWriter op = new OutputWriter(System.out); static int[] getintarray(int n) { int ar[] = new int[n]; for (int i = 0; i < n; i++) { ar[i] = fs.nextInt(); } return ar; } static long[] getlongarray(int n) { long ar[] = new long[n]; for (int i = 0; i < n; i++) { ar[i] = fs.nextLong(); } return ar; } static int[][] get2darray(int n, int m) { int ar[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ar[i][j] = fs.nextInt(); } } return ar; } static Pair[] getpairarray(int n) { Pair ar[] = new Pair[n]; for (int i = 0; i < n; i++) { ar[i] = new Pair(fs.nextInt(), fs.nextInt()); } return ar; } static void printarray(int ar[]) { System.out.println(Arrays.toString(ar)); } static boolean checkmyArray(int[] ar) { int temp = ar[0]; for (int i = 1; i < ar.length; i++) { if (temp != ar[i]) return false; } return true; } public static void main(String[] args) { int t = fs.nextInt(); // int t = 1; while (t > 0) { int n = fs.nextInt(); int ar[] = getintarray(n); int evens = 0; int odd = 0; int evenidex = 0; int o1 = 0; int o2 = 0; boolean rs = false; for (int i = 0; i < ar.length - 1; i++) { if (ar[i] % 2 == 0) { evens++; evenidex = i; rs = true; break; } else { if (ar[i] % 2 != 0 && ar[i + 1] % 2 != 0) { o1 = i; o2 = i + 1; rs = true; break; } } } if (ar[n - 1] % 2 == 0) { evens++; evenidex = n - 1; rs=true; } if (rs) { if (evens != 0) { System.out.println("1"); System.out.println(evenidex + 1); } else { System.out.println("2"); System.out.println((o1 + 1) + " " + (o2 + 1)); } } else System.out.println(-1); t--; } } }/* * 1 5 -2 -3 -1 -4 -6till here */
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
7a1ab2e604731c4cb932168bc6e2cf1d
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.sql.Array; import java.sql.SQLOutput; 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; } } //************************************************************ $ VENI,VIDI,VICI $ *********************************************************************\\ public static void main(String[] args) { FastReader f = new FastReader(); int t = f.nextInt(); while (t-- > 0) { int n = f.nextInt(); int[] a = new int[n]; boolean flag = false; boolean flag1 = false; for (int i = 0; i < n; i++) { a[i] = f.nextInt(); } int sum = 0, temp1 = 0, count = 0, temp2 = 0; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { flag = true; temp1 = i + 1; } } for(int i=0;i<n;i++){ count++; sum += a[i]; temp2=i; if (sum % 2 == 0) { flag1 = true; break; } } if (flag) { System.out.println(1); System.out.println(temp1); } else if (flag1) { System.out.println(count); for (int j = 1; j <= temp2 + 1; j++) { System.out.print(j + " "); } System.out.println(); } else{ System.out.println(-1); } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
54a528104c475a896559ad5030db8644
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
/** * @author egaeus * @mail sebegaeusprogram@gmail.com * @veredict Not sended * @url https://codeforces.com/problemset/problem/ * @category ? * @date 21/05/2020 **/ import java.io.*; import java.util.*; import static java.lang.Integer.*; import static java.lang.Math.*; public class CFA { public static void main(String args[]) throws Throwable { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int T = parseInt(in.readLine()); for (int t = 0; t < T; t++) { int N = parseInt(in.readLine()); StringTokenizer st = new StringTokenizer(in.readLine()); TreeSet<Integer> even = new TreeSet<>(); TreeSet<Integer> odd = new TreeSet<>(); for (int i = 0; i < N; i++) { int u = parseInt(st.nextToken()); if (u % 2 == 0) even.add(i + 1); else odd.add(i + 1); if (odd.size() == 2 || even.size() == 1) break; } if (odd.size() == 2) { System.out.println(2); System.out.println(odd.first() + " " + odd.last()); } else if (even.size() == 1) { System.out.println(1); System.out.println(even.first()); } else System.out.println(-1); } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
7136bc96dabec96d52f197768d0d1136
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; public class EvenSubset { public static int hlp(int[] arr , int n) { int even = 0; int odd = 0; for(int j=0;j<n;j++) { if(arr[j]%2==0) { even++; }else { odd++; } } if(even!=0) { for(int j=0;j<n;j++) { if(arr[j]%2==0) { System.out.println(1); return j+1; } } } if(even==0 && odd==1) { return -1; } int q = 0; int x= 0 ; int y = 0; for(int j=0;j<n;j++) { if(arr[j]%2!=0) { x = j; q = j; } } for(int j=q+1;j<n;j++ ) { if(arr[j]%2!=0) { y = j; } } System.out.println(2); System.out.println(y+1); return x+1; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); for(int i=0;i<tc;i++) { int n = sc.nextInt(); int[] arr = new int[n]; for(int j=0;j<n;j++) { arr[j] = sc.nextInt(); } System.out.println(hlp(arr , n)); } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
913f1ad394ff12ef9895be72bcf389ce
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i=0; i<t; i++){ int n = s.nextInt(); int[] a = new int[n]; for(int j=0; j<n; j++){ a[j] = s.nextInt(); } if(n==1&&a[0]%2==1){ System.out.println(-1); } else { if(a[0]%2==0){ System.out.println(1); System.out.println(1); } else if (a[1]%2==0){ System.out.println(1); System.out.println(2); } else { System.out.println(2); System.out.println(1+" "+2); } } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
1adfca10b2351ccbc73560099451bd1d
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.io.*; import java.util.*; public class Q3 { public static void main(String[] args) throws IOException { Scan scan=new Scan(); Print print=new Print(); int T=scan.scanInt(); loop: while(T-->0) { boolean flag=false; int N=scan.scanInt(); //System.out.println(N+" N"); int index=0; int arr[]=new int[N]; for(int i=0;i<N;i++) { arr[i]=scan.scanInt(); if(arr[i]%2==0) { index=i+1; flag=true; } } if(flag) { print.println("1\n"+index); continue loop; } if(N==1) { print.println("-1"); } else { print.println("2\n1 2"); } //System.out.println(N+" "+Arrays.toString(arr)); } print.close(); } static class Print { private final BufferedWriter bw; public Print() { this.bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object)throws IOException { bw.append(""+object); } public void println(Object object)throws IOException { print(object); bw.append("\n"); } public void close()throws IOException { bw.close(); } } static class Scan { private byte[] buf=new byte[1024*1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } public int scanInt()throws IOException { int integer=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { integer*=10; integer+=n-'0'; n=scan(); } else throw new InputMismatchException(); } return neg*integer; } public double scanDouble()throws IOException { double doub=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)&&n!='.') { if(n>='0'&&n<='9') { doub*=10; doub+=n-'0'; n=scan(); } else throw new InputMismatchException(); } if(n=='.') { n=scan(); double temp=1; while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { temp/=10; doub+=(n-'0')*temp; n=scan(); } else throw new InputMismatchException(); } } return doub*neg; } public long scanLong() throws IOException { long ret = 0; long c = scan(); while (c <= ' ') { c = scan(); } boolean neg = (c == '-'); if (neg) { c = scan(); } do { ret = ret * 10 + c - '0'; } while ((c = scan()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public String scanString()throws IOException { StringBuilder sb=new StringBuilder(); int n=scan(); while(isWhiteSpace(n)) n=scan(); while(!isWhiteSpace(n) || n==' ') { sb.append((char)n); n=scan(); } return sb.toString(); } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
793bb16cc2d13c22dcf37b79fd0dcecf
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int n = 0; int k = 0; int p = 0; for(int i = 0; i < t; i++){ k = 0; p = 0; n = sc.nextInt(); for(int j = 0; j < n; j++){ if(sc.nextInt() % 2 == 0){ k = 1; p = j + 1; break; } } if(k != 1){ if(n != 1){ System.out.println(2); System.out.println("1 2"); } else { System.out.println(-1); } } else { System.out.println(1); System.out.println(Integer.toString(p)); } sc.nextLine(); } sc.close(); } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
327044c0fbb3773548dce2cf29c0f384
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { // BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); // StringTokenizer st = new StringTokenizer(sc.readLine()); Scanner sc = new Scanner(System.in); 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(); int init = -1; int end = -1; for(int i=0;i<n;i++){ int sum = 0; for(int j=i;j<n;j++){ sum+=a[j]; if(sum%2==0){ init = i;end = j; } } } if(init==-1){ System.out.println(-1); }else{ System.out.println(end-init+1); for(int i=init;i<=end;i++){ System.out.print(i+1+ " "); } System.out.println(); } t--; } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
5e33db886dcbd67d89e8bc9f10db85ca
train_004.jsonl
1583573700
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.
512 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int z=0;z<t;z++) { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } long sum=0; int count=1; int count1=1; int count2=1; int flag=0; int flag1=0; if(n==1) { for(int i=0;i<a.length;i++) { if(n==1 && a[0]%2!=0) { System.out.println("-1"); break; } else if(n==1 && a[0]%2==0) { System.out.println("1"); System.out.println("1"); } } } else if(n>1) for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { if(a[j]%2==0) { System.out.println("1"); System.out.println(j+1); flag=1; break; } sum=a[i]; sum=sum+a[j]; if(a[i]%2==0) { System.out.println(count); System.out.println(i+1); flag=1; break; } else { if(sum%2==0) { count1++; System.out.println(count1); System.out.println((i+1)+" "+(j+1)); flag=1; break; } if(sum%2!=0) { count++; sum=a[i]; continue; } } } if(flag==1) break; } } } }
Java
["3\n3\n1 4 3\n1\n15\n2\n3 5"]
1 second
["1\n2\n-1\n2\n1 2"]
NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.
Java 11
standard input
[ "dp", "implementation", "greedy", "brute force" ]
3fe51d644621962fe41c32a2d90c7f94
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).
800
For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.
standard output
PASSED
342793fcb0549e84c6633af642381461
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; /* 300000 3529833 */ public class f2 { static int[][] divs; static int[] divCnts; public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(), k = in.nextInt(); divCnts = new int[n+1]; divs = new int[n+1][]; int max = 0; for(int i=1;i<=n;i++) { for(int j=i+i;j<=n;j+=i) { max++; divCnts[j]++; } } for(int i=0;i<=n;i++) { divs[i] = new int[divCnts[i]]; divCnts[i] = 0; } for(int i=1;i<=n;i++) { for(int j=i+i;j<=n;j+=i) { divs[j][divCnts[j]++] = i; } } // System.err.println(max); if(k > max) { System.out.println("No"); return; } out.println("Yes"); IntList cs = test(n,k); out.println(cs.size()); for(int i=0;i<cs.size();i++) { if(i != 0) out.print(' '); out.print(cs.get(i)); } out.println(); out.close(); } static void add(BTS bit, int k) { bit.add(k+1); } static void del(BTS bit, int k) { bit.remove(k+1); } static IntList test(int n, int k) { boolean[] used = new boolean[n+1]; IntList[] sets = new IntList[n+1]; for(int i=0;i<=n;i++) sets[i] = new IntList(); int[] ptrs = new int[n+1]; int[] cnts = new int[n+1]; IntList ans = new IntList(); ans.add(1); ans.add(2); used[1] = true; used[2] = true; k--; BTS tm = new BTS(n+3); for(int i=3;i<=n;i++) { int p = 2 - (i % 2); sets[p].add(i); add(tm, p); cnts[i] = p; } while(k > 0) { int p = tm.floor(Math.min(k+1, n+2))-1; while(cnts[sets[p].get(ptrs[p])] != p) ptrs[p]++; int c = sets[p].get(ptrs[p]++); del(tm, p); used[c] = true; k -= cnts[c]; ans.add(c); for(int i=c*2;i<=n;i+=c) { if(!used[i]) { del(tm, cnts[i]); cnts[i]++; sets[cnts[i]].add(i); add(tm, cnts[i]); } } // for(int i : divs[c]) { for(int i : divs[c]) { if(!used[i]) { del(tm, cnts[i]); cnts[i]++; sets[cnts[i]].add(i); add(tm, cnts[i]); } } } return ans; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream i) { br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""); } public String next() throws IOException { if(st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } } static class BTS { int[] t; int m, hb; int size; BTS(int max) { m = max; hb = Integer.highestOneBit(m); t = new int[m+1]; size = 0; } private int t(int v) { return t[v]; } private void t(int v, int dv) { t[v] += dv; } void add(int i) { update(i, 1); } void remove(int v) { update(v, -1); } private void update(int i, int v) { size += v; while(i <= m) { t(i, v); i += (i&-i); } } boolean contains(int v) { return indexOf(v) - indexOf(v-1) == 1; } int floor(int v) { return get(indexOf(v)); } int ceiling(int v) { return get(indexOf(v-1)+1); } int lower(int v) { return get(indexOf(v-1)); } int higher(int v) { return get(indexOf(v)+1); } int indexOf(int i) { int s = 0; while(i > 0) { s += t(i); i -= i&-i; } return s-1; } int get(int i) { if(i == -1) return 0; i++; int v = 0; for(int b=hb;b>0;b>>=1) { if((v|b) <= m && t(v|b) < i) { v |= b; i -= t(v); } } return v+1; } int first() { return get(1); } int last() { return get(size); } int size() { return size; } } static class IntList { static int[] EMPTY = {}; int[] a = EMPTY; int n = 0; void add(int v) { if (n >= a.length) a = Arrays.copyOf(a, (n << 2) + 8); a[n++] = v; } int get(int idx) { return a[idx]; } int size() { return n; } } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
1f4e4bf1a0c287acd1aab8ce05b87e16
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Asgar Javadov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); FastWriter out = new FastWriter(outputStream); TaskF solver = new TaskF(); solver.solve(1, in, out); out.close(); } static class TaskF { public void solve(int testNumber, InputReader in, FastWriter out) { int n = in.nextInt(); int k = in.nextInt(); int[] lower = new int[n + 1]; for (int i = 1; i <= n; ++i) { for (int j = 2 * i; j <= n; j += i) { ++lower[j]; } } int total = 0; int m; for (m = 1; m <= n && total < k; ++m) { total += lower[m]; } --m; int[] upper = new int[m + 1]; for (int i = 1; i <= m; ++i) { for (int j = 2 * i; j <= m; j += i) { ++upper[i]; } } if (total < k) { out.println("No"); } else if (total == k) { out.println("Yes"); out.println(m); for (int i = 1; i <= m; ++i) { if (i > 1) out.print(' '); out.print(i); } out.println(); } // else if (k <= 6) { // for (int i = m; i > 0; --i) { // if (total - lower[i] == k) { // out.println("Yes"); // out.println(m - 1); // for (int j = 1; j <= m; ++j) { // if (j != i) { // out.print(j); // out.print(' '); // } // } // out.println(); // return; // } // } // } else { // int[] primes = NumberTheory.primes(m); boolean[] removed = new boolean[m + 1]; int count = m; // int index = primes.length - 1; // int half = m / 2 + 1; // while (total > k && index >= 0 && primes[index] > half) { // removed[primes[index]] = true; // --count; // --total; // --index; // } // if (total > k) { // for (int i = m; i > half && total > k; --i) { // if (lower[i] <= total - k) { // total -= lower[i]; // --count; // } // } // } MathUtils.Pair<Integer, Integer>[] pairs = new MathUtils.Pair[m]; for (int i = 0; i < m; ++i) { pairs[i] = new MathUtils.Pair<>(lower[i + 1] + upper[i + 1], i + 1); } Arrays.sort(pairs); MathUtils.Pair<Integer, Integer> temp = new MathUtils.Pair<>(0, 0); total -= k; while (total > 0) { temp.first = total; int pos = ArrayUtils.upperBound(pairs, temp); removed[pairs[pos].second] = true; total -= pairs[pos].first; --count; } out.println("Yes"); out.println(count); for (int i = 1; i <= m; ++i) { if (!removed[i]) { out.print(i); out.print(' '); } } out.println(); } } } static class MathUtils { public static class Pair<K extends Comparable<K>, V> implements Comparable<MathUtils.Pair<K, V>> { public K first; public V second; public Pair(K first, V second) { this.first = first; this.second = second; } public int compareTo(MathUtils.Pair<K, V> o) { return first.compareTo(o.first); } } } static class FastWriter extends PrintWriter { public FastWriter(OutputStream outputStream) { super(outputStream); } public FastWriter(Writer writer) { super(writer); } public FastWriter(String filename) throws FileNotFoundException { super(filename); } } static class InputReader extends BufferedReader { StringTokenizer tokenizer; public InputReader(InputStream inputStream) { super(new InputStreamReader(inputStream), 32768); } public InputReader(String filename) { super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(readLine()); } catch (IOException e) { throw new RuntimeException(); } } return tokenizer.nextToken(); } public Integer nextInt() { return Integer.valueOf(next()); } } static class ArrayUtils { public static <T extends Comparable<T>> int upperBound(T[] array, T val) { int low = 0, high = array.length - 1; while (low <= high) { int mid = low + high >> 1; if (val.compareTo(array[mid]) < 0) high = mid - 1; else low = mid + 1; } return high; } } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
33079de5aeecb5e06100516888d62ac4
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
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.StringTokenizer; /** * @author Don Li */ public class Divisibility { void solve() { int n = in.nextInt(), k = in.nextInt(); int tot = 0; for (int i = 1; i <= n; i++) { tot += n / i - 1; } if (tot < k) { out.println("No"); return; } int[] nd = num_divisors(n); for (int i = n; i >= 1; i--) { if (tot - (nd[i] - 1) >= k) { tot -= nd[i] - 1; continue; } int num = i, rem = tot - k; int[][] ns = new int[i - i / 2][]; for (int j = i, p = 0; j > i / 2; j--) ns[p++] = new int[]{j, nd[j] - 1}; Arrays.sort(ns, (a, b) -> -Integer.compare(a[1], b[1])); int[] bad = new int[i + 1]; for (int[] v : ns) { if (rem - v[1] >= 0) { rem -= v[1]; num--; bad[v[0]]++; } } out.println("Yes"); out.println(num); for (int j = 1; j <= i; j++) { if (bad[j] == 0) out.printf("%d ", j); } out.println(); return; } } int[] num_divisors(int n) { int[] fp = new int[n + 1]; int sqrt = (int) (Math.sqrt(n) + 0.5); for (int i = 2; i <= n; i++) { if (fp[i] == 0) { fp[i] = i; for (int j = i * i; j <= n && i <= sqrt; j += i) { if (fp[j] == 0) fp[j] = i; } } } int[] nd = new int[n + 1]; nd[1] = 1; for (int i = 2; i <= n; i++) { int x = i, e = 0; while (x % fp[i] == 0) { e++; x /= fp[i]; } nd[i] = nd[x] * (e + 1); } return nd; } public static void main(String[] args) { in = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); new Divisibility().solve(); out.close(); } static FastScanner in; static PrintWriter out; static class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
34e94baa67ef87c2244ca1ce2afe40d7
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.*; import java.util.*; public class Codeforces922F { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); //Read shit String[] sp = br.readLine().split(" "); int n = Integer.parseInt(sp[0]); int k = Integer.parseInt(sp[1]); if (n > 18) { if (k <= 40) n = 18; } if (n <= 18) { int r = (1<<n); boolean bool = false; boolean[] dumblist = new boolean[n]; int counter = 1; while (!bool && counter < r) { int isk = 0; for (int i = 0; i < n; i++) { if ((counter>>i)%2 == 1) dumblist[i] = true; else dumblist[i] = false; } for (int i = 0; i < n-1; i++) { for (int j = i+1; j < n; j++) { if (((j+1)%(i+1) == 0) && dumblist[j] && dumblist[i]) isk++; } } if (isk == k) bool = true; counter++; } counter--; if (bool) { pw.println("Yes"); int val = 0; int s = counter; while (s > 0) { if (s%2 == 1) val++; s /= 2; } pw.println(val); for (int i = 0; i < n; i++) { if ((counter>>i)%2 == 1) pw.print(i+1 + " "); } } else { pw.println("No"); } } else { //list of number of divisors int[] numdivisors = new int[n+1]; for (int i = 1; i < n+1; i++) { for (int j = 1; j <= n/i; j++) { numdivisors[i*j]++; } } int kmax = 0; int N = 1; while ((kmax < k) && (N <= n)) { kmax += numdivisors[N]-1; N++; } if (kmax < k) { pw.println("No"); } else { pw.println("Yes"); N--; n = N; boolean[] dumb2 = new boolean[n+1]; for (int i = 0; i <= n; i++) { dumb2[i] = true; } //greedy for (int i = 1; kmax > k; i++) { if (numdivisors[i] == 2) { int q = n/i; if (kmax - q >= k) { kmax -= q; dumb2[i] = false; N--; } } } pw.println(N); for (int i = 1; i <= n; i++) { if (dumb2[i]) pw.print(i + " "); } } } pw.close(); } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
72f654f6859ec031b0430c028f736a40
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.*; import java.util.*; public class Codeforces922F { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Read shit String[] sp = br.readLine().split(" "); int n = Integer.parseInt(sp[0]); int k = Integer.parseInt(sp[1]); if (n > 18) { if (k <= 40) n = 18; } if (n <= 18) { int r = (1<<n); boolean bool = false; boolean[] dumblist = new boolean[n]; int counter = 1; while (!bool && counter < r) { int isk = 0; for (int i = 0; i < n; i++) { if ((counter>>i)%2 == 1) dumblist[i] = true; else dumblist[i] = false; } for (int i = 0; i < n-1; i++) { for (int j = i+1; j < n; j++) { if (((j+1)%(i+1) == 0) && dumblist[j] && dumblist[i]) isk++; } } if (isk == k) bool = true; counter++; } counter--; if (bool) { System.out.println("Yes"); int val = 0; int s = counter; while (s > 0) { if (s%2 == 1) val++; s /= 2; } System.out.println(val); for (int i = 0; i < n; i++) { if ((counter>>i)%2 == 1) System.out.print(i+1 + " "); } } else { System.out.println("No"); } } else { //list of number of divisors int[] numdivisors = new int[n+1]; for (int i = 1; i < n+1; i++) { for (int j = 1; j <= n/i; j++) { numdivisors[i*j]++; } } int kmax = 0; int N = 1; while ((kmax < k) && (N <= n)) { kmax += numdivisors[N]-1; N++; } if (kmax < k) { System.out.println("No"); } else { System.out.println("Yes"); N--; n = N; boolean[] dumb2 = new boolean[n+1]; for (int i = 0; i <= n; i++) { dumb2[i] = true; } //greedy for (int i = 1; kmax > k; i++) { if (numdivisors[i] == 2) { int q = n/i; if (kmax - q >= k) { kmax -= q; dumb2[i] = false; N--; } } } System.out.println(N); for (int i = 1; i <= n; i++) { if (dumb2[i]) System.out.print(i + " "); } } } } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
0852942bfa88d0314604f90ad1ff837c
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.*; import java.util.*; public class Mainn { FastReader scn; PrintWriter out; String INPUT = "60 191"; void solve() { int n = scn.nextInt(), k = scn.nextInt(); int[] arr = new int[n + 1]; for(int i = 1; i <= n; i++) { int j = 2 * i; while(j <= n) { arr[j]++; j += i; } } for(int i = 1; i <= n; i++) { arr[i] += arr[i - 1]; } int[] primes = linearSieve(n); for(int i = 1; i <= n; i++) { if(arr[i] >= k) { int diff = arr[i] - k; HashSet<Integer> rem = new HashSet<>(); for(int j = i / 2 + 1; j <= i && diff > 0; j++) { if(Arrays.binarySearch(primes, j) >= 0) { rem.add(j); diff--; } } if(diff == 1) { rem.remove(rem.iterator().next()); diff++; } if(diff == 2) { for(int j = i / 3 + 1; j <= i / 2 && diff > 0; j++) { if(Arrays.binarySearch(primes, j) >= 0) { rem.add(j); diff -= 2; } } } if(diff == 2) { rem.remove(rem.iterator().next()); diff++; } if(diff == 3) { for(int j = i / 4 + 1; j <= i / 3 && diff > 0; j++) { if(Arrays.binarySearch(primes, j) >= 0) { rem.add(j); diff -= 3; } } } out.println("Yes"); out.println(i - rem.size()); for(int j = 1; j <= i; j++) { if(!rem.contains(j)) { out.print(j + " "); } } out.println(); return; } } out.println("No"); } int[] linearSieve(int n) { boolean[] isComp = new boolean[n + 1]; int[] prime = new int[n + 1]; int k = 0; for (int i = 2; i <= n; i++) { if (!isComp[i]) { prime[k++] = i; } for (int j = 0; j < k && i * 1.0 * prime[j] <= n; j++) { isComp[i * prime[j]] = true; if (i % prime[j] == 0) { break; } } } return Arrays.copyOf(prime, k); } void run() throws Exception { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; out = new PrintWriter(System.out); scn = new FastReader(oj); solve(); out.flush(); if (!oj) { System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" })); } } public static void main(String[] args) throws Exception { new Mainn().run(); } class FastReader { InputStream is; public FastReader(boolean onlineJudge) { is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes()); } byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; 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++]; } boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return (char) skip(); } String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } char[][] nextMatrix(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = next(m); return map; } int[] nextArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int nextInt() { int num = 0, 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(); } } long nextLong() { 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(); } } int[] shuffle(int[] arr) { Random r = new Random(); for (int i = 1, j; i < arr.length; i++) { j = r.nextInt(i); arr[i] = arr[i] ^ arr[j]; arr[j] = arr[i] ^ arr[j]; arr[i] = arr[i] ^ arr[j]; } return arr; } } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
70c0e0cf130354b3711ae6c2b0e3ffc4
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
// java 8 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; /* 300000 3529833 */ public class f2 { static int[][] divs; static int[] divCnts; public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(), k = in.nextInt(); divCnts = new int[n+1]; divs = new int[n+1][]; int max = 0; for(int i=1;i<=n;i++) { for(int j=i+i;j<=n;j+=i) { max++; divCnts[j]++; } } for(int i=0;i<=n;i++) { divs[i] = new int[divCnts[i]]; divCnts[i] = 0; } for(int i=1;i<=n;i++) { for(int j=i+i;j<=n;j+=i) { divs[j][divCnts[j]++] = i; } } // System.err.println(max); if(k > max) { System.out.println("No"); return; } out.println("Yes"); IntList cs = test(n,k); out.println(cs.size()); for(int i=0;i<cs.size();i++) { if(i != 0) out.print(' '); out.print(cs.get(i)); } out.println(); out.close(); } static void add(BTS bit, int k) { bit.add(k+1); } static void del(BTS bit, int k) { bit.remove(k+1); } static IntList test(int n, int k) { boolean[] used = new boolean[n+1]; IntList[] sets = new IntList[n+1]; for(int i=0;i<=n;i++) sets[i] = new IntList(); int[] ptrs = new int[n+1]; int[] cnts = new int[n+1]; IntList ans = new IntList(); ans.add(1); ans.add(2); used[1] = true; used[2] = true; k--; BTS tm = new BTS(n+3); for(int i=3;i<=n;i++) { int p = 2 - (i % 2); sets[p].add(i); add(tm, p); cnts[i] = p; } while(k > 0) { int p = tm.floor(Math.min(k+1, n+2))-1; while(cnts[sets[p].get(ptrs[p])] != p) ptrs[p]++; int c = sets[p].get(ptrs[p]++); del(tm, p); used[c] = true; k -= cnts[c]; ans.add(c); for(int i=c*2;i<=n;i+=c) { if(!used[i]) { del(tm, cnts[i]); cnts[i]++; sets[cnts[i]].add(i); add(tm, cnts[i]); } } // for(int i : divs[c]) { for(int i : divs[c]) { if(!used[i]) { del(tm, cnts[i]); cnts[i]++; sets[cnts[i]].add(i); add(tm, cnts[i]); } } } return ans; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream i) { br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""); } public String next() throws IOException { if(st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } } static class BTS { int[] t; int m, hb; int size; BTS(int max) { m = max; hb = Integer.highestOneBit(m); t = new int[m+1]; size = 0; } private int t(int v) { return t[v]; } private void t(int v, int dv) { t[v] += dv; } void add(int i) { update(i, 1); } void remove(int v) { update(v, -1); } private void update(int i, int v) { size += v; while(i <= m) { t(i, v); i += (i&-i); } } boolean contains(int v) { return indexOf(v) - indexOf(v-1) == 1; } int floor(int v) { return get(indexOf(v)); } int ceiling(int v) { return get(indexOf(v-1)+1); } int lower(int v) { return get(indexOf(v-1)); } int higher(int v) { return get(indexOf(v)+1); } int indexOf(int i) { int s = 0; while(i > 0) { s += t(i); i -= i&-i; } return s-1; } int get(int i) { if(i == -1) return 0; i++; int v = 0; for(int b=hb;b>0;b>>=1) { if((v|b) <= m && t(v|b) < i) { v |= b; i -= t(v); } } return v+1; } int first() { return get(1); } int last() { return get(size); } int size() { return size; } } static class IntList { static int[] EMPTY = {}; int[] a = EMPTY; int n = 0; void add(int v) { if (n >= a.length) a = Arrays.copyOf(a, (n << 2) + 8); a[n++] = v; } int get(int idx) { return a[idx]; } int size() { return n; } } } // F. Divisibility // time limit per test1 second // memory limit per test256 megabytes // inputstandard input // outputstandard output // Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. // // Let's define for some set of integers as the number of pairs a, b in , such that: // a is strictly less than b; // a divides b without a remainder. // You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that . // // Input // The only line contains two integers n and k . // // Output // If there is no answer, print "No". // // Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. // // If there are multiple answers, print any of them. // // Examples // input // 3 3 // output // No // input // 6 6 // output // Yes // 5 // 1 2 4 5 6 // input // 8 3 // output // Yes // 4 // 2 4 5 8 // Note // In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, . // // In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, . //
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
580977e248655d7b133ea70cbf26e614
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; /** * Created by Administrator on 2018/3/4. */ public class CF922F { public static final int N_LIMIT = 300001; static final boolean IS_OJ = System.getProperty("ONLINE_JUDGE") != null; public static BlockReader input; public static void main(String[] args) throws FileNotFoundException { if (!IS_OJ) { System.setIn(new FileInputStream("D:\\DataBase\\TESTCASE\\codeforces\\CF922F.in")); } input = new BlockReader(System.in); solve(); } public static void solve() { int n = input.nextInteger(); int k = input.nextInteger(); int[] divisors = new int[n + 1]; divisors[1] = 0; for (int i = 2; i <= n; i++) { for (int j = i; j <= n; j += i) { divisors[j] += 1; } } int sum = 0; int setId; for (setId = 1; setId <= n && sum < k; setId++) { sum += divisors[setId]; } if (sum < k) { System.out.println("No"); return; } setId--; System.out.println("Yes"); boolean[] remove = new boolean[setId + 1]; int remain = sum - k; if (setId <= 120) { tryRemove(remove, divisors, setId, sum - k, 1); } else { for (int i = setId / 2 + 1; i <= setId & remain > 0; i++) { if (divisors[i] == 1) { remain--; remove[i] = true; } } } int cnt = 0; StringBuilder builder = new StringBuilder(); for (int i = 1; i <= setId; i++) { if (remove[i] == false) { cnt++; builder.append(i).append(' '); } } System.out.println(cnt); System.out.println(builder); } public static boolean tryRemove(boolean[] remove, int[] divisors, int setId, int remain, int i) { if (remain == 0) { return true; } if (i > setId) { return false; } if (remain >= setId / i + divisors[i] - 1) { remove[i] = true; for (int j = i + i; j <= setId; j += i) { divisors[j]--; } if (tryRemove(remove, divisors, setId, remain - (setId / i + divisors[i] - 1), i + 1)) { return true; } remove[i] = false; for (int j = i + i; j <= setId; j += i) { divisors[j]++; } } return tryRemove(remove, divisors, setId, remain, i + 1); } public static class BlockReader { static final int EOF = -1; InputStream is; byte[] dBuf; int dPos, dSize, next; StringBuilder builder = new StringBuilder(); public BlockReader(InputStream is) { this(is, 4096); } public BlockReader(InputStream is, int bufSize) { this.is = is; dBuf = new byte[bufSize]; next = nextByte(); } public void skipBlank() { while (Character.isWhitespace(next)) { next = nextByte(); } } public String nextBlock() { builder.setLength(0); skipBlank(); while (next != EOF && !Character.isWhitespace(next)) { builder.append((char) next); next = nextByte(); } return builder.toString(); } public int nextInteger() { skipBlank(); int ret = 0; boolean rev = false; if (next == '+' || next == '-') { rev = next == '-'; next = nextByte(); } while (next >= '0' && next <= '9') { ret = (ret << 3) + (ret << 1) + next - '0'; next = nextByte(); } return rev ? -ret : ret; } public int nextBlock(char[] data, int offset) { skipBlank(); int index = offset; int bound = data.length; while (next != EOF && index < bound && !Character.isWhitespace(next)) { data[index++] = (char) next; next = nextByte(); } return index - offset; } public boolean hasMore() { skipBlank(); return next != EOF; } public int nextByte() { while (dPos >= dSize) { if (dSize == -1) { return EOF; } dPos = 0; try { dSize = is.read(dBuf); } catch (IOException e) { throw new RuntimeException(e); } } return dBuf[dPos++]; } } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
1e5381c23feff6315a31d871b5f9226b
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
//package round461; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; public class F2 { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), K = ni(); int s = 0; for(int i = 1;i <= n;i++){ s += n/i-1; } if(K > s){ out.println("No"); return; } int[] lpf = enumLowestPrimeFactors(n); int[] ndivs = enumNumDivisorsFast(n, lpf); for(int i = n;i >= 1;i--){ if(K > s - (ndivs[i] - 1)){ int rem = s - K; int num = i; int[][] ns = new int[i-i/2][]; int p = 0; for(int j = i;j > i/2;j--){ ns[p++] = new int[]{j, ndivs[j]-1}; } Arrays.sort(ns, new Comparator<int[]>() { public int compare(int[] a, int[] b) { return -(a[1] - b[1]); } }); int[] ng = new int[i+1]; for(int[] v : ns){ if(rem - v[1] >= 0){ rem -= v[1]; num--; ng[v[0]]++; } } if(rem == 1)throw new RuntimeException(); out.println("Yes"); out.println(num); for(int j = 1;j <= i;j++){ if(ng[j] == 0)out.print(j + " "); } out.println(); return; } s -= ndivs[i] - 1; } throw new RuntimeException(); } public static int[] enumLowestPrimeFactors(int n) { int tot = 0; int[] lpf = new int[n + 1]; int u = n + 32; double lu = Math.log(u); int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)]; for (int i = 2; i <= n; i++) lpf[i] = i; for (int p = 2; p <= n; p++) { if (lpf[p] == p) primes[tot++] = p; int tmp; for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) { lpf[tmp] = primes[i]; } } return lpf; } public static int[] enumNumDivisorsFast(int n, int[] lpf) { int[] nd = new int[n+1]; nd[1] = 1; for(int i = 2;i <= n;i++){ int j = i, e = 0; while(j % lpf[i] == 0){ j /= lpf[i]; e++; } nd[i] = nd[j] * (e+1); } return nd; } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new F2().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private 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++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, 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(); } } 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(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
fd30b70c5abd7c18f20a451b36a8018e
train_004.jsonl
1518023700
Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .
256 megabytes
import java.io.*; import java.util.*; public class F1 { FastScanner in; PrintWriter out; boolean systemIO = true; public void solve() throws IOException { int n = in.nextInt(); long k = in.nextLong(); long[] max = new long[n]; long[] used = new long[n]; TreeSet<Long> set = new TreeSet(); for (int i = 1; i < used.length; i++) { max[i] = max[i - 1]; for (int j = 1; j * j <= i + 1; j++) { if ((i + 1) % j == 0) { used[j - 1]++; used[i]++; max[i]++; if (j != 1 && (i + 1) / j != j) { used[(i + 1) / j - 1]++; used[i]++; max[i]++; } } } // for (long j = 1; j <= max[i] - max[i - 1]; j++) { // set.add(j); // } // for (int j = 0; j < used.length; j++) { // set.remove(used[j]); // if (set.isEmpty()) { // break; // } // } // if (!set.isEmpty()) { // System.out.println(i + 1); // for (long j : set) { // System.out.println(j); // } // } // set.clear(); if (k <= max[i]) { out.println("Yes"); if (k == max[i]) { out.println(i + 1); for (int j = 0; j <= i; j++) { out.print(j + 1 + " "); } } else { int x = -1; for (int j = 0; j < used.length; j++) { if (used[j] + k == max[i]) { x = j; break; } } if (x != -1) { out.println(i); for (int j = 0; j <= i; j++) { if (j != x) { out.print(j + 1 + " "); } } } else { // TreeSet<Long> ans = new TreeSet<>(); for (long j = 0; j <= i; j++) { set.add(j); } k = max[i] - k; for (long j = 0; j < i; j++) { if (used[(int)j] == 1) { set.remove(j); k--; } if (k == 0) { break; } } for (long j = 0; j < used.length; j++) { if (used[(int)j] == k) { set.remove(j); break; } } out.println(set.size()); for (long j : set) { out.print(j + 1 + " "); } } } return; } } System.out.println("No"); // for (int i = 1; i < used.length; i++) { // set.add(max[i] - max[i - 1]); // } // for (long j : set) { // System.out.println(j); // } // if (k > max[n - 1]) { // System.out.println("No"); // return; // } else { // System.out.println("Yes"); // int j = 0; // for (int i = 0; i < used.length; i++) { // if (max[i] >= k) { // // } // } // } } public void run() { try { if (systemIO) { in = new FastScanner(System.in); out = new PrintWriter(System.out); } else { in = new FastScanner(new File("segments.in")); out = new PrintWriter(new File("segments.out")); } solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String nextLine() { try { return br.readLine(); } catch (IOException e) { return null; } } 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()); } } public static void main(String[] arg) { new F1().run(); } }
Java
["3 3", "6 6", "8 3"]
1 second
["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"]
NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .
Java 8
standard input
[ "dp", "constructive algorithms", "number theory", "greedy" ]
d5d470f2848e779310e5e54eccca8b4a
The only line contains two integers n and k .
2,400
If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them.
standard output
PASSED
b1581242963dee26d8e5aa6d11809497
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; 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()); } 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(); ArrayList<int[]> a = new ArrayList<>(); int n; for(int i=0; i<t; i++) { n = sc.nextInt(); int[] b = new int[n]; for(int j=0; j<n; j++) b[j] = sc.nextInt(); a.add(b); } for(int i=0; i<t; i++) result(a.get(i)); } private static void result(int[] a) { int i; for(i=1; i<a.length; i++) { if(Math.abs(a[i]-a[i-1]) > 1) { System.out.println("YES"); System.out.println(i + " " + (i+1)); break; } } if(i == a.length) System.out.println("NO"); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
c589a01f403f417f15e88b663209718a
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java .util.Scanner ; import java.util.*; import java.io.*; import java.nio.IntBuffer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Iterator; //import java.io.OutputStreamReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.lang.Math; import java.io.InputStream; import java.util.InputMismatchException; import java.awt.Point; import java.util.HashMap; import java.util.Collections; import java.util.Arrays; //import java.util.Collections.reverseOrder() public class cf2{ public static int binarysearch(int[] arr,int num){ int n; n=arr.length; int ans; ans=0; int start; start=0; int end ; end=n-1; while(start<=end){ int mid; mid=(start+end)/2; if (arr[mid]>num){ end=mid-1; } else{ ans=mid+1; start=mid+1; } } return ans; } public static void merger(int startind,int midind,int endind, ArrayList<Integer> arr){ ArrayList<Integer> mergedSortedArray; mergedSortedArray= new ArrayList<Integer>(); int rightIndex ; rightIndex= midind+1; int leftIndex ; leftIndex= startind; while(midind>=leftIndex && endind>=rightIndex){ if(arr.get(leftIndex)<=arr.get(rightIndex)){ mergedSortedArray.add(arr.get(leftIndex)); leftIndex++; }else{ mergedSortedArray.add(arr.get(rightIndex)); rightIndex++; } } while(midind>=leftIndex){ mergedSortedArray.add(arr.get(leftIndex)); leftIndex++; } while(endind>=rightIndex){ mergedSortedArray.add(arr.get(rightIndex)); rightIndex++; } int i ; i= 0; int j ; j= startind; while(i<mergedSortedArray.size()){ arr.set(j, mergedSortedArray.get(i++)); j++; } } public static void divide(int startIndex,int endIndex, ArrayList<Integer> arr){ if(endIndex >startIndex&& (endIndex-startIndex)>=1){ int mid; mid = (endIndex + startIndex)/2; divide(startIndex, mid, arr); divide(mid+1, endIndex, arr); merger(startIndex,mid,endIndex,arr); } } public static int gcd(int a, int b){ return fact(Math.min(a, b)); } public static int fact(int n){ int ans =1; for(int i =1; i<=n; i++){ ans=ans*i; } return ans ; } public static void main(final String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); Scanner s =new Scanner(System.in); int t =in.nextInt(); for(int i =0; i<t; i++){ int n =in.nextInt(); int[] arr =new int[n]; for(int j =0; j<n; j++){ arr[j]=in.nextInt(); } int ans =0; int yo1=0; int yo2=0; for(int x=1; x<n; x++){ if(Math.abs(arr[x]-arr[x-1])>=2){ ans=1; yo1=x-1; yo2=x; break; } else { ans=0; } } if(ans==1){ System.out.println("YES"); System.out.println(yo1+1+" "+(yo2+1)); } else { System.out.println("NO"); } } } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(final 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 (final IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (final IOException e) { e.printStackTrace(); } return str; } 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 double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); final StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(final int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
a8eadc368d20720727ecf5838727476f
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; public class SUBARRAY{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int [] a = new int[n]; int l = 0; a[0] = sc.nextInt(); for(int i = 1 ; i<n;i++){ a[i]=sc.nextInt(); if(Math.abs(a[i-1]-a[i])>1) l=i; } if(l==0) System.out.println("NO"); else{ System.out.println("YES"); System.out.println(l+" "+(l+1)); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
ce2b9f9be2d7d50f84984c88f7391871
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int[] arr = new int[n]; for (int j = 0; j < n; j++) { arr[j] = in.nextInt(); } boolean flag = false; for (int j = 1; j < n; j++) { if (Math.abs(arr[j] - arr[j - 1]) > 1) { out.println("YES"); out.println((j) + " " + (j + 1)); flag = true; break; } } if (!flag) { out.println("NO"); } } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
e1222a040b97796be3d7856cb645354c
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while (t-- > 0){ int n = in.nextInt(); int l = -1; int r = -1; int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 1; i < n; i++) { if(abs(a[i] - a[i-1]) >= 2){ l = i - 1; r = i; } } if(l == -1)out.println("NO"); else { out.println("YES"); out.println(l+1 + " " + (r+1)); } } out.close(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(File f) throws FileNotFoundException { br = new BufferedReader(new FileReader(f)); } FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
ecbffe7a8419590a6eb605619db0ab1e
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.Scanner; import java.util.Arrays; public class Codeforces1270B_Real { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); boolean[] answer1 = new boolean[n]; int[] answer2a = new int[n]; int[] answer2b = new int[n]; int i; int j; for (i = 0; i < n; i++) { int length = input.nextInt(); int[] given = new int[length]; for (j = 0; j < length; j++) { given[j] = input.nextInt(); } int first; int last; for (j = 0; j < length - 1; j++) { first = given[j]; last = given[j + 1]; int big = Math.max(first, last); int small = Math.min(first, last); if (big - small > 1) { answer1[i] = true; answer2a[i] = j + 1; answer2b[i] = j + 2; } } } for (i = 0; i < n; i++) { if (answer1[i]) { System.out.println("YES"); System.out.println(answer2a[i] + " " + answer2b[i]); } else { System.out.println("NO"); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
2c354e61c82a1c1aba67748e9d1073ea
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.*; public final class RAAM { static void solve() throws IOException { int n = nextInt(); int a[] = new int[n]; boolean found = false; for (int i = 0; i < n; ++i) a[i] = nextInt(); for (int i = 0; i < n - 1; ++i) { if (Math.abs(a[i + 1] - a[i]) >= 2) { found = true; out.println("YES\n" + (i + 1) + " " + (i + 2)); break; } } if (!found) out.println("NO"); } public static void main(String args[]) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedOutputStream(System.out)); int tt = nextInt(); while (tt-- > 0) { solve(); } out.close(); } static final long mod = (long) (1e9 + 7); static final int inf = (int) (1e9 + 1); static class Pair implements Comparable<Pair> { int first, second; Pair(int a, int b) { first = a; second = b; } public int compareTo(Pair p) { return this.first - p.first; } public boolean equals(Object p) { Pair p1 = (Pair) p; return (first == p1.first && second == p1.second); } public String toString() { return this.first + " " + this.second; } public int hashCode() { return (int) ((1l * (inf + 1) * this.first + this.second) % mod); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static BufferedReader br; static StringTokenizer st; static PrintWriter out; static String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } static int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } static int[] memset(int n, int val) { int ar[] = new int[n]; Arrays.fill(ar, val); return ar; } static void debug(Object... a) { System.out.print("> "); for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } static void debug(int a[]) { debugnsp(Arrays.stream(a).boxed().toArray()); } static void debug(long a[]) { debugnsp(Arrays.stream(a).boxed().toArray()); } static void debugnsp(Object a[]) { System.out.print("> "); for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } } /* * Jai Sita Ram Ji * * @author: Nishchal Siddharth Pandey */
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
c739cbd7d9143b8f722a23aff24ee646
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.Scanner; public class subArray{ public static void main(String args[]){ int test; Scanner scan = new Scanner(System.in); test = scan.nextInt(); while(test--!=0){ int n= scan.nextInt(); int A[]=new int[n]; int l=-1; for(int i=0;i<n;i++) A[i]=scan.nextInt(); for(int i=1;i<n;i++){ if(Math.abs(A[i]-A[i-1])>1){ l=i; System.out.println("YES"); System.out.println(l+" "+(l+1)); break; } } if(l==-1){ System.out.println("NO"); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
8ae46837a8d62e19c12934131c2821b1
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
// practice with kaiboy import java.io.*; import java.util.*; public class CF1270B extends PrintWriter { CF1270B() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1270B o = new CF1270B(); o.main(); o.flush(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] aa = new int[n]; for (int i = 0; i < n; i++) aa[i] = sc.nextInt(); int l = 0, r = 0; for (int i = 0; i + 1 < n; i++) if (Math.abs(aa[i] - aa[i + 1]) >= 2) { l = i + 1; r = i + 2; break; } if (l == 0) println("NO"); else { println("YES"); println(l + " " + r); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
5965b6a963934e338bec0c6b9dea83a9
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class InterestingSub { public static void main (String [] args) throws IOException { BufferedReader b1 = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(b1.readLine()); t: for(int i = 0; i<T; i++) { int arrLen = Integer.parseInt(b1.readLine()); int start = 0; int end = 0; ArrayList<Integer> a1 = new ArrayList<Integer>(); //StringTokenizer s1 = new StringTokenizer(b1.readLine()); String vals [] = (b1.readLine()).split(" "); for(int j = 0; j<vals.length; j++) { if(j>0 && Math.abs(Integer.parseInt(vals[j]) - Integer.parseInt(vals[j-1])) >=2) { System.out.println("YES"); System.out.println((j) + " " + (j + 1)); continue t; } } System.out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
e2d384d08f1f50b8ea6f37cc39a46f26
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.Scanner; public class Interesting_Subarray { public static void main(String[] args) { // TODO Auto-generated method stub Scanner t = new Scanner(System.in); int test = t.nextInt(); while (test-- > 0) { int n = t.nextInt(); int[] a = new int[n]; int flag = 0; for (int i = 0; i < n; i++) a[i] = t.nextInt(); for (int i = 0; i < n - 1; i++) { if (Math.abs(a[i + 1] - a[i]) > 1) { System.out.println("YES"); System.out.println((i + 1) + " " + (i + 2)); flag = 1; break; } } if (flag == 0) System.out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
8c33dbd7b18fa7a1c607417990eb1c48
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
/*input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 */ import java.math.*; import java.io.*; import java.util.*; public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static Reader sc=new Reader(); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); static int max=0; public static void main(String args[])throws IOException { /* * For integer input: int n=inputInt(); * For long input: long n=inputLong(); * For double input: double n=inputDouble(); * For String input: String s=inputString(); * Logic goes here * For printing without space: print(a+""); where a is a variable of any datatype * For printing with space: printSp(a+""); where a is a variable of any datatype * For printing with new line: println(a+""); where a is a variable of any datatype Scanner in = new Scanner(System.in); //all four int[] dr = { 1, 0, -1, 0 }; int[] dc = { 0, 1, 0, -1 }; println("Case #"+k+": "+1+"");//Google */ int t=inputInt(); while(t-->0) { int n=inputInt(),flag=0 ; int[] a =new int[n]; for(int i=0;i<n;i++) { a[i]=inputInt(); } int max=Integer.MIN_VALUE,min=Integer.MAX_VALUE; int pos1=-1,pos2=-1; for(int i=0;i<n-1;i++) { if(Math.abs(a[i]-a[i+1])>=2) { println("YES\n"+(i+1)+" "+(i+2)+""); flag=1; break; } } if(flag==0) { println("NO"); } } bw.flush(); bw.close(); } static void dfs(int src,int par,List<List<Integer>> ls,boolean visit[]) { if(visit[src]) return; visit[src]=true; Iterator<Integer> ite = ls.get(src).listIterator(); while(ite.hasNext()) { int x=ite.next(); if(!visit[x]) { dfs(x,par,ls,visit); } } } public static long pow(long a,long b) { long result=1; while(b>0) { if(b%2==1) result*=a; a*=a; b/=2; } return result; } public static long nCr(long n, long r) { long ans=1; if(r>n-r) { r=n-r; } for(long i=1;i<=r;i++) { ans*=(n-i+1); ans/=i; } return ans; } public static long modulo(long x,long N) { return (x % N + N) %N; } public static long lcm(long a,long b) { return a / gcd(a, b) * b; } public static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } public static int inputInt()throws IOException { return sc.nextInt(); } public static long inputLong()throws IOException { return sc.nextLong(); } public static double inputDouble()throws IOException { return sc.nextDouble(); } public static String inputString()throws IOException { return sc.readLine(); } public static void print(String a)throws IOException { bw.write(a); } public static void printSp(String a)throws IOException { bw.write(a+" "); } public static void println(String a)throws IOException { bw.write(a+"\n"); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
19273e08c31aff65b39abd9335f66c45
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import javax.sound.sampled.Line; import java.io.*; import java.math.BigInteger; import java.util.*; public class A { public static void main(String[] args) throws Throwable { long time = System.currentTimeMillis(); // Scanner sc = new Scanner("mayors.in"); // PrintWriter pw = new PrintWriter("mayors.out"); Scanner sc = new Scanner(); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] a = new int[n]; boolean f = false; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); if (!f && i > 0 && Math.abs(a[i] - a[i - 1]) > 1) { f = true; pw.println("YES"); pw.println(i + " " + (i + 1)); } } if (!f) pw.println("NO"); } pw.close(); System.err.println((System.currentTimeMillis() - time) / 1000.0); } static class Scanner { StringTokenizer st; BufferedReader br; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } Scanner(String s) throws Throwable { br = new BufferedReader(new FileReader(new File(s))); } String next() throws Throwable { if (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws Throwable { return Integer.parseInt(next()); } long nextLong() throws Throwable { return Long.parseLong(next()); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
654be4d4b04d7c4160be2837d194664b
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws Exception{ MScanner sc=new MScanner(System.in); PrintWriter pw=new PrintWriter(System.out); int t=sc.nextInt(); o:while(t-->0) { int n=sc.nextInt(); int[]in=sc.takearr(n); for(int i=0;i<n-1;i++) { if(Math.abs(in[i]-in[i+1])>=2) { pw.println("YES"); pw.println((i+1)+" "+(i+2)); continue o; } } pw.println("NO"); } pw.flush(); } static class MScanner { StringTokenizer st; BufferedReader br; public MScanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public MScanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int[] takearr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public long[] takearrl(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public Integer[] takearrobj(int n) throws IOException { Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public Long[] takearrlobj(int n) throws IOException { Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
9d55c2e609d51f40f21688f2ade99434
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int test = 0; test < t; ++test) { int n = sc.nextInt(); int[] a = new int[n]; a[0] = sc.nextInt(); int j = 0; for (int i = 1; i < n; ++i) { a[i] = sc.nextInt(); int diff = Math.abs(a[i] - a[i - 1]); if (diff >= 2) j = i; } if (j == 0) System.out.println("NO"); else { System.out.println("YES"); System.out.print(j); System.out.print(" "); System.out.println(j + 1); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
93994795dd1d585a6866304bfb890a63
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.Hashtable; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); for (testNumber = 0; testNumber < t; testNumber++) { int arrLength = in.nextInt(); int[] a = new int[arrLength]; for (int i = 0; i < arrLength; i++) a[i] = in.nextInt(); boolean isInteresting = false; for (int i = 1; i < arrLength; i++) { if (Math.abs(a[i] - a[i - 1]) >= 2) { out.println("YES"); out.println(i + " " + (i + 1)); isInteresting = true; break; } } if (!isInteresting) out.println("NO"); } } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); //, 32768 tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
5c51ac1a3d1f382893fab2b5b5574010
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; public class Solution { public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(System.out); int testNum = (int) nextLong(in); int sizeOfArray; long prevVal; long tmpVal; long savedA; long savedB; for (int i = 0; i < testNum; i++) { sizeOfArray = (int) nextLong(in); prevVal = nextLong(in); savedA = 0; savedB = 0; for (int j = 1; j < sizeOfArray; j++) { tmpVal = nextLong(in); if (Math.abs(tmpVal - prevVal) >= 2) { savedA = j; savedB = savedA + 1; } prevVal = tmpVal; } if (savedB == 0) { out.println("NO"); } else { out.println("YES"); out.println(savedA + " " + savedB); } out.flush(); } } private static long nextLong(StreamTokenizer in) throws IOException { in.nextToken(); return (long) in.nval; } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
336ca75ecf80fe28d60839ae38da1828
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
//package c1270.b; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { private static class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t; i++) { if (i > 0) sb.append("\n"); int n = sc.nextInt(); int[] a = sc.nextIntArray(n); boolean isFound = false; for (int j = 0; j < n - 1; j++) { if (Math.abs(a[j] - a[j + 1]) >= 2) { sb.append("YES\n"); sb.append(String.format("%d %d", j + 1, j + 2)); isFound = true; break; } } if (!isFound) sb.append("NO"); } System.out.println(sb.toString()); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
490cbd1868fd724e8250deaf14c8fe9b
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main{ static int mod = 998244353; public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); public static void main(String sp[])throws IOException{ FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int k = n; int arr[] = new int[n+1]; for(int i=1;i<=n;i++) arr[i] = sc.nextInt(); boolean g=false; for(int i=1;i<n;i++){ if(Math.abs(arr[i]-arr[i+1])>=2){ System.out.println("YES"); System.out.println(i+" "+(i+1)); g=true; break; } } if(g==false){ System.out.println("NO"); } } } public 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 (Exception r) { r.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next());//converts string to integer } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception r) { r.printStackTrace(); } return str; } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
1db4dc7538ee7834b0954f93f8c7ea1f
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
//package Codeforces; import java.util.Scanner; public class B1270 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int t=input.nextInt(); int a[]=new int [200010]; while(t-->0) { int n=input.nextInt(); int g=0; for(int i=1;i<=n;i++) { a[i]=input.nextInt(); } for(int i=2;i<=n;i++) { if(Math.abs(a[i]-a[i-1])>=2) { g=1; System.out.println("YES"); System.out.println(i-1+" "+i); break; } } if(g==0) System.out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
0c2a44cb92dfacd9577f2d9a54b9a571
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.math.BigInteger; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0){ int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++){ a[i] = sc.nextInt(); } boolean found = false; int start = -1;int end = -1; for(int i=0;i<n-1&&!found;i++){ if(Math.abs(a[i]-a[i+1])>=2){ found = true; start = i+1;end=i+2; } } if(found){ System.out.println("YES"); System.out.println((start)+ " "+(end)); }else { System.out.println("NO"); } t--; } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
339574f5b9f69afe58eccf770e693d31
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; public class InterestingSubarray { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int flag=0; for(int i=0;i<n-1;i++) { if(Math.abs(a[i]-a[i+1])>1) { System.out.println("YES"); System.out.println((i+1)+" "+(i+2)); flag=1; break; } } if(flag==0) { System.out.println("NO"); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
051e9c50f20d996a65a10b2a2fe112fa
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); B solver = new B(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class B { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int prev = in.nextInt(); boolean good = false; int ind = 0; for (int i = 1; i < n; i++) { int cur = in.nextInt(); if (Math.abs(cur - prev) > 1) { good = true; ind = i; } prev = cur; } if (!good) { out.println("NO"); } else { out.println("YES"); out.println(ind + " " + (ind + 1)); } } } static class InputReader { private BufferedReader reader; private StringTokenizer stt; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { return null; } } public String next() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
d1a24f75e6664f419c5a98213c65b969
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author ky112233 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); int[] arr = new int[2]; arr[0] = a[0]; arr[1] = a[1]; int mx = Math.max(arr[0], arr[1]); int mn = Math.min(arr[0], arr[1]); if (mx - mn >= 2) { out.println("YES"); out.println(1 + " " + 2); return; } for (int i = 2; i < n; i++) { arr[0] = arr[1]; arr[1] = a[i]; mx = Math.max(arr[0], arr[1]); mn = Math.min(arr[0], arr[1]); if (mx - mn >= 2) { out.println("YES"); out.println(i + " " + (i + 1)); return; } } out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
527d44a8a380198f0cf5c6103b1a0c80
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
//package pkg1270b; 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 array[]=new int[n+1]; for(int i=1;i<=n;i++) { array[i]=sc.nextInt(); } int flage=0; int l=1; while(flage==0 && l<n) { if(Math.abs(array[l+1] - array[l])>1) { flage=1; System.out.println("YES"); System.out.println(l+" "+(l+1)); } l++; } if(flage==0) { System.out.println("NO"); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
71bf5c3cee33e13dfa4b10772a45c9a5
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main implements Runnable { boolean multiple = true; void solve() throws Exception { int n = sc.nextInt(); long prev = sc.nextLong(); for (int i = 1; i < n; i++) { long curr = sc.nextLong(); if (abs(prev-curr) >= 2) { System.out.println("YES"); System.out.println((i) + " " + (i+1)); for (int j = i + 1; j < n; j++) { sc.nextLong(); } return; } prev = curr; } System.out.println("NO"); } @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new FastScanner(in); if (multiple) { int q = sc.nextInt(); for (int i = 0; i < q; i++) solve(); } else solve(); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); } } public static void main(String[] args) throws Throwable { Thread thread = new Thread(null, new Main(), "", (1 << 26)); thread.start(); thread.join(); if (Main.uncaught != null) { throw Main.uncaught; } } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
951ebf6c294429970d1fc0f943336bb1
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.Scanner; public class B2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int k = 0; k < t; k++) { int n = scanner.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scanner.nextInt(); } int i; for (i = 0; i < n - 1; i++) { if (Math.abs(arr[i] - arr[i + 1]) >= 2) { System.out.println("YES"); System.out.println((i + 1) + " " + (i + 2)); break; } } if (i == n - 1) { System.out.println("NO"); } } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
b8cb689c51409c0bec13aee436eb2b11
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf1270b { public static void main(String[] args) throws IOException { int t = ri(); next: while (t --> 0) { int n = ri(), a[] = ria(n); for (int i = 0; i < n - 1; ++i) { if (abs(a[i + 1] - a[i]) > 1) { prY(); prln(i + 1, i + 2); continue next; } } prN(); } close(); } static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static Random __rand = new Random(); // references // IBIG = 1e9 + 7 // IMAX ~= 2e10 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final int IMIN = -2147483648; static final long LMAX = 9223372036854775807L; static final long LMIN = -9223372036854775808L; // 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 gcf(int a, int b) {return b == 0 ? a : gcf(b, a % b);} static long gcf(long a, long b) {return b == 0 ? a : gcf(b, a % b);} static int randInt(int min, int max) {return __rand.nextInt(max - min + 1) + min;} static long hash(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);} // 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(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 rsort(int[] a) {shuffle(a); sort(a);} static void rsort(long[] 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 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 int[] sorted(int[] a) {int[] ans = copy(a); sort(ans); return ans;} static long[] sorted(long[] a) {long[] ans = copy(a); sort(ans); return ans;} static int[] rsorted(int[] a) {int[] ans = copy(a); rsort(ans); return ans;} static long[] rsorted(long[] a) {long[] ans = copy(a); rsort(ans); return ans;} // graph util static List<List<Integer>> graph(int n) {List<List<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;} static List<List<Integer>> graph(List<List<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;} static List<List<Integer>> graph(int n, int m) throws IOException {return graph(graph(n), m);} static List<List<Integer>> dgraph(List<List<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;} static List<List<Integer>> dgraph(List<List<Integer>> g, int n, int m) throws IOException {return dgraph(graph(n), m);} static List<Set<Integer>> sgraph(int n) {List<Set<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;} static List<Set<Integer>> sgraph(List<Set<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;} static List<Set<Integer>> sgraph(int n, int m) throws IOException {return sgraph(sgraph(n), m);} static List<Set<Integer>> dsgraph(List<Set<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;} static List<Set<Integer>> dsgraph(List<Set<Integer>> g, int n, int m) throws IOException {return dsgraph(sgraph(n), m);} static void connect(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);} static void connecto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);} static void dconnect(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);} static void dconnecto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);} // input static void r() throws IOException {input = new StringTokenizer(__in.readLine());} static int ri() throws IOException {return Integer.parseInt(__in.readLine());} static long rl() throws IOException {return Long.parseLong(__in.readLine());} static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;} static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;} static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;} static char[] rcha() throws IOException {return __in.readLine().toCharArray();} static String rline() throws IOException {return __in.readLine();} static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());} static int ni() {return Integer.parseInt(input.nextToken());} static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());} static long nl() {return Long.parseLong(input.nextToken());} // output static void pr(int i) {__out.print(i);} static void prln(int i) {__out.println(i);} static void pr(long l) {__out.print(l);} static void prln(long l) {__out.println(l);} static void pr(double d) {__out.print(d);} static void prln(double d) {__out.println(d);} static void pr(char c) {__out.print(c);} static void prln(char c) {__out.println(c);} static void pr(char[] s) {__out.print(new String(s));} static void prln(char[] s) {__out.println(new String(s));} static void pr(String s) {__out.print(s);} static void prln(String s) {__out.println(s);} static void pr(Object o) {__out.print(o);} static void prln(Object o) {__out.println(o);} static void prln() {__out.println();} static void pryes() {__out.println("yes");} static void pry() {__out.println("Yes");} static void prY() {__out.println("YES");} static void prno() {__out.println("no");} static void prn() {__out.println("No");} static void prN() {__out.println("NO");} static void pryesno(boolean b) {__out.println(b ? "yes" : "no");}; static void pryn(boolean b) {__out.println(b ? "Yes" : "No");} static void prYN(boolean b) {__out.println(b ? "YES" : "NO");} static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();} static void h() {__out.println("hlfd");} static void flush() {__out.flush();} static void close() {__out.close();} }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
c832c6246ad7f0d3f22f82ae0a5ee711
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { static void solve() throws Exception { int tests = scanInt(); for (int test = 0; test < tests; test++) { int n = scanInt(); int maxSum = Integer.MIN_VALUE, maxSumPos = -1, minDif = Integer.MAX_VALUE, minDifPos = -1; int ansL = -1, ansR = -1; for (int i = 0; i < n; i++) { int a = scanInt(); if (a + i >= maxSum) { maxSum = a + i; maxSumPos = i; } else { ansL = maxSumPos; ansR = i; } if (a - i <= minDif) { minDif = a - i; minDifPos = i; } else { ansL = minDifPos; ansR = i; } } if (ansL < 0) { out.println("NO"); } else { out.println("YES"); out.println((ansL + 1) + " " + (ansR + 1)); } } } static int scanInt() throws IOException { return parseInt(scanString()); } static long scanLong() throws IOException { return parseLong(scanString()); } static String scanString() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } static BufferedReader in; static PrintWriter out; static StringTokenizer tok; public static void main(String[] args) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); exit(1); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
c32daef26f236d07d2fea1669ed40889
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.*; public class Main { static class Reader { BufferedReader br; StringTokenizer st; BufferedWriter bw; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); bw = new BufferedWriter(new OutputStreamWriter(System.out)); } 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; } void pr(String s){ try{ bw.write(s); } catch(Exception e){ e.printStackTrace(); } } void prln(String s){ try{ bw.write(s+"\n"); } catch(Exception e){ e.printStackTrace(); } } void close(){ try{ bw.close(); } catch(Exception e){ e.printStackTrace(); } } } public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Reader r=new Reader(); int q=r.nextInt(); while(q-->0){ int n=r.nextInt(); int a[]=new int[n]; int l=-1,h=-1; for(int i=0;i<n;++i){ a[i]=r.nextInt(); //if(i>0&&a[i]<a[mini])mini=i; } //boolean flag=false; for(int i=1;i<=n-1;++i){ if(Math.abs(a[i]-a[i-1])>=2){ l=i;h=i+1;break; } } if(l==h)r.prln("NO"); else r.prln("YES\n"+l+" "+h); } r.close(); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
1b629fed1d5414a680fa4305311cd63c
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; public class JavaApplication14 { public static void main(String[] args) { Scanner io = new Scanner(System.in); int t = io.nextInt(); while(t-- != 0) { int n = io.nextInt(); int[] arr = new int[n]; boolean flag = true; for(int i = 0; i < n; i++) arr[i] = io.nextInt(); for(int i = 1; i < n; i++) { if(Math.abs(arr[i]-arr[i-1]) > 1) { System.out.println("YES"); System.out.println(i + " " + (int)(i+1)); flag = false; break; } } if(flag) System.out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
023b210ddeba50d99f4cc7354e378fd5
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; import java.io.*; public class Main { static final int MOD_PRIME = 1000000007; public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); int i = 0; int t = 1; t = in.nextInt(); for (; i < t; i++) solver.solve(i, in, out); out.close(); } static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] ar = new int[n]; for(int i = 0; i < n; i++) { ar[i] = in.nextInt(); } for(int i = 0; i < ar.length - 1; i++) { if(Math.abs(ar[i+1] - ar[i]) >= 2) { out.println("YES"); out.println((i+1) + " " + (i+2)); return; } } out.println("NO"); } } // template code static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } static long modexp(long a, long b, long p) { // returns a to the power b mod p by modular exponentiation long res = 1; long mult = a % p; while (b > 0) { if (b % 2 == 1) { res = (res * mult) % p; } b /= 2; mult = (mult * mult) % p; } return res; } static double log(double arg, double base) { // returns log of a base b, contains floating point errors, dont use for exact // calculations. if (base < 0 || base == 1) { throw new ArithmeticException("base cant be 1 or negative"); } if (arg < 0) { throw new ArithmeticException("log of negative number undefined"); } return Math.log10(arg) / Math.log10(base); } 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); } // scope for improvement static ArrayList<Integer> sieveOfEratosthenes(int n) { boolean[] check = new boolean[n + 1]; ArrayList<Integer> prime = new ArrayList<Integer>(); for (long i = 2; i <= n; i++) { if (!check[(int) i]) { prime.add((int) i); for (long j = i * i; j <= n; j += i) { check[(int) j] = true; } } } return prime; } static int modInverse(int a, int n) { // returns inverse of a mod n by extended euclidean algorithm int t = 0; int newt = 1; int r = n; int newr = a; int quotient; int tempr, tempt; while (newr != 0) { quotient = r / newr; tempt = newt; tempr = newr; newr = r - quotient * tempr; newt = t - quotient * tempt; t = tempt; r = tempr; } if (r > 1) { throw new ArithmeticException("inverse of " + a + " mod " + n + " does not exist"); } else { if (t < 0) { t += n; } return t; } } static int primeModInverse(int a, int n) { // returns inverse of a mod n by mod exponentiation, use only if n is prime return (int) modexp(a, n - 2, n); } static void dfs(HashMap<Integer, ArrayList<Integer>> adj, Set<Integer> ans, Set<Integer> open, HashMap<String, Integer> edge, boolean[] vis, int i) { vis[i] = true; open.add(i); if (adj.get(i) != null) { for (int k : adj.get(i)) { if (!vis[k]) { dfs(adj, ans, open, edge, vis, k); } else if (open.contains(k)) { ans.add(edge.get(String.valueOf(i) + " " + String.valueOf(k))); } } } open.remove(i); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
e5dd8f9b0efb338ce0f812b5fa216220
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Vaibhav Pulastya */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); BInterestingSubarray solver = new BInterestingSubarray(); solver.solve(1, in, out); out.close(); } static class BInterestingSubarray { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int[] a = in.nextIntArray(n); boolean ok = false; for (int i = 0; i < n - 1; i++) { if (Math.abs(a[i + 1] - a[i]) >= 2) { out.println("YES"); out.println((i + 1) + " " + (i + 2)); ok = true; break; } } if (!ok) { out.println("NO"); } } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; 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; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] nextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
96d9e03a1d2aebd3497ba4d06ce7fa04
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class CFGB19B { public void solve(Scanner in, PrintWriter out) { int t = in.nextInt(); for (int q = 0; q < t; q++) { int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } int l = -1; int r = -1; for (int i = 1; i < n; i++) { if (Math.abs(arr[i] - arr[i - 1]) >= 2) { l = i; r = i + 1; break; } } if (l == -1) { out.println("NO"); } else { out.println("YES"); out.println(l + " " + r); } } } public static void main(String[] args) { new CFGB19B().run(); } public void run() { try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out)) { solve(in, out); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
5ce12662374b5774020926d715fe69da
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.*; import java.util.*; public class B { static void solve(FastIO io) { int n = io.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = io.nextLong(); long[] left = new long[n]; long[] right = new long[n]; for (int i = 0; i < n; i++) { left[i] = a[i] - i; right[n-1-i] = a[n-i-1] - i; } long min = (long)1e10; int minIdx = -1; int l = -1, r = -1; for (int i = 0; i < n; i++) { if (left[i] < min) { min = left[i]; minIdx = i; } // io.println(left[i] + " " + (left[i]-min)); if (left[i] - min > 0) { // io.println(minIdx + " !!!" + (i)); l = minIdx; r = i; break; } } if (l < 0 || r < 0) { min = (long)1e10; minIdx = -1; for (int i = n-1; i >= 0; i--) { if (right[i] < min) { min = right[i]; minIdx = i; } if (right[i] - min > 0) { l = minIdx; r = i; break; } } } // io.println(Arrays.toString(left)); // io.println(Arrays.toString(right)); if (l >= 0 && r >= 0) io.printf("YES%n%d %d%n", Math.min(l, r)+1, Math.max(l, r)+1); else io.println("NO"); } public static void main(String[] args) { FastIO io = new FastIO(); int t = io.nextInt(); for (int i = 0; i < t; i++) solve(io); io.close(); } } class FastIO extends PrintWriter { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); FastIO() { super(System.out); } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(r.readLine()); } catch (Exception e) { //TODO: handle exception } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
9f3aeab18c697ad731a745844e8b41c2
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Xbenx */ public class InterestingSubarray { public static void main(String[] args) { Scanner input=new Scanner(System.in); int t =input.nextInt(); int o=0; back: for(;o<t;o++) { int n=input.nextInt(); long a[]=new long[n]; for(int i=0;i<n;a[i]=input.nextLong(),i++); for (int i = 1; i <n ; i++) { if (Math.abs(a[i]-a[i-1])>1){ System.out.println("YES"); System.out.println(i+" "+(i+1)); continue back; } } System.out.println("NO"); }}}
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
2d8b772d826b989d9543f819ea56fec0
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Karan Mehta */ 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); BInterestingSubarray solver = new BInterestingSubarray(); solver.solve(1, in, out); out.close(); } static class BInterestingSubarray { public void solve(int testNumber, InputReader c, OutputWriter w) { int tc = c.readInt(); while (tc-- > 0) { int n = c.readInt(); int a[] = c.readIntArray(n); boolean fg = true; for (int i = 1; i < n; i++) { if (Math.abs(a[i] - a[i - 1]) > 1) { w.printLine("YES"); w.printLine(i, i + 1); fg = false; break; } } if (fg) { w.printLine("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[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = readInt(); } return array; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
13b3089ce796e0be2b11c43a0f6a7c61
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.util.*; public class InterestingSubarray{ static Scanner in=new Scanner(System.in); public static void main(String array[]){ int t=in.nextInt(); while(t-->0){ int n=in.nextInt(),a[]=new int[n]; for(int i=0;i<n;i++) a[i]=in.nextInt(); boolean check=true; for(int i=0;i<n-1;i++){ if(Math.abs(a[i]-a[i+1])>=2){ System.out.println("yes"); System.out.println((i+1)+" "+(i+2)); check=false; break; } } if(check) System.out.println("no"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
b25a3d5ff9f23e6a24d07a937d8b6262
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class pre346 { 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 obj = new FastReader(); int tc = obj.nextInt(); while(tc--!=0) { int n = obj.nextInt(),arr[] = new int[n]; for(int i=0;i<n;i++) arr[i] = obj.nextInt(); boolean flag = false; for(int i=0;i<n-1;i++) { if(Math.abs(arr[i+1]-arr[i])>1) { System.out.println("YES\n"+(i+1)+" "+(i+2)); flag = true; break; } } if(!flag)System.out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
b29e4a81fcf806fb83f8f5c836c1b080
train_004.jsonl
1577628300
For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 &lt; 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
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 x=0;x<t;x++) { int n=sc.nextInt(); int arr[]=new int[n]; boolean b=true; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); for(int i=1;i<n;i++) { if((int)Math.abs(arr[i]-arr[i-1])>=2) { System.out.println("YES"); System.out.println(i+" "+(i+1)); b=false; break; } } if(b) System.out.println("NO"); } } }
Java
["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"]
2 seconds
["NO\nYES\n1 4\nNO"]
NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.
Java 11
standard input
[ "constructive algorithms", "greedy", "math" ]
fa16d33fb9447eea06fcded0026c6e31
The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
1,200
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).
standard output
PASSED
33cc93a5c1cb7799b4803e711e2236b3
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.*; public class Main { static int n; static Scanner s; static int in[][]; static HashMap<Integer,Boolean>map; public static void main(String[]args) { s=new Scanner(System.in); n=s.nextInt(); in=new int[n][2]; for(int c=0;c<n;c++) { String temp=s.next(); if(temp.equals("+")) { in[c][0]=1; in[c][1]=s.nextInt(); } else { in[c][0]=0; in[c][1]=s.nextInt(); } } System.out.println(cal()); } static int cal() { map=new HashMap<Integer,Boolean>(); int cap[]=new int[n]; int current[]=new int[n]; for(int c=0;c<n;c++) { if(in[c][0]==1) { if(c==0) { current[c]=1; cap[c]=1; } else { current[c]=current[c-1]+1; cap[c]=cap[c-1]; if(cap[c]<current[c]) { cap[c]=current[c]; } } map.put(in[c][1],true); } else { if(c==0) { current[c]=0; cap[c]=1; } else { if(map.get(in[c][1])==null) { current[c]=current[c-1]; cap[c]=cap[c-1]+1; } else { map.put(in[c][1],null); if(current[c-1]>0) { current[c]=current[c-1]-1; } else { current[c]=0; } cap[c]=cap[c-1]; } } } } // print(current); // System.out.println(); //print(cap); return cap[n-1]; } static void print(int array[]) { for(int c=0;c<array.length;c++) { System.out.print(array[c]+" "); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
ad94e843dcaa5c79281daac03a3fbb83
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
/** * Created by IntelliJ IDEA. * User: Hamza Hasbi "h.hamza" * Date: 02-Sep-16 * Time: 12:31 AM * Blog :www.hamzahasbi.me */ import java.util.*; import java.io.*; public class Berland_National_Library { public static void main(String[] args) throws java.lang.Exception { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter ps=new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(input.readLine()); int ans = 0, y = 0; String a; int x; Set<Integer> mp=new HashSet<Integer>(); for(int i=0;i<n;i++){ String[] p = input.readLine().split(" "); a = p[0]; x = Integer.parseInt(p[1]); if (a.equals("+")) { y++; mp.add(x); } else { if (mp.contains(x)) y--; else ans++; } ans = Math.max(ans, y); } System.out.printf("%d",ans); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
956f2da7962331051100b49deda24bac
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.*; public class BerlanLibrary{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int nn = sc.nextInt(); ArrayList<Integer> e = new ArrayList<Integer>(); ArrayList<Integer> l = new ArrayList<Integer>(); int n=0; int min=0; for(int i=0;i<nn;i++){ String s = sc.next(); int r = sc.nextInt(); if(s.equals("+")) { e.add(r); if(l.indexOf(r)!=-1){ l.remove(l.indexOf(r)); n++; if(n>min)min=n; } else{ n++; if(n>min)min=n; } } if(s.equals("-")){ l.add(r); if(e.indexOf(r)!=-1){ e.remove(e.indexOf(r)); n--; } else{ min++; } } //System.out.println(l.size() + " " + e.size() + " " + n+ " " + min); } System.out.println(min); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
6acd827ec8f44d81cdc9608c2059af87
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; import java.util.Set; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = Integer.valueOf(in.nextLine()); // HashMap<Integer,Boolean> map = new HashMap<Integer, Boolean>(); boolean stat[] = new boolean[n]; int id[] = new int[n]; for (int i = 0; i < n; i++) { String s = in.nextLine(); String st[] = s.split(" "); stat[i] = st[0].equals("+") ? true : false; id[i] = Integer.valueOf(st[1]); } //find number of existing visitors. Set<Integer> set = new HashSet<Integer>(); int res = 0; for (int i = 0; i < n; i++) { if (stat[i]) set.add(id[i]); else { if (set.contains(id[i])) set.remove(id[i]); else ++res; } } int ret = 0; set.clear(); for (int i = 0; i < n; i++) { ret = Math.max(ret, res + set.size()); if (stat[i]) set.add(id[i]); else { if (set.contains(id[i])) set.remove(id[i]); else --res; } } ret = Math.max(ret, res + set.size()); out.print(ret); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
a3f9c34c25ae0d83af5940f502674713
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.Scanner; public class main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[1000001]; int count=0; sc.nextLine(); int maxcount=count; int c=0; String a[][]=new String[n][]; for(int i=0;i<n;i++){ String x=sc.nextLine(); a[i]=x.split(" "); if(a[i][0].equals("+")){ arr[Integer.parseInt(a[i][1])]=1; } else{ if(arr[Integer.parseInt(a[i][1])]==1){ arr[Integer.parseInt(a[i][1])]=0; } else{ c++; } } } count=c; maxcount=count; //System.out.println(count); for(int i=0;i<n;i++){ if(a[i][0].equals("+")){ count++; arr[Integer.parseInt(a[i][1])]=1; } else{ arr[Integer.parseInt(a[i][1])]=0; count--; } if(maxcount<count) maxcount=count; } System.out.println(maxcount); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
8161aba82bf96b0e290b2508add070b1
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.HashSet; import java.util.Scanner; public class cf567b { public static void main(String[] args) { Scanner in = new Scanner(System.in); short numRecords = in.nextShort(); int newRecord; int minCapacityCurr = 0; int minCapacityNew = 0; HashSet<Integer> wasEntering = new HashSet<>(); for(short s=0;s<numRecords;s++){ if(in.next().charAt(0)=='+'){ wasEntering.add(in.nextInt()); minCapacityNew = wasEntering.size(); minCapacityCurr = Math.max(minCapacityCurr,minCapacityNew); }else{ newRecord = in.nextInt(); if(wasEntering.contains(newRecord)){ wasEntering.remove(newRecord); }else{ minCapacityCurr++; } } } System.out.println(minCapacityCurr); in.close(); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
c4b9ca0ffd3930106811a67a4f95648c
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.Scanner; public class wjd { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n=1000000; int m=input.nextInt(); int[] ar = new int[m]; boolean[] el = new boolean[m]; boolean[] ok = new boolean[n+1]; for(int i=0 ; i<=n ; i++) ok[i] = false; for(int i=0 ; i<m ; i++) el[i] = false; int cur=0; for(int i=0 ; i<m ; i++){ String str = input.next(); ar[i] = input.nextInt(); if(str.equals("-")){ if(ok[ar[i]]==false) cur++; el[i]=false; } else el[i]=true; ok[ar[i]]=el[i]; } int ans=cur; for(int i=0 ; i<m ; i++){ if(el[i]) cur++; else cur--; ans=Math.max(ans, cur); } System.out.println(ans); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
551545ee4ac15f7388898a5d152a7b4e
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.Scanner; public class B { final int asdf = 1000001; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int people[] = new int[n+10]; for(int i=0; i < n+10; i++) people[i] = 0; boolean[] enteredRoom = new boolean[1000001]; for(int i=1; i<=n; i++){ char c = in.next().charAt(0); int id = in.nextInt(); if(c=='+'){ enteredRoom[id] = true; for(int j=i; j<= n; j++) people[j]++; } else{ if(enteredRoom[id]==true){ for(int j=i; j<=n; j++) people[j]--; } else{ for(int j=0;j <i; j++) people[j]++; } enteredRoom[id] = false; } } int maxi = -1; for(int i=0; i <=n; i++){ maxi = Math.max(maxi,people[i]); } System.out.println(maxi); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
14fa2d0c9752f4ed9aba0959512b725b
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.*; import java.nio.Buffer; import java.util.*; public class codeforces { // public static long fact[]; // public static int mod=1000000007; public static long []st; public static void main(String[] args) throws IOException { InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); // BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=in.nextInt(); int count=0; int state=0; boolean []a=new boolean[1000007]; Arrays.fill(a,false); for (int i=0;i<n;i++) { String str=in.readString(); int register=in.nextInt(); if(str.charAt(0)=='+') { state++; a[register]=true; }else if(str.charAt(0)=='-' && a[register]) { // out.println("aya"); state--; a[register]=false; }else if(str.charAt(0)=='-' && !a[register] ) { count++; a[register]=false; } count=Math.max(count,state); } out.println(count); out.close(); } public static int nextPowerOf2(final int a) { int b = 1; while (b < a) { b = b << 1; } return b; } public static long []contruct(long []a) { int next2power=nextPowerOf2(a.length); st=new long[next2power*2-1]; //System.out.println(size); // st=new long[size]; Arrays.fill(st,Integer.MAX_VALUE); constructST(a,0,a.length-1,0); return st; } public static void constructST(long []a,int start,int end,int pos) { if(start==end) { st[pos]=a[start]; return ; } int mid=(start+end)>>1; constructST(a,start,mid,pos*2+1); constructST(a,mid+1,end,pos*2+2); st[pos]=st[2*pos+1]^st[2*pos+2]; } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
c0d3b55f3a49ae781a96d0798e3137f5
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * Created by numnikov on 8/11/15. */ public class BerlandNationalLibrary { void solve() throws IOException { int n = nextInt(); Set<Integer> entered = new HashSet<Integer>(); List<String> lines = new ArrayList<String>(); int minCapacity = 0; int initial = 0; for (int i = 0; i < n; ++i) { String s = reader.readLine(); lines.add(s); String sign = s.split(" ")[0]; int index = Integer.parseInt(s.split(" ")[1]); if (sign.equals("-") && !entered.contains(index)) { ++initial; } if (sign.equals("+")) { entered.add(index); } } entered.clear(); int curState = 0; minCapacity = Math.max(initial + curState, minCapacity); for (int i = 0; i < n; ++i) { String s = lines.get(i); String sign = s.split(" ")[0]; int index = Integer.parseInt(s.split(" ")[1]); if (sign.equals("-") && entered.contains(index)) { --curState; } else if (sign.equals("-")) { --initial; } if (sign.equals("+")) { ++curState; entered.add(index); } minCapacity = Math.max(initial + curState, minCapacity); } writer.println(minCapacity); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } StringTokenizer tokenizer; PrintWriter writer; BufferedReader reader; public void run() { try { writer = new PrintWriter(System.out); reader = new BufferedReader(new InputStreamReader(System.in)); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { new BerlandNationalLibrary().run(); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
16335e7a9fb0a00685253d9493ba581a
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.Scanner; public class ArrayList { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int min=0,c=0; boolean f[]=new boolean[10000001]; for (int i=0;i<n;i++) { String s = sc.next(); int r=sc.nextInt(); if(s.charAt(0)=='-'){ if (!f[r]) min++; else c--; } else c++; f[r]=true; if(c>min)min=c; } System.out.println(min); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
182d0853b4f38a6b31d69cbf5821d032
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.Scanner; public class WA { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String c; int r; boolean a[] = new boolean[1000001]; int max=0; int k=0; for (int i=0;i<n;i++) { c = in.next(); r = in.nextInt(); if (c.equals("+")) { k++; a[r]=true; } else { if (a[r]) { k--; a[r]=false; } else { max++; } } if (k>max) { max=k; } //System.out.println(k+" "+max); } System.out.print(max); in.close(); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
a3abe29d8ed309aad60877371fa61b51
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class code314_2B { public static void main(String args[])throws IOException { InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int t=in.readInt(); boolean[] a=new boolean[1000000];int present=0,max=0; for(int t1=0;t1<t;t1++){ String s=in.readString(); int n=in.readInt();;n--; if(s.charAt(0)=='-'){ if(a[n]==false) max++; else {a[n]=false;present--;} }else{ a[n]=true; present++; } max=Math.max(max,present); } out.println(max);out.flush(); } } class InputReader { private InputStream stream; private byte[] buf=new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) {this.stream=stream;} public int read() { if(numChars==-1) throw new InputMismatchException(); if(curChar>=numChars) { curChar=0; try{ numChars=stream.read(buf); }catch(IOException e){ throw new InputMismatchException(); } if(numChars<=0) return -1; } return buf[curChar++]; } public int readInt() { int c=read(); while(isSpaceChar(c)) c=read(); int sgn=1; if(c=='-') { sgn=-1; c=read(); } int res=0; do{ if(c<'0'||c>'9') throw new InputMismatchException(); res*=10; res+=c-'0'; c=read(); }while(!isSpaceChar(c)); return res*sgn; } public long readLong() { int c=read(); while(isSpaceChar(c)) c=read(); int sgn=1; if(c=='-') { sgn=-1; c=read(); } long res=0; do{ if(c<'0'||c>'9') throw new InputMismatchException(); res*=10; res+=c-'0'; c=read(); }while(!isSpaceChar(c)); return res*sgn; } public int[] readArray(int len) { int c=read(); while(isSpaceChar(c)) c=read(); int sgn=1; if(c=='-') { sgn=-1; c=read(); } int[] res=new int[len];int j=0; do{ if(c<'0'||c>'9') throw new InputMismatchException(); //res*=10; res[j++]=c-'0'; c=read(); }while(!isSpaceChar(c)); return res; } public String readString() { int c=read(); while(isSpaceChar(c)) c=read(); StringBuilder res=new StringBuilder(); do{ res.appendCodePoint(c); c=read(); }while(!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if(filter!=null) return filter.isSpaceChar(c); return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
fde428f83f0c1c5b762b44e8c7feeb2a
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; import java.util.stream.IntStream; import static java.lang.Math.max; public class AProb2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); List<String> input = IntStream.range(0, n) .mapToObj(i -> sc.nextLine()) .collect(Collectors.toList()); solve(input); } private static void solve(List<String> input) { int cap = 0; HashSet<String> set = new HashSet<>(); for (String s : input) { String[] split = s.split("\\s"); if (split[0].equals("+")) { set.add(split[1]); cap = max(cap, set.size()); } else { if (set.contains(split[1])) { set.remove(split[1]); } else { cap++; } } } System.out.println(cap); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
cb431f1ea1f4015ca5c639d050d63870
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.Set; import java.util.InputMismatchException; import java.io.IOException; import java.util.HashSet; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Hippskill (Hippskill@gmail.com) */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); Set<Integer> was = new HashSet<>(); int ans = 0; for (int i = 0; i < n; i++) { if (in.readCharacter() == '+') { was.add(in.readInt()); ans = Math.max(ans, was.size()); } else { int man = in.readInt(); if (!was.contains(man)) ans++; was.remove(man); } } out.printLine(Math.max(ans, was.size())); } } 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 close() { writer.close(); } public void printLine(int i) { writer.println(i); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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 char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
557a09c82289ad1a33ef56739985f999
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; public class ProblemSet_567B { FastScanner in; PrintWriter out; ArrayList<ArrayList<Integer>> tree; int[] arrDepth; public void solve() throws IOException { int n = in.nextInt(); boolean modeEnter; int id; Set<Integer> visitors = new HashSet<>(); int numVisitorBefore = 0; int currentVisitor = 0; Guess[] guesses = new Guess[n+1]; guesses[0] = new Guess(0,0); for(int i = 1; i <= n; i++){ modeEnter = (in.next().charAt(0) == '+'); id = in.nextInt(); if(modeEnter){ visitors.add(id); currentVisitor++; } else { if(visitors.contains(id)) { visitors.remove(id); currentVisitor--; } else { numVisitorBefore++; } } guesses[i] = new Guess(numVisitorBefore, currentVisitor); } int max = 0; for(Guess g : guesses){ max = Math.max(max, g.currentVisitor + numVisitorBefore - g.knownBefore); } out.println(max); } public class Guess{ int knownBefore; int currentVisitor; public Guess(int i, int j){ knownBefore = i; currentVisitor = j; } } public void run() throws IOException { // try { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); // } catch (IOException e) { // e.printStackTrace(); // } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) { // try { st = new StringTokenizer(br.readLine()); // } catch (IOException e) { // e.printStackTrace(); // } } return st.nextToken(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } } public static void main(String[] arg) throws IOException { new ProblemSet_567B().run(); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
4faf94c21fd4986c2ff7ba74af852ee1
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.*; import java.util.Scanner; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import javax.lang.model.util.ElementScanner6; public class B567 { 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 in=new FastReader(); int t=1; //t=in.nextInt(); while(t-->0) { int n=in.nextInt(); HashSet<Integer> hset1=new HashSet<>(); HashSet<Integer> hset2=new HashSet<>(); int count=0; int vac=0; for(int i=0;i<n;i++) { String S=in.nextLine(); int num=Integer.parseInt(S.substring(2,S.length())); char ch=S.charAt(0); if(ch=='-') { if(!hset1.contains(num)) { count++; vac++; hset1.remove(num); } else { vac++; } } else { hset1.add(num); if(vac>=1) { vac--; } else { count++; } } } System.out.println(count); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
91772a22a06c1efa67a07f53e78f54f0
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.*; import java.util.*; public class HackerCup1 { public static void main(String[] args) throws Throwable { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int ans=0; boolean[] taken = new boolean[((int)1e6)+2]; int[][] arr = new int[n][2]; for (int i = 0; i < n; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); char c = st.nextToken().charAt(0); int x = Integer.parseInt(st.nextToken()); arr[i][0] = c=='+'? 1:0; arr[i][1] = x; } for (int i = 0; i < arr.length; i++) { if(arr[i][0]==1) { taken[arr[i][1]] = true; } else { if(!taken[arr[i][1]]) ans++; } } int cur = ans; for (int i = 0; i < arr.length; i++) { if(arr[i][0]==1) { cur++; } else { cur--; } ans = Math.max(ans, cur); } System.out.println(ans); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
00e21e970030959de7439e29a3cc2bf0
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { try (Scanner scan= new Scanner(System.in)) { ArrayList<Integer> add = new ArrayList<Integer>(); ArrayList<Integer> sub = new ArrayList<Integer>(); ArrayList<Character> ops = new ArrayList<Character>(); int n = scan.nextInt(); int start = 0; int max = -1; int count = 0; for (int i = 0; i < n; i++) { char op = scan.next().charAt(0); ops.add(op); int num = scan.nextInt(); if (op=='+') { add.add(num); } else { if (!add.contains(num)) { start++; } sub.add(num); } } count = start; for (int i = 0; i < n; i++) { if (count>max)max=count; if (ops.get(i)=='+') { count++; }else { count--; } } if(count>max)max=count; if (n==1) { System.out.println("1"); return; } System.out.println(max); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
e509332a146df2284482893496c43b7d
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.IOException; import java.util.InputMismatchException; import java.io.PrintWriter; import java.io.OutputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); boolean[] t = new boolean[1000010]; int cap = 0; int cur = 0; for (int i = 0; i < n; i++) { String s = in.readLine(); String[] ar = s.split(" "); if (ar[0].charAt(0) == '+') { cur++; t[Integer.valueOf(ar[1])] = true; } else if (ar[0].charAt(0) == '-' && t[Integer.valueOf(ar[1])]) { cur--; } else if (ar[0].charAt(0) == '-' && !t[Integer.valueOf(ar[1])]) cap++; cap = Math.max(cap, cur); } out.print(cap); } } 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 readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } 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 close() { writer.close(); } public void print(int i) { writer.print(i); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
fd8fd74a9bc24dfddec654f248ce45f5
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.IOException; import java.util.InputMismatchException; import java.io.PrintWriter; import java.io.OutputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); boolean[] t = new boolean[1000010]; int cap = 0; int cur = 0; for (int i = 0; i < n; i++) { String s = in.readLine(); String[] ar = s.split(" "); if (ar[0].charAt(0) == '+' && !t[Integer.valueOf(ar[1])]) { cur++; t[Integer.valueOf(ar[1])] = true; } else if (ar[0].charAt(0) == '-' && t[Integer.valueOf(ar[1])]) { cur--; t[Integer.valueOf(ar[1])] = false; } else if (ar[0].charAt(0) == '-' && !t[Integer.valueOf(ar[1])]) cap++; cap = Math.max(cap, cur); } out.print(cap); } } 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 readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } 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 close() { writer.close(); } public void print(int i) { writer.print(i); } } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
de993c26ed2c4df40cb51070d281512d
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main (String[] args) throws java.lang.Exception { HashMap<Integer,Integer> entry =new HashMap<>(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine(); int t = Integer.parseInt(s); int count = 0; int max =0; int l = 0; while(t-->0) { s= br.readLine(); String in[] = s.split(" "); String sign = in[0]; int num = Integer.parseInt(in[1]); if(sign.equals("+")) { count++; entry.put(num,num); if(max<count) max=count; } else if(sign.equals("-")) { if(entry.containsKey(num)) { count--; entry.remove(num); } else { max++; } } } System.out.println(max); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output
PASSED
faeee491162aab1d4aad22f50004bb46
train_004.jsonl
1438790400
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: "+ ri" — the reader with registration number ri entered the room; "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
256 megabytes
import java.util.Scanner; public class S0_2 { public static void main(String args[]) { Scanner input=new Scanner(System.in); int n=input.nextInt(); input.nextLine(); boolean a[]=new boolean[1000001]; boolean b[]=new boolean[1000001]; int in=0,max=0,ans=0; while(n-->0) { String str=input.nextLine(); String tmp[]=str.split(" "); if(tmp[0].equals("+")) { a[Integer.parseInt(tmp[1])]=true; if(in==max) { max++; } in++; } else { if(a[Integer.parseInt(tmp[1])]) { a[Integer.parseInt(tmp[1])]=false; in--; } else{ max++; } } } System.out.println(max); } }
Java
["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1"]
1 second
["3", "2", "1"]
NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
Java 8
standard input
[ "implementation" ]
6cfd3b0a403212ec68bac1667bce9ef1
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
1,300
Print a single integer — the minimum possible capacity of the reading room.
standard output