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
be0aa3d39118f792b9aafd3c5075b39c
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; public class Main { public static void main(String[] args) throws Exception { Sol obj=new Sol(); obj.runner(); } } class Sol{ FastScanner fs=new FastScanner(); Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); void runner() throws Exception{ int T=1; //T=sc.nextInt(); //preCompute(); T=fs.nextInt(); while(T-->0) { solve(T); } out.close(); System.gc(); } private void solve(int T) throws Exception { int n=fs.nextInt(); long l=fs.nextLong(); long r=fs.nextLong(); long arr[]=new long[n+1]; for( int i=1;i<=n;i++ ) { arr[i]= (( l+i-1 )/i) *i; } boolean flag=true; for( int i=1;i<=n;i++ ) { if( arr[i]<l || arr[i]>r ) { flag=false; break; } } if( !flag ) { System.out.println("NO"); return ; } System.out.println("YES"); for( int i=1;i<=n;i++ ) { System.out.print(arr[i]+" "); } System.out.println(); /**/ } private void preCompute() { } static class FastScanner { BufferedReader br; StringTokenizer st ; FastScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } FastScanner(String file) { try { br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); st = new StringTokenizer(""); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("file not found"); e.printStackTrace(); } } String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } String readLine() throws IOException{ return br.readLine(); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
48d4e479322e067c239bb0d09b621cb7
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class q1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.next()); while (t-- > 0) { int n = Integer.parseInt(sc.next()); long l = Long.parseLong(sc.next()); long r = Long.parseLong(sc.next()); long[] ans = new long[n]; boolean flag = false; for(int i=0;i<n;i++){ if(l%(i+1)==0){ ans[i] = l; }else{ long rem = l%(i+1); rem = (i+1)-rem; if(l+rem<=r){ ans[i] = l+rem; }else{ flag = true; break; } } } if(flag){ System.out.println("NO"); }else{ System.out.println("YES"); for(int i=0;i<n;i++){ System.out.print(ans[i]+" "); } System.out.println(""); } } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
3056a6e978093b10ba404145bad5da70
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; public class cp { static PrintWriter w = new PrintWriter(System.out); static FastScanner s = new FastScanner(); public static void main(String[] args) { { int t = s.nextInt(); // int t = 1; while (t-- > 0) { solve(); } w.close(); } } static class Edge { int src; int wt; int nbr; Edge(int src, int nbr, int et) { this.src = src; this.wt = et; this.nbr = nbr; } } class EdgeComparator implements Comparator<Edge> { @Override //return samllest elemnt on polling public int compare(Edge s1, Edge s2) { if (s1.wt < s2.wt) { return -1; } else if (s1.wt > s2.wt) { return 1; } return 0; } } /* 1 2 4 8 16 32 3 6 9 18 5 10 20 */ static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static int noofdivisors(int n) { //it counts no of divisors of every number upto number n int arr[] = new int[n + 1]; for (int i = 1; i <= (n); i++) { for (int j = i; j <= (n); j = j + i) { arr[j]++; } } return arr[0]; } static char[] reverse(char arr[]) { char[] b = new char[arr.length]; int j = arr.length; for (int i = 0; i < arr.length; i++) { b[j - 1] = arr[i]; j = j - 1; } return b; } static long factorial(int n) { if (n == 0) { return 1; } long su = 1; for (int i = 1; i <= n; i++) { su *= (long) i; } return su; } 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(); } long[] readArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void solve() { int n =s.nextInt();//int x =s.nextInt(); int l =s.nextInt(); int r =s.nextInt(); long arr[]= new long[n]; for(int i=0;i<arr.length;i++) { long q = (long)Math.ceil((double)l/(double)(i+1)); arr[i]= (q)*(i+1); if(arr[i]>r) { w.println("NO"); return; } } w.println("YES"); for(long i:arr) w.print(i+" "); w.println(); } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
7d323ec53edb1ebe97485666544e9395
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; // import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import javax.print.attribute.HashAttributeSet; import javax.sound.sampled.BooleanControl; import javax.swing.event.ChangeEvent; import javax.swing.text.Position; import javax.swing.text.StyleConstants; import javax.xml.validation.Validator; // import javax.lang.model.element.QualifiedNameable; // import javax.swing.ViewportLayout; // import javax.swing.plaf.basic.BasicTreeUI.TreeCancelEditingAction; // import javax.swing.plaf.metal.MetalComboBoxUI.MetalPropertyChangeListener; // import javax.swing.text.html.HTMLDocument.HTMLReader.CharacterAction; // import org.w3c.dom.Node; import java.lang.*; import java.math.BigInteger; import java.net.NetworkInterface; import java.text.SimpleDateFormat; import java.beans.beancontext.BeanContext; // import java.net.CookieHandler; // import java.security.SecureRandomParameters; // import java.security.cert.CollectionCertStoreParameters; // import java.text.BreakIterator; import java.io.*; @SuppressWarnings("unchecked") public class Main implements Runnable{ static FastReader in; static PrintWriter out; static int bit(long n) { return (n == 0) ? 0 : (1 + bit(n & (n - 1))); } static void p(Object o) { out.print(o); } static void pn(Object o) { out.println(o); } static void pni(Object o) { out.println(o); out.flush(); } static String n() throws Exception { return in.next(); } static String nln() throws Exception { return in.nextLine(); } static int ni() throws Exception { return Integer.parseInt(in.next()); } static long nl() throws Exception { return Long.parseLong(in.next()); } static double nd() throws Exception { return Double.parseDouble(in.next()); } static class FastReader { static BufferedReader br; static StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception { br = new BufferedReader(new FileReader(s)); } String next() throws Exception { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } } static long power(long a, long b) { if (a == 0L) return 0L; if (b == 0) return 1; long val = power(a, b / 2); val = val * val; if ((b % 2) != 0) val = val * a; return val; } static long power(long a, long b, long mod) { if (a == 0L) return 0L; if (b == 0) return 1; long val = power(a, b / 2L, mod) % mod; val = (val * val) % mod; if ((b % 2) != 0) val = (val * a) % mod; return val; } static ArrayList<Long> prime_factors(long n) { ArrayList<Long> ans = new ArrayList<Long>(); while (n % 2 == 0) { ans.add(2L); n /= 2L; } for (long i = 3; i <= Math.sqrt(n); i++) { while (n % i == 0) { ans.add(i); n /= i; } } if (n > 2) { ans.add(n); } return ans; } static void sort(ArrayList<Long> a) { Collections.sort(a); } static void reverse_sort(ArrayList<Long> a) { Collections.sort(a, Collections.reverseOrder()); } static void swap(long[] a, int i, int j) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(List<Long> a, int i, int j) { long temp = a.get(i); a.set(j, a.get(i)); a.set(j, temp); } static void sieve(boolean[] prime) { int n = prime.length - 1; Arrays.fill(prime, true); for (int i = 2; i * i <= n; i++) { if (prime[i]) { for (int j = i * i; j <= n; j += i) { prime[j] = false; } } } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } /* * ----------------------------------------------------Sorting------------------ * ------------------------------------------------ */ public static void sort(long[] arr, int l, int r) { if (l >= r) return; int mid = (l + r) / 2; sort(arr, l, mid); sort(arr, mid + 1, r); merge(arr, l, mid, r); } public static void sort(int[] arr, int l, int r) { if (l >= r) return; int mid = (l + r) / 2; sort(arr, l, mid); sort(arr, mid + 1, r); merge(arr, l, mid, r); } static void merge(int[] arr, int l, int mid, int r) { int[] left = new int[mid - l + 1]; int[] right = new int[r - mid]; for (int i = l; i <= mid; i++) { left[i - l] = arr[i]; } for (int i = mid + 1; i <= r; i++) { right[i - (mid + 1)] = arr[i]; } int left_start = 0; int right_start = 0; int left_length = mid - l + 1; int right_length = r - mid; int temp = l; while (left_start < left_length && right_start < right_length) { if (left[left_start] < right[right_start]) { arr[temp] = left[left_start++]; } else { arr[temp] = right[right_start++]; } temp++; } while (left_start < left_length) { arr[temp++] = left[left_start++]; } while (right_start < right_length) { arr[temp++] = right[right_start++]; } } static void merge(long[] arr, int l, int mid, int r) { long[] left = new long[mid - l + 1]; long[] right = new long[r - mid]; for (int i = l; i <= mid; i++) { left[i - l] = arr[i]; } for (int i = mid + 1; i <= r; i++) { right[i - (mid + 1)] = arr[i]; } int left_start = 0; int right_start = 0; int left_length = mid - l + 1; int right_length = r - mid; int temp = l; while (left_start < left_length && right_start < right_length) { if (left[left_start] < right[right_start]) { arr[temp] = left[left_start++]; } else { arr[temp] = right[right_start++]; } temp++; } while (left_start < left_length) { arr[temp++] = left[left_start++]; } while (right_start < right_length) { arr[temp++] = right[right_start++]; } } static HashMap<Long, Integer> map_prime_factors(long n) { HashMap<Long, Integer> map = new HashMap<>(); while (n % 2 == 0) { map.put(2L, map.getOrDefault(2L, 0) + 1); n /= 2L; } for (long i = 3; i <= Math.sqrt(n); i++) { while (n % i == 0) { map.put(i, map.getOrDefault(i, 0) + 1); n /= i; } } if (n > 2) { map.put(n, map.getOrDefault(n, 0) + 1); } return map; } static List<Long> divisor(long n) { List<Long> ans = new ArrayList<>(); ans.add(1L); long count = 0; for (long i = 2L; i * i <= n; i++) { if (n % i == 0) { if (i == n / i) ans.add(i); else { ans.add(i); } } } return ans; } // static void smallest_prime_factor(int n) { // smallest_prime_factor[1] = 1; // for (int i = 2; i <= n; i++) { // if (smallest_prime_factor[i] == 0) { // smallest_prime_factor[i] = i; // for (int j = i * i; j <= n; j += i) { // if (smallest_prime_factor[j] == 0) { // smallest_prime_factor[j] = i; // } // } // } // } // } // static int[] smallest_prime_factor; // static int count = 1; // static int[] p = new int[100002]; // static long[] flat_tree = new long[300002]; // static int[] in_time = new int[1000002]; // static int[] out_time = new int[1000002]; // static long[] subtree_gcd = new long[100002]; // static int w = 0; // static boolean poss = true; /* * (a^b^c)%mod * Using fermats Little theorem * x^(mod-1)=1(mod) * so b^c can be written as b^c=x*(mod-1)+y * then (a^(x*(mod-1)+y))%mod=(a^(x*(mod-1))*a^(y))mod * the term (a^(x*(mod-1)))%mod=a^(mod-1)*a^(mod-1) * */ // ---------------------------------------------------Segment_Tree----------------------------------------------------------------// // static class comparator implements Comparator<node> { // public int compare(node a, node b) { // return a.a - b.a > 0 ? 1 : -1; // } // } static class Segment_Tree { private long[] segment_tree; public Segment_Tree(int n) { this.segment_tree = new long[4 * n + 1]; } void build(int index, int left, int right, int[] a) { if (left == right) { segment_tree[index] = a[left]; return; } int mid = (left + right) / 2; build(2 * index + 1, left, mid, a); build(2 * index + 2, mid + 1, right, a); segment_tree[index] = segment_tree[2 * index + 1] + segment_tree[2 * index + 2]; } long query(int index, int left, int right, int l, int r) { if (left > right) return 0; if (left >= l && r >= right) { return segment_tree[index]; } if (l > right || left > r) return 0; int mid = (left + right) / 2; return query(2 * index + 1, left, mid, l, r) + query(2 * index + 2, mid + 1, right, l, r); } void update(int index, int left, int right, int node, int val) { if (left == right) { segment_tree[index] += val; return; } int mid = (left + right) / 2; if (node <= mid) update(2 * index + 1, left, mid, node, val); else update(2 * index + 2, mid + 1, right, node, val); segment_tree[index] = segment_tree[2 * index + 1] + segment_tree[2 * index + 2]; } } static class min_Segment_Tree { private long[] segment_tree; public min_Segment_Tree(int n) { this.segment_tree = new long[4 * n + 1]; } void build(int index, int left, int right, int[] a) { if (left == right) { segment_tree[index] = a[left]; return; } int mid = (left + right) / 2; build(2 * index + 1, left, mid, a); build(2 * index + 2, mid + 1, right, a); segment_tree[index] = Math.min(segment_tree[2 * index + 1], segment_tree[2 * index + 2]); } long query(int index, int left, int right, int l, int r) { if (left > right) return Integer.MAX_VALUE; if (left >= l && r >= right) { return segment_tree[index]; } if (l > right || left > r) return Integer.MAX_VALUE; int mid = (left + right) / 2; return Math.min(query(2 * index + 1, left, mid, l, r), query(2 * index + 2, mid + 1, right, l, r)); } } static class max_Segment_Tree { private long[] segment_tree; public max_Segment_Tree(int n) { this.segment_tree = new long[4 * n + 1]; } void build(int index, int left, int right, int[] a) { if (left == right) { segment_tree[index] = a[left]; return; } int mid = (left + right) / 2; build(2 * index + 1, left, mid, a); build(2 * index + 2, mid + 1, right, a); segment_tree[index] = Math.min(segment_tree[2 * index + 1], segment_tree[2 * index + 2]); } long query(int index, int left, int right, int l, int r) { if (left > right) return Integer.MIN_VALUE; if (left >= l && r >= right) { return segment_tree[index]; } if (l > right || left > r) return Integer.MIN_VALUE; int mid = (left + right) / 2; return Math.max(query(2 * index + 1, left, mid, l, r), query(2 * index + 2, mid + 1, right, l, r)); } } // ------------------------------------------------------ DSU // --------------------------------------------------------------------// static class dsu { private int[] parent; private int[] rank; private int[] size; public dsu(int n) { this.parent = new int[n + 1]; this.rank = new int[n + 1]; this.size = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; rank[i] = 1; size[i] = 1; } } int findParent(int a) { if (parent[a] == a) return a; else return parent[a] = findParent(parent[a]); } void join(int a, int b) { int parent_a = findParent(a); int parent_b = findParent(b); if (parent_a == parent_b) return; if (rank[parent_a] > rank[parent_b]) { parent[parent_b] = parent_a; size[parent_a] += size[parent_b]; } else if (rank[parent_a] < rank[parent_b]) { parent[parent_a] = parent_b; size[parent_b] += size[parent_a]; } else { parent[parent_a] = parent_b; size[parent_b] += size[parent_a]; rank[parent_b]++; } } } // ------------------------------------------------Comparable---------------------------------------------------------------------// static class pair implements Comparable<pair> { int a; int b; int dir; public pair(int a, int b, int dir) { this.a = a; this.b = b; this.dir = dir; } public int compareTo(pair p) { // if (this.b == Integer.MIN_VALUE || p.b == Integer.MIN_VALUE) // return (int) (this.index - p.index); return (int) (this.a - p.a); } } static class pair2 implements Comparable<pair2> { long a; int index; public pair2(long a, int index) { this.a = a; this.index = index; } public int compareTo(pair2 p) { return (int) (this.a - p.a); } } static class node implements Comparable<node>{ int l; int r; public node(int l, int r) { this.l = l; this.r = r; } public int compareTo(node a){ if(this.l==a.l)return this.r-a.r; return a.l-this.l; } } // static int ans = 0; static long ans = 0; static int leaf = 0; static boolean poss = true; static long mod = 1000000007L; static int[] dx = { 0, 0, -1, 1 }; static int[] dy = { 1, -1, 0, 0 }; static long[] sub = new long[300001]; static boolean cycle; static int count=0; public static void main(String[] args) throws Exception { // in = new FastReader(); // out = new PrintWriter(System.out); new Thread(null, new Main(), "Main", 1<<32).start(); // int tc = ni(); // while (tc-- > 0) { // int n=ni(); // int c=ni(); // int q=ni(); // String s=n(); // int[][] a=new int[c][2]; // int length=n; // for(int i=0;i<c;i++){ // a[i][0]=ni(); // a[i][1]=ni(); // length+=a[i][1]-a[i][0]+1; // } // char[] ans=new char[length]; // for(int i=0;i<n;i++){ // ans[i]=s.charAt(i); // } // int index=n; // for(int i=0;i<c;i++){ // for(int j=a[i][0]-1;j<=a[i][1]-1;j++){ // ans[index]=ans[j]; // index++; // } // } // for(int i=0;i<q;i++){ // int l=ni(); // pn(ans[l-1]); // } // pn(String.valueOf(ans)); // } // out.flush(); // out.close(); } public void run(){ try{ in = new FastReader(); out = new PrintWriter(System.out); int tc = ni(); while (tc-- > 0) { int n=ni(); int l=ni(); int r=ni(); boolean poss=true; for(int i=1;i<=n;i++){ if(((r/i)*i)<l)poss=false; } if(!poss){ pn("NO"); continue; } pn("YES"); for(int i=1;i<=n;i++){ p(((r/i)*i)+" "); } pn(""); } out.flush(); out.close(); }catch(Exception e){ } } static int binary_search(int[] a,int val){ int l=0; int r=a.length-1; int ans=0; while(l<=r){ int mid=l+(r-l)/2; if(a[mid]<=val){ ans=mid; l=mid+1; }else r=mid-1; } return ans; } static int[] longest_common_prefix(String s) { int m = s.length(); int[] lcs = new int[m]; int len = 0; int i = 1; lcs[0] = 0; while (i < m) { if (s.charAt(i) == s.charAt(len)) { lcs[i++] = ++len; } else { if (len == 0) { lcs[i] = 0; i++; } else len = lcs[len - 1]; } } return lcs; } static void swap(char[] a, char[] b, int i, int j) { char temp = a[i]; a[i] = b[j]; b[j] = temp; } static void factorial(long[] fact, long[] fact_inv, int n, long mod) { fact[0] = 1; for (int i = 1; i < n; i++) { fact[i] = (i * fact[i - 1]) % mod; } for (int i = 0; i < n; i++) { fact_inv[i] = power(fact[i], mod - 2, mod);// (1/x)%m can be calculated by fermat's little theoram which is // (x**(m-2))%m when m is prime } // (a^(b^c))%m is equal to, let res=(b^c)%(m-1) then (a^res)%m // https://www.geeksforgeeks.org/find-power-power-mod-prime/?ref=rp } static void find(int i, int n, int[] row, int[] col, int[] d1, int[] d2) { if (i >= n) { ans++; return; } for (int j = 0; j < n; j++) { if (col[j] == 0 && d1[i - j + n - 1] == 0 && d2[i + j] == 0) { col[j] = 1; d1[i - j + n - 1] = 1; d2[i + j] = 1; find(i + 1, n, row, col, d1, d2); col[j] = 0; d1[i - j + n - 1] = 0; d2[i + j] = 0; } } } static int answer(int l, int r, int[][] dp) { if (l > r) return 0; if (l == r) { dp[l][r] = 1; return 1; } if (dp[l][r] != -1) return dp[l][r]; int val = Integer.MIN_VALUE; int mid = l + (r - l) / 2; val = 1 + Math.max(answer(l, mid - 1, dp), answer(mid + 1, r, dp)); return dp[l][r] = val; } static TreeSet<Integer> ans(int n) { TreeSet<Integer> set = new TreeSet<>(); for (int i = 1; i * i <= n; i++) { if (n % i == 0) { set.add(i); set.add(n / i); } } set.remove(1); return set; } // static long find(String s, int i, int n, long[] dp) { // // pn(i); // if (i >= n) // return 1L; // if (s.charAt(i) == '0') // return 0; // if (i == n - 1) // return 1L; // if (dp[i] != -1) // return dp[i]; // if (s.substring(i, i + 2).equals("10") || s.substring(i, i + 2).equals("20")) // { // return dp[i] = (find(s, i + 2, n, dp)) % mod; // } // if ((s.charAt(i) == '1' || (s.charAt(i) == '2' && s.charAt(i + 1) - '0' <= // 6)) // && ((i + 2 < n ? (s.charAt(i + 2) != '0' ? true : false) : (i + 2 == n ? true // : false)))) { // return dp[i] = (find(s, i + 1, n, dp) + find(s, i + 2, n, dp)) % mod; // } else // return dp[i] = (find(s, i + 1, n, dp)) % mod; static void print(int[] a) { for (int i = 0; i < a.length; i++) p(a[i] + " "); pn(""); } static long count(long n) { long count = 0; while (n != 0) { count += n % 10; n /= 10; } return count; } static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static int LcsOfPrefix(String a, String b) { int i = 0; int j = 0; int count = 0; while (i < a.length() && j < b.length()) { if (a.charAt(i) == b.charAt(j)) { j++; count++; } i++; } return a.length() + b.length() - 2 * count; } static void reverse(int[] a, int n) { for (int i = 0; i < n / 2; i++) { int temp = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = temp; } } static char get_char(int a) { return (char) (a + 'a'); } static int find1(int[] a, int val) { int ans = -1; int l = 0; int r = a.length - 1; while (l <= r) { int mid = l + (r - l) / 2; if (a[mid] <= val) { l = mid + 1; ans = mid; } else r = mid - 1; } return ans; } static int find2(int[] a, int val) { int l = 0; int r = a.length - 1; int ans = -1; while (l <= r) { int mid = l + (r - l) / 2; if (a[mid] <= val) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } // static void dfs(List<List<Integer>> arr, int node, int parent, long[] val) { // p[node] = parent; // in_time[node] = count; // flat_tree[count] = val[node]; // subtree_gcd[node] = val[node]; // count++; // for (int adj : arr.get(node)) { // if (adj == parent) // continue; // dfs(arr, adj, node, val); // subtree_gcd[node] = gcd(subtree_gcd[adj], subtree_gcd[node]); // } // out_time[node] = count; // flat_tree[count] = val[node]; // count++; // } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
1d984f77d4f8e24397df2893d3b6eced
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Solution{ public static void main(String[] args) { TaskA solver = new TaskA(); // initFac(2*100001); int t = in.nextInt(); for (int i = 1; i <= t ; i++) { solver.solve(i, in, out); } // solver.solve(1, in, out); out.flush(); out.close(); } static ArrayList<Integer>[] graph ; static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n= in.nextInt(); int l=in.nextInt(); int r= in.nextInt(); int []ans=new int[n]; for(int i=1;i<=n;i++) { int x=ceil(l,i); int y=i*(x); if(y>r) { println("NO");return; } ans[i-1]=y; } println("YES"); println(ans);return; } } public void rotate(ArrayList<ArrayList<Integer>> a) { int n=a.size(); for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ int x=a.get(i).get(j); int y=a.get(j).get(i); a.get(j).set(i, x); a.get(i).set(j, y); } } for(int i=0;i<n;i++) { ArrayList<Integer>l=a.get(i); Collections.reverse(l); } } static long search (long[]len,long q) { long index=0; while(index<len.length&&len[(int)index]<q) { index++; } index--; return index; } static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return power(n, p - 2, p); } static long nCrModPFermat(long n, long r, long p) { if (n<r) return 0; if (r == 0) return 1; long[] fac = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[(int)n] * modInverse(fac[(int)r], p) % p * modInverse(fac[(int)(n - r)], p) % p) % p; } static int min(int x,int y) { return Math.min(x, y); } static int max(int x,int y) { return Math.max(x, y); } static long min(long x,long y) { return Math.min(x, y); } static long max(long x,long y) { return Math.max(x, y); } static int abs(int x,int y) { return Math.abs(x-y); } static long abs(long x,long y) { return Math.abs(x-y); } static void Eularianbfs(int v,int[]cur,int k,ArrayList<Integer>path) { while (cur[v] < k) { int u = cur[v]++; Eularianbfs(u,cur,k,path); path.add(u); } } static long fpow(long b, long x, long mod) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fpow(b * b % mod, x / 2, mod) % mod; return b * fpow(b * b % mod, x / 2, mod) % mod; } static long[] fac; static long mod = 1_000_000_007; static void initFac(long n) { fac = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) { fac[i] = (fac[i - 1] * i) % mod; } } static int count(char []arr,char x) { int c=0; for(int i=0;i<arr.length;i++) { if(arr[i]==x) { c++; } } return c; } static int count(int []arr,int x) { int c=0; for(int i=0;i<arr.length;i++) { if(arr[i]==x) { c++; } } return c; } static boolean[]seive(int n){ boolean[]b=new boolean[n+1]; for (int i = 2; i <= n; i++) b[i] = true; for(int i=2;i*i<=n;i++) { if(b[i]) { for(int j=i*i;j<=n;j+=i) { b[j]=false; } } } return b; } static int[] query(int l,int r) { System.out.println("? "+l+" "+r); System.out.print ("\n");System.out.flush(); int[]arr=new int[r-l+1]; for(int i=0;i<r-l+1;i++) { arr[i]=in.nextInt(); } return arr; } static long[]presum(long[]arr){ int n= arr.length; long[]pre=new long[n]; for(int i=0;i<n;i++) { if(i>0) { pre[i]=pre[i-1]; } pre[i]+=arr[i]; } return pre; } static int max(int[]arr) { int max=Integer.MIN_VALUE; for(int i=0;i<arr.length;i++) { max=Math.max(max, arr[i]); } return max; } static int min(int[]arr) { int min=Integer.MAX_VALUE; for(int i=0;i<arr.length;i++) { min=Math.min(min, arr[i]); } return min; } static int ceil(int a,int b) { int ans=a/b;if(a%b!=0) { ans++; } return ans; } static long sum(int[]arr) { long s=0; for(int x:arr) { s+=x; } return s; } static long sum(long[]arr) { long s=0; for(long x:arr) { s+=x; } return s; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void println(int[][]arr) { for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[0].length;j++) { print(arr[i][j]+" "); } print("\n"); } } static void println(long[][]arr) { for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[0].length;j++) { print(arr[i][j]+" "); } print("\n"); } } static void println(int[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static void println(long[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static void println(char x) { out.println(x); } static long[]input(long n){ long[]arr=new long[(int)n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } static int[]input(int n){ int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } static Character Char(int x) { return Character.toString((char)x).charAt(0); } static int[]input(){ int n= in.nextInt(); int[]arr=new int[(int)n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } //////////////////////////////////////////////////////// static class Pair { long first; long second;int third; Pair(long x, long y) { this.first = x; this.second = y; } // public int compareTo(Pair p) { // return Integer.compare(second, p.second); // } } // static void sortS(Pair arr[]) // { // Arrays.sort(arr, new Comparator<Pair>() { // @Override public int compare(Pair p1, Pair p2) // { // if(p1.second==p2.second) {return p1.first-p2.first;} // return (p1.second - p2.second); // // } // }); // } // static void sortF(Pair arr[]) // { // Arrays.sort(arr, new Comparator<Pair>() { // @Override public int compare(Pair p1, Pair p2) // { // if(p1.first==p2.first) {return p1.second-p2.second;} // return (p1.first - p2.first); // } // }); // } ///////////////////////////////////////////////////////////// static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); static void println(long c) { out.println(c); } static void print(long c) { out.print(c); } static void print(int c) { out.print(c); } static void println(int x) { out.println(x); } static void print(String s) { out.print(s); } static void println(String s) { out.println(s); } static void println(boolean b) { out.println(b); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
032abbec70b0643f9e6afedba03dd4fe
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import static java.lang.Math.max; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; public class B { /** * Template * * @author William Fiset, william.alexandre.fiset@gmail.com * */ static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static class InputReader { private static final int DEFAULT_BUFFER_SIZE = 1 << 16; private static final InputStream DEFAULT_STREAM = System.in; private static final int MAX_DECIMAL_PRECISION = 21; private int c; private byte[] buf; private int bufferSize, bufIndex, numBytesRead; private InputStream stream; private static final byte EOF = -1; private static final byte NEW_LINE = 10; private static final byte SPACE = 32; private static final byte DASH = 45; private static final byte DOT = 46; private char[] charBuffer; private static byte[] bytes = new byte[58]; private static int[] ints = new int[58]; private static char[] chars = new char[128]; static { char ch = ' '; int value = 0; byte _byte = 0; for (int i = 48; i < 58; i++) { bytes[i] = _byte++; } for (int i = 48; i < 58; i++) { ints[i] = value++; } for (int i = 32; i < 128; i++) { chars[i] = ch++; } } private static final double[][] doubles = { {0.0d, 0.00d, 0.000d, 0.0000d, 0.00000d, 0.000000d, 0.0000000d, 0.00000000d, 0.000000000d, 0.0000000000d, 0.00000000000d, 0.000000000000d, 0.0000000000000d, 0.00000000000000d, 0.000000000000000d, 0.0000000000000000d, 0.00000000000000000d, 0.000000000000000000d, 0.0000000000000000000d, 0.00000000000000000000d, 0.000000000000000000000d}, {0.1d, 0.01d, 0.001d, 0.0001d, 0.00001d, 0.000001d, 0.0000001d, 0.00000001d, 0.000000001d, 0.0000000001d, 0.00000000001d, 0.000000000001d, 0.0000000000001d, 0.00000000000001d, 0.000000000000001d, 0.0000000000000001d, 0.00000000000000001d, 0.000000000000000001d, 0.0000000000000000001d, 0.00000000000000000001d, 0.000000000000000000001d}, {0.2d, 0.02d, 0.002d, 0.0002d, 0.00002d, 0.000002d, 0.0000002d, 0.00000002d, 0.000000002d, 0.0000000002d, 0.00000000002d, 0.000000000002d, 0.0000000000002d, 0.00000000000002d, 0.000000000000002d, 0.0000000000000002d, 0.00000000000000002d, 0.000000000000000002d, 0.0000000000000000002d, 0.00000000000000000002d, 0.000000000000000000002d}, {0.3d, 0.03d, 0.003d, 0.0003d, 0.00003d, 0.000003d, 0.0000003d, 0.00000003d, 0.000000003d, 0.0000000003d, 0.00000000003d, 0.000000000003d, 0.0000000000003d, 0.00000000000003d, 0.000000000000003d, 0.0000000000000003d, 0.00000000000000003d, 0.000000000000000003d, 0.0000000000000000003d, 0.00000000000000000003d, 0.000000000000000000003d}, {0.4d, 0.04d, 0.004d, 0.0004d, 0.00004d, 0.000004d, 0.0000004d, 0.00000004d, 0.000000004d, 0.0000000004d, 0.00000000004d, 0.000000000004d, 0.0000000000004d, 0.00000000000004d, 0.000000000000004d, 0.0000000000000004d, 0.00000000000000004d, 0.000000000000000004d, 0.0000000000000000004d, 0.00000000000000000004d, 0.000000000000000000004d}, {0.5d, 0.05d, 0.005d, 0.0005d, 0.00005d, 0.000005d, 0.0000005d, 0.00000005d, 0.000000005d, 0.0000000005d, 0.00000000005d, 0.000000000005d, 0.0000000000005d, 0.00000000000005d, 0.000000000000005d, 0.0000000000000005d, 0.00000000000000005d, 0.000000000000000005d, 0.0000000000000000005d, 0.00000000000000000005d, 0.000000000000000000005d}, {0.6d, 0.06d, 0.006d, 0.0006d, 0.00006d, 0.000006d, 0.0000006d, 0.00000006d, 0.000000006d, 0.0000000006d, 0.00000000006d, 0.000000000006d, 0.0000000000006d, 0.00000000000006d, 0.000000000000006d, 0.0000000000000006d, 0.00000000000000006d, 0.000000000000000006d, 0.0000000000000000006d, 0.00000000000000000006d, 0.000000000000000000006d}, {0.7d, 0.07d, 0.007d, 0.0007d, 0.00007d, 0.000007d, 0.0000007d, 0.00000007d, 0.000000007d, 0.0000000007d, 0.00000000007d, 0.000000000007d, 0.0000000000007d, 0.00000000000007d, 0.000000000000007d, 0.0000000000000007d, 0.00000000000000007d, 0.000000000000000007d, 0.0000000000000000007d, 0.00000000000000000007d, 0.000000000000000000007d}, {0.8d, 0.08d, 0.008d, 0.0008d, 0.00008d, 0.000008d, 0.0000008d, 0.00000008d, 0.000000008d, 0.0000000008d, 0.00000000008d, 0.000000000008d, 0.0000000000008d, 0.00000000000008d, 0.000000000000008d, 0.0000000000000008d, 0.00000000000000008d, 0.000000000000000008d, 0.0000000000000000008d, 0.00000000000000000008d, 0.000000000000000000008d}, {0.9d, 0.09d, 0.009d, 0.0009d, 0.00009d, 0.000009d, 0.0000009d, 0.00000009d, 0.000000009d, 0.0000000009d, 0.00000000009d, 0.000000000009d, 0.0000000000009d, 0.00000000000009d, 0.000000000000009d, 0.0000000000000009d, 0.00000000000000009d, 0.000000000000000009d, 0.0000000000000000009d, 0.00000000000000000009d, 0.000000000000000000009d} }; public InputReader() { this(DEFAULT_STREAM, DEFAULT_BUFFER_SIZE); } public InputReader(int bufferSize) { this(DEFAULT_STREAM, bufferSize); } public InputReader(InputStream stream) { this(stream, DEFAULT_BUFFER_SIZE); } public InputReader(InputStream stream, int bufferSize) { if (stream == null || bufferSize <= 0) { throw new IllegalArgumentException(); } buf = new byte[bufferSize]; charBuffer = new char[128]; this.bufferSize = bufferSize; this.stream = stream; } private byte read() throws IOException { if (numBytesRead == EOF) { throw new IOException(); } if (bufIndex >= numBytesRead) { bufIndex = 0; numBytesRead = stream.read(buf); if (numBytesRead == EOF) { return EOF; } } return buf[bufIndex++]; } private void doubleCharBufferSize() { char[] newBuffer = new char[charBuffer.length << 1]; for (int i = 0; i < charBuffer.length; i++) { newBuffer[i] = charBuffer[i]; } charBuffer = newBuffer; } private int readJunk(int token) throws IOException { if (numBytesRead == EOF) { return EOF; } do { while (bufIndex < numBytesRead) { if (buf[bufIndex] > token) { return 0; } bufIndex++; } numBytesRead = stream.read(buf); if (numBytesRead == EOF) { return EOF; } bufIndex = 0; } while (true); } public byte nextByte() throws IOException { return (byte) nextInt(); } public int nextInt() throws IOException { if (readJunk(DASH - 1) == EOF) { throw new IOException(); } int sgn = 1, res = 0; c = buf[bufIndex]; if (c == DASH) { sgn = -1; bufIndex++; } do { while (bufIndex < numBytesRead) { if (buf[bufIndex] > SPACE) { res = (res << 3) + (res << 1); res += ints[buf[bufIndex++]]; } else { bufIndex++; return res * sgn; } } numBytesRead = stream.read(buf); if (numBytesRead == EOF) { return res * sgn; } bufIndex = 0; } while (true); } public int[] nextIntArray(int n) throws IOException { int[] ar = new int[n]; for (int i = 0; i < n; i++) { ar[i] = nextInt(); } return ar; } public long[] nextLongArray(int n) throws IOException { long[] ar = new long[n]; for (int i = 0; i < n; i++) { ar[i] = nextLong(); } return ar; } public void close() throws IOException { stream.close(); } public long nextLong() throws IOException { if (readJunk(DASH - 1) == EOF) { throw new IOException(); } int sgn = 1; long res = 0L; c = buf[bufIndex]; if (c == DASH) { sgn = -1; bufIndex++; } do { while (bufIndex < numBytesRead) { if (buf[bufIndex] > SPACE) { res = (res << 3) + (res << 1); res += ints[buf[bufIndex++]]; } else { bufIndex++; return res * sgn; } } numBytesRead = stream.read(buf); if (numBytesRead == EOF) { return res * sgn; } bufIndex = 0; } while (true); } public String nextString() throws IOException { if (numBytesRead == EOF) { return null; } if (readJunk(SPACE) == EOF) { return null; } for (int i = 0;;) { while (bufIndex < numBytesRead) { if (buf[bufIndex] > SPACE) { if (i == charBuffer.length) { doubleCharBufferSize(); } charBuffer[i++] = (char) buf[bufIndex++]; } else { bufIndex++; return new String(charBuffer, 0, i); } } // Reload buffer numBytesRead = stream.read(buf); if (numBytesRead == EOF) { return new String(charBuffer, 0, i); } bufIndex = 0; } } } // public static void main(String args[]) throws Exception { int t = in.nextInt(); while (t-- != 0) { solve(); } out.print(sb.toString()); out.close(); } static void solve() throws IOException, Exception { int n = in.nextInt(); int l = in.nextInt(); int r = in.nextInt(); int[] ans = new int[n]; boolean possible = true; for (int i = 1; i <= n; i++) { int x = l % i == 0 ? l / i : l / i + 1; // if (x % i == 0) { // x++; // } if (x * i > r) { possible = false; break; } ans[i-1] = x * i; } if (possible) { sb.append("YES").append("\n"); for (int i : ans) { sb.append(i + " "); } sb.append("\n"); } else { sb.append("NO").append("\n"); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
35935dd2084b1ffb5c2eeeab0f4cb128
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class JaiShreeRam{ static Scanner in=new Scanner(); static long systemTime; static long mod = 1000000007; //static ArrayList<ArrayList<Integer>> adj; static int seive[]=new int[1000001]; static long C[][]; static int fen[]=new int[4*100005]; static long nt=0; static ArrayList<Integer> ans=new ArrayList<>(); public static void main(String[] args) throws Exception{ int z=in.readInt(); for(int test=1;test<=z;test++) { //setTime(); solve(); //printTime(); //printMemory(); } } static void solve() { int n=in.readInt(); long l=in.readLong(); long r=in.readLong(); long gcd=1; long a[]=new long[n]; for(int i=0;i<n;i++) { gcd=i+1; long tmp=(l+gcd-1)/gcd; if(tmp*gcd>r) { no(); return; } a[i]=tmp*gcd; } yes(); print(a); } static long fn(int i,int j,int a[],long b,long c,long dp[]) { if(j==a.length) { return 0; } long min=Long.MAX_VALUE; if(i<j) { min=Math.min(min,fn(j,j+1,a,b,c,dp)+Math.abs(a[j]-a[i])*b+Math.abs(a[j]-a[i])*c); } min=Math.min(min,fn(i,j+1,a,b,c,dp)+Math.abs(a[j]-a[i])*c); //print(min); return min; } static long pow(long n, long m) { if(m==0) return 1; else if(m==1) return n; else { long r=pow(n,m/2); if(m%2==0) return (r*r); else return (r*r*n); } } static long maxsumsub(ArrayList<Long> al) { long max=0; long sum=0; for(int i=0;i<al.size();i++) { sum+=al.get(i); if(sum<0) { sum=0; } max=Math.max(max,sum); } return max; } static long abs(long a) { return Math.abs(a); } static void ncr(int n, int k){ C= new long[n + 1][k + 1]; int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= Math.min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } } static boolean isPalin(String s) { int i=0,j=s.length()-1; while(i<=j) { if(s.charAt(i)!=s.charAt(j)) { return false; } i++; j--; } return true; } static int knapsack(int W, int wt[],int val[], int n){ int []dp = new int[W + 1]; for (int i = 1; i < n + 1; i++) { for (int w = W; w >= 0; w--) { if (wt[i - 1] <= w) { dp[w] = Math.max(dp[w],dp[w - wt[i - 1]] + val[i - 1]); } } } return dp[W]; } static void seive() { Arrays.fill(seive, 1); seive[0]=0; seive[1]=0; for(int i=2;i*i<1000001;i++) { if(seive[i]==1) { for(int j=i*i;j<1000001;j+=i) { if(seive[j]==1) { seive[j]=0; } } } } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static int[] nia(int n){ int[] arr= new int[n]; int i=0; while(i<n){ arr[i++]=in.readInt(); } return arr; } static long[] nla(int n){ long[] arr= new long[n]; int i=0; while(i<n){ arr[i++]=in.readLong(); } return arr; } static long[] nla1(int n){ long[] arr= new long[n+1]; int i=1; while(i<=n){ arr[i++]=in.readLong(); } return arr; } static int[] nia1(int n){ int[] arr= new int[n+1]; int i=1; while(i<=n){ arr[i++]=in.readInt(); } return arr; } static Integer[] nIa(int n){ Integer[] arr= new Integer[n]; int i=0; while(i<n){ arr[i++]=in.readInt(); } return arr; } static Long[] nLa(int n){ Long[] arr= new Long[n]; int i=0; while(i<n){ arr[i++]=in.readLong(); } return arr; } static long gcd(long a, long b) { if (b==0) return a; return gcd(b, a%b); } static void no() { print("NO"); } static void yes() { print("YES"); } static void print(long i) { System.out.println(i); } static void print(Object o) { System.out.println(o); } static void print(int a[]) { for(int i:a) { System.out.print(i+" "); } System.out.println(); } static void print(long a[]) { for(long i:a) { System.out.print(i+" "); } System.out.println(); } static void print(ArrayList<Long> a) { for(long i:a) { System.out.print(i+" "); } System.out.println(); } static void print(Object a[]) { for(Object i:a) { System.out.print(i+" "); } System.out.println(); } static void setTime() { systemTime = System.currentTimeMillis(); } static void printTime() { System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime)); } static void printMemory() { System.err.println("Memory consumed: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + "kb"); } static class Scanner{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String readString() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } double readDouble() { return Double.parseDouble(readString()); } int readInt() { return Integer.parseInt(readString()); } long readLong() { return Long.parseLong(readString()); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
9ff323ea25b9f8b5634e0d7124bc0975
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.io.*; public class tr0 { static PrintWriter out; static StringBuilder sb; static int mod = (int) 1e9 + 7; static int inf = (int) 1e9; static int n, m; static long k; static ArrayList<int[]>[] ad; static int[][] memo; static long[] inv, f, ncr[]; static HashMap<Integer, Integer> hm; static int[] pre, suf, Smax[], Smin[]; static int idmax, idmin; static ArrayList<Integer> av; static HashMap<Integer, Integer> mm; static int[] vis; static int[] lazy[], lazyCount; static double[] get; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int l = sc.nextInt(); int r = sc.nextInt(); boolean f = true; int[] a = new int[n]; for (int i = 1; i <= n; i++) { int ai = i; int x = l / i; if (l % i == 0) ai = l; else { ai = (x + 1) * i; } if (ai > r) { f = false; break; } a[i - 1] = ai; } if (f) { out.println("YES"); for (int y : a) out.print(y + " "); out.println(); } else out.println("NO"); } out.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(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 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 int[] nextArrInt(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextArrLong(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextArrIntSorted(int n) throws IOException { int[] a = new int[n]; Integer[] a1 = new Integer[n]; for (int i = 0; i < n; i++) a1[i] = nextInt(); Arrays.sort(a1); for (int i = 0; i < n; i++) a[i] = a1[i].intValue(); return a; } public long[] nextArrLongSorted(int n) throws IOException { long[] a = new long[n]; Long[] a1 = new Long[n]; for (int i = 0; i < n; i++) a1[i] = nextLong(); Arrays.sort(a1); for (int i = 0; i < n; i++) a[i] = a1[i].longValue(); return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
71dc592b7c733df02650bc253def2924
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); int l = sc.nextInt(); int r = sc.nextInt(); ArrayList<Integer> list = new ArrayList<>(); boolean ok = true; for(int i = 1; i <= n; i++){ if(l % i == 0) { list.add(l); continue; } int x = l / i; x++; int val = x * i; if(val > r) { ok = false; break; } list.add(val); } if(!ok) System.out.println("NO"); else { System.out.println("YES"); for(int i : list) System.out.print(i + " "); System.out.println(); } } } public static long fastPow(long x, int y) { long result = 1; while (y > 0) { if ((y & 1) == 0) { x *= x; y >>>= 1; } else { result *= x; y--; } } return result; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
cfe859d58e0416cd1eb4d25ce40bca81
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; public class Main { private static FastReader sc = new FastReader(System.in); public static void main(String[] args) { int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int l = sc.nextInt(); int r = sc.nextInt(); boolean exists = true; int[] ans = new int[n]; for (int j = 1; j <= n; j++) { double min = Math.ceil((1.0 * l) / j) * j; double max = Math.floor((1.0 * r) / j) * j; if (min > r && max < l) { exists = false; break; } ans[j - 1] = min < r ? (int) min : (int) max; } if (!exists) { System.out.println("NO"); } else { System.out.println("YES"); for (int k : ans) { System.out.print(k + " "); } System.out.println(); } } } } class FastReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastReader(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 peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } 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 == ',') { c = read(); } 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 String nextString() { 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 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 nextLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String nextLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return nextLine(); } else { return readLine0(); } } public BigInteger nextBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } 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 boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
b740b538ead70842899e267f39f28d75
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; public class _1708B { private static final int START_TEST_CASE = 1; public static void solveCase(FastIO io, int testCase) { int n = io.nextInt(); int l = io.nextInt(); int r = io.nextInt(); int[] ans = new int[n]; for (int i = n; i >= 1; i--) { int num = (l / i * i); if (l % i != 0) { num += i; } if (num > r) { io.println("NO"); return; } ans[i-1] = num; } io.println("YES"); io.printlnArray(ans); } public static void solve(FastIO io) { final int T = io.nextInt(); for (int t = 0; t < T; ++t) { solveCase(io, START_TEST_CASE + t); } } public static class FastIO { private InputStream reader; private PrintWriter writer; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastIO(InputStream r, OutputStream w) { reader = r; writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w))); } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = reader.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { 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 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 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; } // TODO: read this byte-by-byte like the other read functions. public double nextDouble() { return Double.parseDouble(nextString()); } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } 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 printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printArray(long[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printlnArray(int[] arr) { printArray(arr); writer.println(); } public void printlnArray(long[] arr) { printArray(arr); writer.println(); } public void printf(String format, Object... args) { print(String.format(format, args)); } public void flush() { writer.flush(); } } public static void main(String[] args) { FastIO io = new FastIO(System.in, System.out); solve(io); io.flush(); } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
2eeac5c7169d4406f7ae8947eba75a2e
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n,l,r,t,m; int [] a = new int[100010]; t = cin.nextInt(); while(t-->0) { n=cin.nextInt(); l=cin.nextInt(); r=cin.nextInt(); m=0; boolean flag = false; for(int i=1;i<=n;i++) { int k = l%i; if(k==0)a[++m] = l; else { if(l + i- k <= r)a[++m] = l+i-k; else { flag = true; break; } } } if(flag)System.out.println("NO"); else { System.out.println("YES"); for(int i=1;i<=m;i++) { System.out.print(a[i]+" "); } System.out.println(); } } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
5a97fa424ddbc8ed3835d83ceafc4f74
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.math.*; import java.util.* ; import java.io.* ; @SuppressWarnings("unused") //Scanner s = new Scanner(new File("input.txt")); //s.close(); //PrintWriter writer = new PrintWriter("output.txt"); //writer.close(); public class cf { static long gcd(long a, long b){if (b == 0) {return a;}return gcd(b, a % b);} public static void main(String[] args)throws Exception { FastReader in = new FastReader() ; // FastIO in = new FastIO(System.in) ; StringBuilder op = new StringBuilder() ; int T = in.nextInt() ; // int T=1 ; for(int tt=0 ; tt<T ; tt++){ //CODE : int n = in.nextInt() ; int l = in.nextInt() ; int r = in.nextInt() ; int a[] = new int[n] ; int pos=1 ; for(int i=1 ; i<=n ; i++) { int mul = (l/i)*i ; if(mul<l)mul+=i ; if(mul > r) { pos=0; break ; } a[i-1]=mul ; } if(pos==0) { op.append("NO\n") ; continue ; } op.append("YES\n") ; for(int el : a)op.append(el+" "); op.append("\n") ; } System.out.println(op.toString()) ; } static class pair implements Comparable<pair> { int first, second; pair(int first, int second) { this.first = first; this.second = second; } @Override public int compareTo(pair other) { return this.first - other.first; } @Override public boolean equals(Object obj) { pair other = (pair)obj ; return this.first == other.first && this.second == other.second ; } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastIO { InputStream dis; byte[] buffer = new byte[1 << 17]; int pointer = 0; public FastIO(String fileName) throws Exception { dis = new FileInputStream(fileName); } public FastIO(InputStream is) throws Exception { dis = is; } int nextInt() throws Exception { int ret = 0; byte b; do { b = nextByte(); } while (b <= ' '); boolean negative = false; if (b == '-') { negative = true; b = nextByte(); } while (b >= '0' && b <= '9') { ret = 10 * ret + b - '0'; b = nextByte(); } return (negative) ? -ret : ret; } long nextLong() throws Exception { long ret = 0; byte b; do { b = nextByte(); } while (b <= ' '); boolean negative = false; if (b == '-') { negative = true; b = nextByte(); } while (b >= '0' && b <= '9') { ret = 10 * ret + b - '0'; b = nextByte(); } return (negative) ? -ret : ret; } byte nextByte() throws Exception { if (pointer == buffer.length) { dis.read(buffer, 0, buffer.length); pointer = 0; } return buffer[pointer++]; } String next() throws Exception { StringBuffer ret = new StringBuffer(); byte b; do { b = nextByte(); } while (b <= ' '); while (b > ' ') { ret.appendCodePoint(b); b = nextByte(); } return ret.toString(); } int[] readArray(int n) throws Exception { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); }; String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
7c7c3caff817e3e659a80d46114b6884
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { FastScanner input = new FastScanner(); int tc = input.nextInt(); work: while (tc-- > 0) { int n = input.nextInt(); int l = input.nextInt(); int r= input.nextInt(); int ans[] = new int[n+1]; for (int i = 1; i <=n; i++) { int now= (l%i); if(now>0) { now = i-now; } ans[i] = l+now; if(ans[i]>r) { System.out.println("NO"); continue work; } } StringBuilder result = new StringBuilder();; result.append("YES\n"); for (int i=1;i<=n;i++) { result.append(ans[i]+" "); } System.out.println(result); } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { 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() throws IOException { return br.readLine(); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
b8af4c3765045b2c6cf24257d4115e61
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; public class a { public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); int l = fs.nextInt(); int r = fs.nextInt(); int[] a = new int[n]; boolean ok = true; for (int i = 1; i <= n; ++i) { a[i-1] = r - r%i; if (a[i-1] > r || a[i-1] < l) { ok = false; break; } } out.println(ok ? "YES" : "NO"); if (ok) { for (int i = 1; i <= n; ++i) { out.print(a[i-1] + " "); } out.println(); } } out.close(); } static int lowerBound(List<Integer> a, int l, int r, int target) { while (l < r) { int mid = l + (r - l) / 2; if (target > a.get(mid)) { l = mid + 1; } else { r = mid; } } return l; } static int upperBound(List<Integer> a, int l, int r, int target) { while (l < r) { int mid = l + (r - l) / 2; if (a.get(mid) > target) { r = mid; } else { l = mid + 1; } } return l; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
ed2d146bd0644ab7a5bed4ff6c7c57ab
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t-->0){ int n = scan.nextInt(); int l = scan.nextInt(); int r = scan.nextInt(); boolean flag = true; int[] arr = new int[n+1]; for(int i=1; i<=n; i++){ arr[i] = ((l-1)/i+1)*i; if(arr[i]>r){ flag = false; break; } } if(flag){ System.out.println("yes"); for(int i=1; i<=n; i++) System.out.print(arr[i]+" "); }else System.out.print("no"); System.out.println(); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
90505052e5be862531a388494d088d3c
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; public final class Main { //int 2e9 - long 9e18 static PrintWriter out = new PrintWriter(System.out); static FastReader in = new FastReader(); static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)}; static Pair[] movesDiagonal = new Pair[]{new Pair(-1, -1), new Pair(-1, 1), new Pair(1, -1), new Pair(1, 1)}; static int mod = (int) (1e9 + 7); static int mod2 = 998244353; public static void main(String[] args) { int tt = i(); while (tt-- > 0) { solve(); } out.flush(); } public static void solve() { int n = i(); int l = i(); int r = i(); int[] ans = new int[n]; for (int i = 1; i <= n; i++) { int m = l / i * i; if (m == l) { ans[i-1] = m; } else { m += i; if (m<=r){ ans[i-1] = m; }else{ out.println("NO");return; } } } out.println("YES"); print(ans); } // (10,5) = 2 ,(11,5) = 3 static long upperDiv(long a, long b) { return (a / b) + ((a % b == 0) ? 0 : 1); } static long sum(int[] a) { long sum = 0; for (int x : a) { sum += x; } return sum; } static int[] preint(int[] a) { int[] pre = new int[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } static long[] pre(int[] a) { long[] pre = new long[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } static long[] post(int[] a) { long[] post = new long[a.length + 1]; post[0] = 0; for (int i = 0; i < a.length; i++) { post[i + 1] = post[i] + a[a.length - 1 - i]; } return post; } static long[] pre(long[] a) { long[] pre = new long[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } static void print(char A[]) { for (char c : A) { out.print(c); } out.println(); } static void print(boolean A[]) { for (boolean c : A) { out.print(c + " "); } out.println(); } static void print(int A[]) { for (int c : A) { out.print(c + " "); } out.println(); } static void print(long A[]) { for (long i : A) { out.print(i + " "); } out.println(); } static void print(List<Integer> A) { for (int a : A) { out.print(a + " "); } } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static double d() { return in.nextDouble(); } static String s() { return in.nextLine(); } static String c() { return in.next(); } static int[][] inputWithIdx(int N) { int A[][] = new int[N][2]; for (int i = 0; i < N; i++) { A[i] = new int[]{i, in.nextInt()}; } return A; } static int[] input(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] inputLong(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) { A[i] = in.nextLong(); } return A; } static int GCD(int a, int b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } static long GCD(long a, long b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } static long LCM(int a, int b) { return (long) a / GCD(a, b) * b; } static long LCM(long a, long b) { return a / GCD(a, b) * b; } // find highest i which satisfy a[i]<=x static int lowerbound(List<Long> a, long x) { int l = 0; int r = a.size() - 1; while (l < r) { int m = (l + r + 1) / 2; if (a.get(m) <= x) { l = m; } else { r = m - 1; } } return l; } static void shuffle(int[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } } static void shuffleAndSort(int[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int[] temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr, comparator); } static void shuffleAndSort(long[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); long temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static boolean isPerfectSquare(double number) { double sqrt = Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static void swap(int A[], int a, int b) { int t = A[a]; A[a] = A[b]; A[b] = t; } static void swap(char A[], int a, int b) { char t = A[a]; A[a] = A[b]; A[b] = t; } static long pow(long a, long b, int mod) { long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) { pow = (pow * x) % mod; } x = (x * x) % mod; b /= 2; } return pow; } static long pow(long a, long b) { long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) { pow *= x; } x = x * x; b /= 2; } return pow; } static long modInverse(long x, int mod) { return pow(x, mod - 2, mod); } static boolean isPrime(long N) { if (N <= 1) { return false; } if (N <= 3) { return true; } if (N % 2 == 0 || N % 3 == 0) { return false; } for (int i = 5; i * i <= N; i = i + 6) { if (N % i == 0 || N % (i + 2) == 0) { return false; } } return true; } public static String reverse(String str) { if (str == null) { return null; } return new StringBuilder(str).reverse().toString(); } public static void reverse(int[] arr) { int l = 0; int r = arr.length - 1; while (l < r) { swap(arr, l, r); l++; r--; } } public static String repeat(char ch, int repeat) { if (repeat <= 0) { return ""; } final char[] buf = new char[repeat]; for (int i = repeat - 1; i >= 0; i--) { buf[i] = ch; } return new String(buf); } public static int[] manacher(String s) { char[] chars = s.toCharArray(); int n = s.length(); int[] d1 = new int[n]; for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1); while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) { k++; } d1[i] = k--; if (i + k > r) { l = i - k; r = i + k; } } return d1; } public static int[] kmp(String s) { int n = s.length(); int[] res = new int[n]; for (int i = 1; i < n; ++i) { int j = res[i - 1]; while (j > 0 && s.charAt(i) != s.charAt(j)) { j = res[j - 1]; } if (s.charAt(i) == s.charAt(j)) { ++j; } res[i] = j; } return res; } } class Pair { int i; int j; Pair(int i, int j) { this.i = i; this.j = j; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Pair pair = (Pair) o; return i == pair.i && j == pair.j; } @Override public int hashCode() { return Objects.hash(i, j); } } class ThreePair { int i; int j; int k; ThreePair(int i, int j, int k) { this.i = i; this.j = j; this.k = k; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ThreePair pair = (ThreePair) o; return i == pair.i && j == pair.j && k == pair.k; } @Override public int hashCode() { return Objects.hash(i, j); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Node { int val; public Node(int val) { this.val = val; } } class ST { int n; Node[] st; ST(int n) { this.n = n; st = new Node[4 * Integer.highestOneBit(n)]; } void build(Node[] nodes) { build(0, 0, n - 1, nodes); } private void build(int id, int l, int r, Node[] nodes) { if (l == r) { st[id] = nodes[l]; return; } int mid = (l + r) >> 1; build((id << 1) + 1, l, mid, nodes); build((id << 1) + 2, mid + 1, r, nodes); st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]); } void update(int i, Node node) { update(0, 0, n - 1, i, node); } private void update(int id, int l, int r, int i, Node node) { if (i < l || r < i) { return; } if (l == r) { st[id] = node; return; } int mid = (l + r) >> 1; update((id << 1) + 1, l, mid, i, node); update((id << 1) + 2, mid + 1, r, i, node); st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]); } Node get(int x, int y) { return get(0, 0, n - 1, x, y); } private Node get(int id, int l, int r, int x, int y) { if (x > r || y < l) { return new Node(0); } if (x <= l && r <= y) { return st[id]; } int mid = (l + r) >> 1; return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y)); } Node comb(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } return new Node(GCD(a.val, b.val)); } static int GCD(int a, int b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
ea67c904d0487c4560ab80046c6ce858
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
// package faltu; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { // ***********************MATHS--STARTS************************************************* // private static ArrayList<Long> get_divisor(long x) { ArrayList<Long>a=new ArrayList<Long>(); for(long i=1;i*i<=x;i++) { if(x%i==0) { a.add((long) i); if(x/i!=i)a.add(x/i); } } return a; } static long[] sieve; static long[] smallestPrime; public static void sieve() { int n=4000000+1; sieve=new long[n]; smallestPrime=new long[n]; sieve[0]=1; sieve[1]=1; for(int i=2;i<n;i++){ sieve[i]=i; smallestPrime[i]=i; } for(int i=2;i*i<n;i++){ if(sieve[i]==i){ for(int j=i*i;j<n;j+=i){ if(sieve[j]==j)sieve[j]=1; if(smallestPrime[j]==j||smallestPrime[j]>i)smallestPrime[j]=i; } } } } static long nCr(long n,long r,long MOD) { if(n<r)return 0; if(r==0)return 1; return fact[(int) n]*mod_inv(fact[(int) r],MOD)%MOD*mod_inv(fact[(int) (n-r)],MOD)%MOD; } static long[]fact; static void computeFact(long n,long MOD) { fact=new long[(int)n+1]; fact[0]=1; for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i%MOD)%MOD; } static long bin_expo(long a,long b,long MOD) { if(b == 0)return 1; long ans = bin_expo(a,b/2,MOD); ans = (ans*ans)%MOD; if(b % 2!=0){ ans = (ans*a)%MOD; } return ans%MOD; } static long mod_add(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} static long mod_mul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} static long mod_sub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} static long mod_inv(long n,long p) {return bin_expo(n,p-2,p);} static long gcd(long a, long b){if (a == 0) {return b;}return gcd(b % a, a); } static int gcd(int a, int b){if (a == 0) {return b; }return gcd(b % a, a); } static long lcm(long a,long b){return (a / gcd(a, b)) * b;} static long min(long x,long y) {return Math.min(x, y);}static long max(long x,long y) {return Math.max(x, y);} static int min(int x,int y) {return Math.min(x, y);}static int max(int x,int y) {return Math.max(x, y);} static ArrayList<String>powof2s; static void powof2S() { long i=1; while(i<(long)2e18) { powof2s.add(String.valueOf(i)); i*=2; } } static long power(long a, long b){ a %=MOD;long out = 1; while (b > 0) { if((b&1)!=0)out = out * a % MOD; a = a * a % MOD; b >>= 1; a*=a; } return out; } static boolean coprime(int a, long l){return (gcd(a, l) == 1);} // ****************************MATHS-ENDS***************************************************** // ***********************BINARY-SEARCH STARTS*********************************************** public static int upperBound(long[] arr, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<=m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(long[] a, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(a[mid]<m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(ArrayList<Integer> ar,int k){ int s=0,e=ar.size(); while (s!=e){ int mid = s+e>>1; if (ar.get(mid) <k)s=mid+1; else e=mid; } if(s==ar.size())return -1; return s; } public static int upperBound(ArrayList<Integer> ar,int k){ int s=0,e=ar.size(); while (s!=e){ int mid = s+e>>1; if (ar.get(mid) <=k)s=mid+1; else e=mid; } if(s==ar.size())return -1; return s; } public static long getClosest(long val1, long val2,long target){if (target - val1 >= val2 - target)return val2; else return val1;} static void ruffleSort(long[] a) { int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { long oi=r.nextInt(n), temp=a[i]; a[i]=a[(int)oi]; a[(int)oi]=temp; } Arrays.sort(a); } static void ruffleSort(int[] a){ int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } int ceilIndex(int input[], int T[], int end, int s){ int start = 0; int middle; int len = end; while(start <= end){ middle = (start + end)/2; if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){ return middle+1; }else if(input[T[middle]] < s){ start = middle+1; }else{ end = middle-1; } } return -1; } static int lowerLimitBinarySearch(ArrayList<Long> v,long k) { int n =v.size(); int first = 0,second = n; while(first <second) { int mid = first + (second-first)/2; if(v.get(mid) > k) { second = mid; }else { first = mid+1; } } if(first < n && v.get(first) < k) { first++; } return first; //1 index } public static int searchindex(long arr[], long t){int index = Arrays.binarySearch(arr, t);return (index < 0) ? -1 : index;} public static long[] sort(long[] a) {ArrayList<Long> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;} public static int[] sort(int[] a) {ArrayList<Integer> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;} // *******************************BINARY-SEARCH ENDS*********************************************** // *********************************GRAPHS-STARTS**************************************************** // *******----SEGMENT TREE IMPLEMENT---***** // -------------START--------------- void buildTree (int[] arr,int[] tree,int start,int end,int treeNode){ if(start==end){ tree[treeNode]=arr[start]; return; } buildTree(arr,tree,start,end,2*treeNode); buildTree(arr,tree,start,end,2*treeNode+1); tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1]; } void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value){ if(start==end){ arr[idx]=value; tree[treeNode]=value; return; } int mid=(start+end)/2; if(idx>mid)updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value); else updateTree(arr,tree,start,mid,2*treeNode,idx,value); tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1]; } long query(int[]arr,int[]tree,int start,int end,int treeNode,int qleft,int qright) { if(start>=qleft&&end<=qright)return tree[treeNode]; if(start>qright||end<qleft)return 0; int mid=(start+end)/2; long valLeft=query(arr,tree,start,mid-1,treeNode*2,qleft,qright); long valRight=query(arr,tree,mid+1,end,treeNode*2+1,qleft,qright); return valLeft+valRight; } // -------------ENDS--------------- //***********************DSU IMPLEMENT START************************* static int parent[]; static int rank[]; static int[]Size; static void makeSet(int n){ parent=new int[n]; rank=new int[n]; Size=new int[n]; for(int i=0;i<n;i++){ parent[i]=i; rank[i]=0; Size[i]=1; } } static void union(int u,int v){ u=findpar(u); v=findpar(v); if(rank[u]<rank[v]) { parent[u]=v; Size[v]+=Size[u]; } else if(rank[v]<rank[u]) { parent[v]=u; Size[u]+=Size[v]; } else{ parent[v]=u; rank[u]++; Size[u]+=Size[v]; } } private static int findpar(int node){ if(node==parent[node])return node; return parent[node]=findpar(parent[node]); } // *********************DSU IMPLEMENT ENDS************************* // ****__________PRIMS ALGO______________________**** private static int prim(ArrayList<node>[] adj,int N,int node) { int key[] = new int[N+1]; int parent[] = new int[N+1]; boolean mstSet[] = new boolean[N+1]; for(int i = 0;i<N;i++) { key[i] = 100000000; mstSet[i] = false; } PriorityQueue<node> pq = new PriorityQueue<node>(N, new node()); key[node] = 0; parent[node] = -1; pq.add(new node( node,key[node])); for(int i = 0;i<N-1;i++) { int u = pq.poll().getV(); mstSet[u] = true; for(node it: adj[u]) { if(mstSet[it.getV()] == false && it.getW() < key[it.getV()]) { parent[it.getV()] = u; key[it.getV()] = (int) it.getW(); pq.add(new node(it.getV(), key[it.getV()])); } } } int sum=0; for(int i=1;i<N;i++) { System.out.println(key[i]); sum+=key[i]; } System.out.println(sum); return sum; } // ****____________DIJKSTRAS ALGO___________**** static int[]dist; static int dijkstra(int u,int n,ArrayList<node>adj[]) { dist=new int[n]; Arrays.fill(dist,Integer.MAX_VALUE); dist[u]=0; PriorityQueue<node>pq=new PriorityQueue<node>(new node()); pq.add(new node(u,0)); while(!pq.isEmpty()) { node v=pq.poll(); for(node it:adj[v.getV()]) { if(dist[it.getV()]>it.getW()+dist[v.getV()]) { dist[it.getV()]=(int) (it.getW()+dist[v.getV()]); pq.add(new node(it.getV(),dist[it.getV()])); } } } int sum=0; for(int i=1;i<n;i++){ System.out.println(dist[i]); sum+=dist[i]; } return sum; } private static void setGraph(int n,int m){ vis=new boolean[n+1]; indeg=new int[n+1]; // adj=new ArrayList<ArrayList<Integer>>(); // for(int i=0;i<=n;i++)adj.add(new ArrayList<>()); // for(int i=0;i<m;i++){ // int u=s.nextInt(),v=s.nextInt(); // adj.get(u).add(v); // adj.get(v).add(u); // } adj=new ArrayList[n+1]; // backadj=new ArrayList[n+1]; for(int i=0;i<=n;i++){ adj[i]=new ArrayList<Integer>(); // backadj[i]=new ArrayList<Integer>(); } for(int i=0;i<m;i++){ int u=s.nextInt(),v=s.nextInt(); adj[u].add(v); adj[v].add(u); // backadj[v].add(u); indeg[v]++; indeg[u]++; } // weighted adj // adj=new ArrayList[n+1]; // for(int i=0;i<=n;i++){ // adj[i]=new ArrayList<node>(); // } // for(int i=0;i<m;i++){ // int u=s.nextInt(),v=s.nextInt(); // long w=s.nextInt(); // adj[u].add(new node(v,w)); //// adj[v].add(new node(u,w)); // } } // *********************************GRAPHS-ENDS**************************************************** static int[][] dirs8 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; static int[][] dirs4 = {{1,0},{-1,0},{0,1},{0,-1}}; //d-u-r-l static long MOD=(long) (1e9+7); static int prebitsum[][]; static boolean[] vis; static int[]indeg; // static ArrayList<ArrayList<Integer>>adj; static ArrayList<Integer> adj[]; static ArrayList<Integer> backadj[]; static FastReader s = new FastReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { // sieve(); // computeFact((int)1e7+1,MOD); // prebitsum=new int[2147483648][31]; // presumbit(prebitsum); // powof2S(); // // try { int tt = s.nextInt(); // int tt=1; for(int i=1;i<=tt;i++) { solver(); } // catch(Exception e) {return;} } private static void solver() { int n=s.nextInt(); long l=s.nextLong(); long r=s.nextLong(); boolean f=true; StringBuilder ans=new StringBuilder(); for(int i=1;i<=n;i++) { long x=i*(r/i); if(x<l||x>r) { f=false; } ans.append(x); ans.append(" "); } if(f) { System.out.println("YES"); System.out.println(ans); } else System.out.println("NO"); } public static int BS(long val , ArrayList<pair> al){ int l=0; int r = al.size(); while(l<r){ int mid = (r+l)/2; if(al.get(mid).x<=val){ l = mid+1; }else{ r = mid; } } return r; } /* *********************BITS && TOOLS &&DEBUG STARTS***********************************************/ static boolean issafe(int i, int j, int k,int r,int c,int h){ if (i < 0 || j < 0 || i >= r || j >= c)return false; else return true; } static void presumbit(int[][]prebitsum) { for(int i=1;i<=200000;i++) { int z=i; int j=0; while(z>0) { if((z&1)==1) { prebitsum[i][j]+=(prebitsum[i-1][j]+1); }else { prebitsum[i][j]=prebitsum[i-1][j]; } z=z>>1; j++; } } } static void countOfSetBit(long[]a) { for(int j=30;j>=0;j--) { int cnt=0; for(long i:a) { if((i&1<<j)==1)cnt++; } // printing the current no set bit in all array element System.out.println(cnt); } } public static String revStr(String str){String input = str;StringBuilder input1 = new StringBuilder();input1.append(input);input1.reverse();return input1.toString();} static void printA(int[]a) {for(int i:a)System.out.print(i+" ");System.out.println();} static void pc2d(boolean[][] vis) { int n=vis.length; int m=vis[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(vis[i][j]+" "); } System.out.println(); } } static void pi2d(char[][] a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void p1d(int[]a) { for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } // *****************BITS && TOOLS &&DEBUG ENDS*********************************************** } // **************************I/O************************* class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; public FastReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = null;} public String next() {while (tokenizer == null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(reader.readLine());} catch (IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() {String str = "";try {str = reader.readLine();}catch (IOException e) {e.printStackTrace();}return str;} } class pair{ long x,y; char c; int u,v; public pair(char c,int v) {this.c=c;this.v=v;} public pair(long x,long y) {this.x=x;this.y=y;} public pair(int u,int v) {this.u=u;this.v=v;}; public boolean greater(pair node) { if (x > node.x || (x == node.x && y > node.y)) { return true; } return false; } } class node implements Comparator<node>{ private int v; private long w; node(int _v, long _w) { v = _v; w = _w; } node() {} int getV() { return v; } long getW() { return w; } @Override public int compare(node node1, node node2) { if (node1.w < node2.w) return -1; if (node1.w > node2.w) return 1; return 0; } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
310acad70a2237ee0cf11683fd2d1102
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
/* Author:-crazy_coder- */ import java.io.*; import java.util.*; public class cp{ public static void main(String[] args)throws Exception{ BufferedReader br=new BufferedReader (new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); // int t=1; while(t-->0){ String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); long l=Long.parseLong(str[1]); long r=Long.parseLong(str[2]); long[] arr=new long[n+1]; // String[] str1=br.readLine().split(" "); boolean flag=true; for(int i=1;i<=n;i++){ long rem=l%i; long val=l+(rem==0?0:i-rem); if(val<=r){ arr[i]=val; }else{ flag=false; break; } } if(flag){ pw.println("YES"); for(int i=1;i<=n;i++){ pw.print(arr[i]+" "); } pw.println(); }else{ pw.println("NO"); } } pw.flush(); } public static boolean findAllFactors(long num,long q){ for(long i = 1; i <= num/i; ++i) { if(num % i == 0) { //if i is a factor, num/i is also a factor if(i+num/i==q)return true; } } return false; //sort the factors } //****************************function to find all factor************************************************* public static ArrayList<Long> findAllFactors(long num){ ArrayList<Long> factors = new ArrayList<Long>(); for(long i = 1; i <= num/i; ++i) { if(num % i == 0) { //if i is a factor, num/i is also a factor factors.add(i); factors.add(num/i); } } //sort the factors Collections.sort(factors); return factors; } //*************************** function to find GCD of two number******************************************* public static long gcd(long a,long b){ if(b==0)return a; return gcd(b,a%b); } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
c9bca2a67441cf3c43e0062e62e4898e
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Div2_808_B { private static InputReader in = new InputReader(System.in); public static void main(String[] args) throws IOException { int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int l = in.nextInt(); int r = in.nextInt(); int[] a = new int[n]; boolean result = true; for (int j = n; j >= 1; j--) { int k = (l / j) * j; while (k < l) { k += j; } if (k > r) { result = false; break; } a[j - 1] = k; } if (result) { System.out.println("YES"); for (int j = 0; j < n; j++) { System.out.print(a[j] + " "); } System.out.println(); } else { System.out.println("NO"); } } } static class InputReader extends BufferedReader { public StringTokenizer tkn; public InputReader(InputStream stream) { super(new InputStreamReader(stream), 32768); } public String next() throws IOException { while (tkn == null || !tkn.hasMoreTokens()) { tkn = new StringTokenizer(readLine()); } return tkn.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
726d2b6a1735da96630159aec7f09fb4
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Difference_of_CDs { static int n=100000; static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int l=sc.nextInt(); int r=sc.nextInt(); int arr[]=new int [n]; boolean f=false; for (int i = 1; i <=n; i++) { if(((((l-1)/i)+1)*i)<=r) arr[i-1]=((((l-1)/i)+1)*i); else f=true; } if(!f) { pw.println("YES"); for (int i = 0; i < n; i++) { pw.print(arr[i]+" "); } pw.println(); } else pw.println("NO"); } pw.flush(); } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } public static void display(char[][] a) { for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.print(a[i][j]); } System.out.println(); } }}
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
8a770912ae0cd31559cade93c30b5d2f
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.Scanner; public class B1708 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); int L = in.nextInt(); int R = in.nextInt(); StringBuilder out = new StringBuilder(); boolean possible = true; for (int n=1; n<=N; n++) { int a = n*(R/n); if (a < L) { possible = false; break; } out.append(a).append(' '); } if (possible) { System.out.println("YES"); System.out.println(out); } else { System.out.println("NO"); } } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
08c138eb001067c5f3f9bf02f4591d8f
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; public class Cf_1708B { BufferedReader br; StringTokenizer in; PrintWriter out; public String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } public static void main(String[] args) throws IOException { new Cf_1708B().run(); } public void solve() throws IOException { int t = nextInt(); for (int tt = 0; tt < t; tt++) { int n = nextInt(); int l = nextInt(); int r = nextInt(); boolean possible = true; int[] a = new int[n]; int mod; for (int i = 1; i <= n; i++) { mod = l % i; if (mod == 0) { a[i - 1] = l; } else { int k = l + (i - mod); if (k > r) { possible = false; break; } else { a[i - 1] = k; } } } if (possible) { out.println("YES"); for (int i = 0; i < n; i++) { out.print(a[i] + " "); } out.println(); } else { out.println("NO"); } } } public void run() { try { /* br = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt");*/ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
56043dad51f6dd08aebbabc6f834ed25
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.Scanner; /** * * @author Acer */ public class NewClass_B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); k: while(T-- > 0){ int n = sc.nextInt(); int l = sc.nextInt(); int r = sc.nextInt(); int j = 1; StringBuilder str = new StringBuilder(); for (int i = 1; i <= n; i++) { int rem = l%i; if(rem == 0){ str.append(l+" "); } else{ int x = l+i-rem; if(x > r){ System.out.println("NO"); continue k; } str.append(x+" "); } } System.out.println("YES"); System.out.println(str.toString()); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
d823dce2035cc74f7707684ec5272e99
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t=scanner.nextInt(); while (t--!=0){ int n= scanner.nextInt(); int l= scanner.nextInt(); int r=scanner.nextInt(); int []a=new int[n+1]; boolean falg=false; for (int i=1;i<=n;i++){ int b=(r/i)*i; if (b>=l&&b<=r){ a[i]=b; }else { falg=true; } if (b==0){ falg=true; } } if (falg){ System.out.println("NO"); }else { System.out.println("YES"); for (int i=1;i<=n;i++){ System.out.print(a[i]+" "); } } } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
230084400b0f396f9e1ea13d441ecb92
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; @SuppressWarnings("unused") public class B_Difference_of_GCDs { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int tc = sc.nextInt(); while (tc-- > 0) { int n = sc.nextInt(), l = sc.nextInt(), r = sc.nextInt(); StringBuilder sb = new StringBuilder(); boolean ok = true; for (int i = 1; i <= n; i++) { int t = l % i; int x = t == 0 ? l : l + i - t; if (x > r) { ok = false; break; } sb.append(' ').append(x); } out.println(ok ? "YES" : "NO"); if (ok) out.println(sb.substring(1)); } out.close(); } public static PrintWriter out; public static long mod = (long) 1e9 + 7; public static int[] parent = new int[101]; public static int[] rank = new int[101]; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void google(int tt) { out.print("Case #" + (tt) + ": "); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } public static void push(TreeMap<Integer, Integer> map, int k, int v) { if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } static int[][] matrixMul(int[][] a, int[][] m) { if (a[0].length == m.length) { int[][] b = new int[a.length][m.length]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m.length; j++) { int sum = 0; for (int k = 0; k < m.length; k++) { sum += m[i][k] * m[k][j]; } b[i][j] = sum; } } return b; } return null; } static void swap(int[] a, int l, int r) { int temp = a[l]; a[l] = a[r]; a[r] = temp; } static void SieveOfEratosthenes(int n, boolean prime[]) { prime[0] = false; prime[1] = false; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) for (int i = p * p; i <= n; i += p) prime[i] = false; } } static void dfs(int root, boolean[] vis, int[] value, ArrayList[] gr, int prev) { vis[root] = true; value[root] = 3 - prev; prev = 3 - prev; for (int i = 0; i < gr[root].size(); i++) { int next = (int) gr[root].get(i); if (!vis[next]) dfs(next, vis, value, gr, prev); } } static boolean isPrime(int n) { for (int i = 2; i <= Math.sqrt(n); i++) if (n % i == 0) return false; return true; } static boolean isPrime(long n) { for (long i = 2; i <= Math.sqrt(n); i++) if (n % i == 0) return false; return true; } static int abs(int a) { return a > 0 ? a : -a; } static int max(int a, int b) { return a > b ? a : b; } static int min(int a, int b) { return a < b ? a : b; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long pow(long n, long m) { if (m == 0) return 1; long temp = pow(n, m / 2); long res = ((temp * temp) % mod); if (m % 2 == 0) return res; return (res * n) % mod; } static long modular_add(long a, long b) { return ((a % mod) + (b % mod)) % mod; } static long modular_sub(long a, long b) { return ((a % mod) - (b % mod) + mod) % mod; } static long modular_mult(long a, long b) { return ((a % mod) * (b % mod)) % mod; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static int gcd(int n1, int n2) { if (n2 != 0) return gcd(n2, n1 % n2); else return n1; } static int find(int u) { if (u == parent[u]) return u; return parent[u] = find(parent[u]); } static void union(int u, int v) { int a = find(u), b = find(v); if (a == b) return; if (rank[a] > rank[b]) { parent[b] = a; rank[a] += rank[b]; } else { parent[a] = b; rank[b] += rank[a]; } } static void dsu() { for (int i = 0; i < 101; i++) { parent[i] = i; rank[i] = 1; } } static class Pair { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } static void sortbyx(Pair[] coll) { List<Pair> al = new ArrayList<>(Arrays.asList(coll)); Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return p1.x - p2.x; } }); for (int i = 0; i < al.size(); i++) { coll[i] = al.get(i); } } static void sortbyy(Pair[] coll) { List<Pair> al = new ArrayList<>(Arrays.asList(coll)); Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return p1.y - p2.y; } }); for (int i = 0; i < al.size(); i++) { coll[i] = al.get(i); } } static void sortbyx(ArrayList<Pair> al) { Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return Integer.compare(p1.x, p2.x); } }); } static void sortbyy(ArrayList<Pair> al) { Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return Integer.compare(p1.y, p2.y); } }); } public String toString() { return String.format("(%s, %s)", String.valueOf(x), String.valueOf(y)); } } static void sort(int[] a) { ArrayList<Integer> list = new ArrayList<>(); for (int i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static void sort(long a[]) { ArrayList<Long> list = new ArrayList<>(); for (long i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static int[] array(int n, int value) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = value; return a; } static long sum(long a[]) { long sum = 0; for (long i : a) sum += i; return (sum); } static long count(long a[], long x) { long c = 0; for (long i : a) if (i == x) c++; return (c); } static int sum(int a[]) { int sum = 0; for (int i : a) sum += i; return (sum); } static int count(int a[], int x) { int c = 0; for (int i : a) if (i == x) c++; return (c); } static int count(String s, char ch) { int c = 0; char x[] = s.toCharArray(); for (char i : x) if (ch == i) c++; return (c); } static int[] freq(int a[], int n) { int f[] = new int[n + 1]; for (int i : a) f[i]++; return f; } static int[] pos(int a[], int n) { int f[] = new int[n + 1]; for (int i = 0; i < n; i++) f[a[i]] = i; return f; } static boolean isPalindrome(String s) { StringBuilder sb = new StringBuilder(); sb.append(s); String str = String.valueOf(sb.reverse()); if (s.equals(str)) return true; else return false; } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
3bb93227a5920947cb909f0aae8e5c8f
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); long l=sc.nextInt(); long r=sc.nextInt(); long arr[]=new long[n]; arr[0]=l; boolean flag=true; for(int i=2;i<=n;i++) { if(l%i==0) { arr[i-1]=l; continue; } long m=l/i; m*=i; m+=i; if(m>r) { flag=false; break; } arr[i-1]=m; } if(!flag) { System.out.println("NO"); continue; } System.out.println("YES"); for(long x:arr) { System.out.print(x+" "); } System.out.println(); } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
da3b97df56ad94780f0a7df8f0399d39
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.io.*; import java.lang.Math; public class cp{ 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 { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[])throws Exception{ FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int l=sc.nextInt(); int r=sc.nextInt(); int a[]=new int[n+1]; boolean flag=true; for(int i=1;i<=n;i++){ a[i]=((l-1)/i+1)*i; if(a[i]>r){ flag=false; break; } } if(flag){ System.out.println("YES"); for(int i=1;i<=n;i++){ System.out.print(a[i]+" "); } System.out.println(); } else{ System.out.println("NO"); } } } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
44a13e0b8e858f6fa5d9c4b9bc79e630
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.security.cert.X509CRL; import java.util.*; import java.lang.*; import java.util.stream.Collector; import java.util.stream.Collectors; @SuppressWarnings("unused") public class Main { static InputStream is; static PrintWriter out; //static String INPUT = "in.txt"; static String INPUT = ""; static String OUTPUT = ""; //global const //private final static long BASE = 998244353L; private final static int ALPHABET = (int)('z') - (int)('a') + 1; private final static long BASE = 1000000007l; private final static int INF_I = 1000000000; private final static long INF_L = 10000000000000000l; private final static int MAXN = 1000100; private final static int MAXK = 30; private final static int[] DX = {-1,0,1,0}; private final static int[] DY = {0,1,0,-1}; //global static void solve() { //int ntest = 1; int ntest = readInt(); for (int test=0;test<ntest;test++) { int N = readInt(), L = readInt(), R = readInt(); long[] ans = new long[N]; boolean isOk = true; Set<Integer> used = new HashSet<>(); for (int i=1;i<=N;i++) { long curr = 1l*((L+i-1)/i) * i; isOk &= (L<=curr && curr<=R); ans[i-1] = curr; } if (isOk) { out.println("Yes"); for (int i=0; i<N; i++) out.print(ans[i] + " "); out.println(); } else { out.println("No"); } } } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); if (INPUT=="") { is = System.in; } else { File file = new File(INPUT); is = new FileInputStream(file); } if (OUTPUT == "") out = new PrintWriter(System.out); else out = new PrintWriter(OUTPUT); solve(); out.flush(); long G = System.currentTimeMillis(); } private static class MultiSet<T extends Comparable<T>> { private TreeSet<T> set; private Map<T, Integer> count; public MultiSet() { this.set = new TreeSet<>(); this.count = new HashMap<>(); } public void add(T x) { this.set.add(x); int o = this.count.getOrDefault(x, 0); this.count.put(x, o+1); } public void remove(T x) { int o = this.count.getOrDefault(x, 0); if (o==0) return; this.count.put(x, o-1); if (o==1) this.set.remove(x); } public T first() { return this.set.first(); } public T last() { return this.set.last(); } public int size() { int res = 0; for (T x: this.set) res += this.count.get(x); return res; } } private static class Point<T extends Number & Comparable<T>> implements Comparable<Point<T>> { private T x; private T y; public Point(T x, T y) { this.x = x; this.y = y; } public T getX() {return x;} public T getY() {return y;} @Override public int compareTo(Point<T> o) { int cmp = x.compareTo(o.getX()); if (cmp==0) return y.compareTo(o.getY()); return cmp; } } private static class ClassComparator<T extends Comparable<T>> implements Comparator<T> { public ClassComparator() {} @Override public int compare(T a, T b) { return a.compareTo(b); } } private static class ListComparator<T extends Comparable<T>> implements Comparator<List<T>> { public ListComparator() {} @Override public int compare(List<T> o1, List<T> o2) { for (int i = 0; i < Math.min(o1.size(), o2.size()); i++) { int c = o1.get(i).compareTo(o2.get(i)); if (c != 0) { return c; } } return Integer.compare(o1.size(), o2.size()); } } private static boolean eof() { if(lenbuf == -1)return true; int lptr = ptrbuf; while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false; try { is.mark(1000); while(true){ int b = is.read(); if(b == -1){ is.reset(); return true; }else if(!isSpaceChar(b)){ is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static 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 static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } // private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static double readDouble() { return Double.parseDouble(readString()); } private static char readChar() { return (char)skip(); } private static String readString() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] readChar(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 static char[][] readTable(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = readChar(m); return map; } private static int[] readIntArray(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = readInt(); return a; } private static long[] readLongArray(int n) { long[] a = new long[n]; for (int i=0;i<n;i++) a[i] = readLong(); return a; } private static int readInt() { 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 static long readLong() { 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 static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
7138c0a7a764af48d3a914eb742afb49
train_108.jsonl
1657982100
You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.StringTokenizer; /** * @author KaiXin * @version 11 * @date 2022-07-12 20:05 */ public class TaskB { static final int SIZE = (int)1e5 + 5; static long[] a = new long[SIZE]; public static void solve(InputReader in,PrintWriter out){ long n = in.nextLong(),l = in.nextLong(),r = in.nextLong(); int i = 0; for(i = 1; i <= n; ++i){ long t = l % i; if(t == 0) a[i] = l; else { t = (l / i + 1) * i; if(t <= r) a[i] = t; else break; } } if(i == n + 1) { out.println("YES"); for(i = 1; i <= n; ++i) out.print(a[i] + " "); out.println(); } else out.println("NO"); } private static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int T = 1; T = in.nextInt(); for(int i = 1; i <= T; ++i){ solve(in,out); } out.close(); } }
Java
["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"]
1 second
["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"]
NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively.
Java 8
standard input
[ "constructive algorithms", "math" ]
d2cc6efe7173a64482659ba59efeec16
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,100
For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.
standard output
PASSED
fa8fd552cfdb8e19b78389cbd005e039
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; public class A { static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder str = new StringBuilder(); int t = sc.nextInt(); for (int xx = 1; xx <= t; xx++) { int n = sc.nextInt(); int q = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int low = 0; int a = -1; int high = n - 1; while (low <= high) { int mid = low + high >> 1; boolean ok = true; int q1 = q; for (int i = mid; i < n; i++) { if (q1 == 0) ok = false; if (arr[i] > q1) q1--; } if (ok) { high = mid - 1; a = mid; } else low = mid + 1; } for (int i = 0; i < n; i++) { if (i < a) { str.append(arr[i] <= q ? 1 : 0); } else { str.append(1); } } str.append("\n"); } System.out.println(str); sc.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
1a3d11b20d880c0bb53367655700baeb
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; /** * * @author eslam */ public class IceCave { static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName + ".out"); r = new BufferedReader(new FileReader(problemName + ".in")); } // returns null if no more input String nextLine() { String str = ""; try { str = r.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(r.readLine()); } return st.nextToken(); } catch (Exception e) { } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } // Beginning of the solution static Kattio input = new Kattio(); static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); static ArrayList<ArrayList<Integer>> powerSet = new ArrayList<>(); static ArrayList<LinkedList<Integer>> allprem = new ArrayList<>(); static ArrayList<LinkedList<String>> allprems = new ArrayList<>(); static ArrayList<Long> luc = new ArrayList<>(); static long mod = (long) (Math.pow(10, 9) + 7); static int dp[][][]; static char ans[]; public static void main(String[] args) throws IOException { int t = input.nextInt(); loop: while (t-- > 0) { int n = input.nextInt(); int iq = input.nextInt(); ans = new char[n]; int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = input.nextInt(); } int max = n; int min = 0; while (max >= min) { int mid = (max + min) / 2; if (can(mid, a, iq)) { min = mid + 1; } else { max = mid - 1; } } for (int i = 0; i < n; i++) { log.write(ans[i]+""); } log.write("\n"); } log.flush(); } public static boolean can(int num, int a[], int iq) { TreeSet<Integer> s = new TreeSet<>(); for (int i = 0; i < a.length && num > 0; i++) { if (iq == 0) { return false; } if (a[i] > iq) { if (a.length - i - 1 < num) { iq--; s.add(i); num--; } } else { s.add(i); num--; } } for (int i = 0; i < a.length; i++) { if (s.contains(i)) { ans[i] = '1'; } else { ans[i] = '0'; } } return true; } public static int getlo(int va) { int v = 1; while (v <= va) { if ((va&v) != 0) { return v; } v <<= 1; } return 0; } static long fast_pow(long a, long p) { long res = 1; while (p > 0) { if (p % 2 == 0) { a = (a * a) % mod; p /= 2; } else { res = (res * a) % mod; p--; } } return res; } public static int countPrimeInRange(int n, boolean isPrime[]) { int cnt = 0; for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = i * 2; j <= n; j += i) { isPrime[j] = false; } } } for (int i = 2; i <= n; i++) { if (isPrime[i]) { cnt++; } } return cnt; } public static void create(long num) { luc.add(num); if (num > power(10, 9)) { return; } create(num * 10 + 4); create(num * 10 + 7); } public static long ceil(long a, long b) { return (a + b - 1) / b; } public static long round(long a, long b) { if (a < 0) { return (a - b / 2) / b; } return (a + b / 2) / b; } public static void allPremutationsst(LinkedList<String> l, boolean visited[], ArrayList<String> st) { if (l.size() == st.size()) { allprems.add(l); } for (int i = 0; i < st.size(); i++) { if (!visited[i]) { visited[i] = true; LinkedList<String> nl = new LinkedList<>(); for (String x : l) { nl.add(x); } nl.add(st.get(i)); allPremutationsst(nl, visited, st); visited[i] = false; } } } public static void allPremutations(LinkedList<Integer> l, boolean visited[], int a[]) { if (l.size() == a.length) { allprem.add(l); } for (int i = 0; i < a.length; i++) { if (!visited[i]) { visited[i] = true; LinkedList<Integer> nl = new LinkedList<>(); for (Integer x : l) { nl.add(x); } nl.add(a[i]); allPremutations(nl, visited, a); visited[i] = false; } } } public static int binarySearch(long[] a, long value) { int l = 0; int r = a.length - 1; while (l <= r) { int m = (l + r) / 2; if (a[m] == value) { return m; } else if (a[m] > value) { r = m - 1; } else { l = m + 1; } } return -1; } public static void reverse(int l, int r, char ch[]) { for (int i = 0; i < r / 2; i++) { char c = ch[i]; ch[i] = ch[r - i - 1]; ch[r - i - 1] = c; } } public static int logK(long v, long k) { int ans = 0; while (v > 1) { ans++; v /= k; } return ans; } public static long power(long a, long n) { if (n == 1) { return a; } long pow = power(a, n / 2); pow *= pow; if (n % 2 != 0) { pow *= a; } return pow; } public static long get(long max, long x) { if (x == 1) { return max; } int cnt = 0; while (max > 0) { cnt++; max /= x; } return cnt; } public static int numOF0(long v) { long x = 1; int cnt = 0; while (x <= v) { if ((x & v) == 0) { cnt++; } x <<= 1; } return cnt; } public static int log2(double n) { int cnt = 0; while (n > 1) { n /= 2; cnt++; } return cnt; } public static int[] bfs(int node, ArrayList<Integer> a[]) { Queue<Integer> q = new LinkedList<>(); q.add(node); int distances[] = new int[a.length]; Arrays.fill(distances, -1); distances[node] = 0; while (!q.isEmpty()) { int parent = q.poll(); ArrayList<Integer> nodes = a[parent]; int cost = distances[parent]; for (Integer node1 : nodes) { if (distances[node1] == -1) { q.add(node1); distances[node1] = cost + 1; } } } return distances; } public static int get(int n) { int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } public static ArrayList<Integer> primeFactors(int n) { ArrayList<Integer> a = new ArrayList<>(); while (n % 2 == 0) { a.add(2); n /= 2; } for (int i = 3; i <= Math.sqrt(n); i += 2) { while (n % i == 0) { a.add(i); n /= i; } if (n < i) { break; } } if (n > 2) { a.add(n); } return a; } public static ArrayList<Integer> printPrimeFactoriztion(int n) { ArrayList<Integer> a = new ArrayList<>(); for (int i = 1; i < Math.sqrt(n) + 1; i++) { if (n % i == 0) { if (isPrime(i)) { a.add(i); n /= i; i = 0; } else if (isPrime(n / i)) { a.add(n / i); n = i; i = 0; } } } return a; } // end of solution public static BigInteger f(long n) { if (n <= 1) { return BigInteger.ONE; } long t = n - 1; BigInteger b = new BigInteger(t + ""); BigInteger ans = new BigInteger(n + ""); while (t > 1) { ans = ans.multiply(b); b = b.subtract(BigInteger.ONE); t--; } return ans; } public static long factorial(long n) { if (n <= 1) { return 1; } long t = n - 1; while (t > 1) { n = mod((mod(n, mod) * mod(t, mod)), mod); t--; } return n; } public static long rev(long n) { long t = n; long ans = 0; while (t > 0) { ans = ans * 10 + t % 10; t /= 10; } return ans; } public static boolean isPalindrome(int n) { int t = n; int ans = 0; while (t > 0) { ans = ans * 10 + t % 10; t /= 10; } return ans == n; } static class tri { int x, y, z; public tri(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } static boolean isPrime(long num) { if (num == 1) { return false; } if (num == 2) { return true; } if (num % 2 == 0) { return false; } if (num == 3) { return true; } for (int i = 3; i <= Math.sqrt(num) + 1; i += 2) { if (num % i == 0) { return false; } } return true; } public static void prefixSum(long[] a) { for (int i = 1; i < a.length; i++) { a[i] = a[i] + a[i - 1]; } } public static void suffixSum(long[] a) { for (int i = a.length - 2; i > -1; i--) { a[i] = a[i] + a[i + 1]; } } static long mod(long a, long b) { long r = a % b; return r < 0 ? r + b : r; } public static long binaryToDecimal(String w) { long r = 0; long l = 0; for (int i = w.length() - 1; i > -1; i--) { long x = (w.charAt(i) - '0') * (long) Math.pow(2, l); r = r + x; l++; } return r; } public static String decimalToBinary(long n) { String w = ""; while (n > 0) { w = n % 2 + w; n /= 2; } return w; } public static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] >= a[i + 1]) { return false; } } return true; } public static void print(int[] a) throws IOException { for (int i = 0; i < a.length; i++) { log.write(a[i] + " "); } log.write("\n"); } public static void read(int[] a) { for (int i = 0; i < a.length; i++) { a[i] = input.nextInt(); } } static class pair { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return x + " " + y; } } public static long LCM(long x, long y) { return x / GCD(x, y) * y; } public static long GCD(long x, long y) { if (y == 0) { return x; } return GCD(y, x % y); } public static void simplifyTheFraction(long a, long b) { long GCD = GCD(a, b); System.out.println(a / GCD + " " + b / GCD); } /** */ // class RedBlackNode static class RedBlackNode<T extends Comparable<T>> { /** * Possible color for this node */ public static final int BLACK = 0; /** * Possible color for this node */ public static final int RED = 1; // the key of each node public T key; /** * Parent of node */ RedBlackNode<T> parent; /** * Left child */ RedBlackNode<T> left; /** * Right child */ RedBlackNode<T> right; // the number of elements to the left of each node public int numLeft = 0; // the number of elements to the right of each node public int numRight = 0; // the color of a node public int color; RedBlackNode() { color = BLACK; numLeft = 0; numRight = 0; parent = null; left = null; right = null; } // Constructor which sets key to the argument. RedBlackNode(T key) { this(); this.key = key; } }// end class RedBlackNode static class RedBlackTree<T extends Comparable<T>> { // Root initialized to nil. private RedBlackNode<T> nil = new RedBlackNode<T>(); private RedBlackNode<T> root = nil; public RedBlackTree() { root.left = nil; root.right = nil; root.parent = nil; } // @param: X, The node which the lefRotate is to be performed on. // Performs a leftRotate around X. private void leftRotate(RedBlackNode<T> x) { // Call leftRotateFixup() which updates the numLeft // and numRight values. leftRotateFixup(x); // Perform the left rotate as described in the algorithm // in the course text. RedBlackNode<T> y; y = x.right; x.right = y.left; // Check for existence of y.left and make pointer changes if (!isNil(y.left)) { y.left.parent = x; } y.parent = x.parent; // X's parent is nul if (isNil(x.parent)) { root = y; } // X is the left child of it's parent else if (x.parent.left == x) { x.parent.left = y; } // X is the right child of it's parent. else { x.parent.right = y; } // Finish of the leftRotate y.left = x; x.parent = y; }// end leftRotate(RedBlackNode X) // @param: X, The node which the leftRotate is to be performed on. // Updates the numLeft & numRight values affected by leftRotate. private void leftRotateFixup(RedBlackNode x) { // Case 1: Only X, X.right and X.right.right always are not nil. if (isNil(x.left) && isNil(x.right.left)) { x.numLeft = 0; x.numRight = 0; x.right.numLeft = 1; } // Case 2: X.right.left also exists in addition to Case 1 else if (isNil(x.left) && !isNil(x.right.left)) { x.numLeft = 0; x.numRight = 1 + x.right.left.numLeft + x.right.left.numRight; x.right.numLeft = 2 + x.right.left.numLeft + x.right.left.numRight; } // Case 3: X.left also exists in addition to Case 1 else if (!isNil(x.left) && isNil(x.right.left)) { x.numRight = 0; x.right.numLeft = 2 + x.left.numLeft + x.left.numRight; } // Case 4: X.left and X.right.left both exist in addtion to Case 1 else { x.numRight = 1 + x.right.left.numLeft + x.right.left.numRight; x.right.numLeft = 3 + x.left.numLeft + x.left.numRight + x.right.left.numLeft + x.right.left.numRight; } }// end leftRotateFixup(RedBlackNode X) // @param: X, The node which the rightRotate is to be performed on. // Updates the numLeft and numRight values affected by the Rotate. private void rightRotate(RedBlackNode<T> y) { // Call rightRotateFixup to adjust numRight and numLeft values rightRotateFixup(y); // Perform the rotate as described in the course text. RedBlackNode<T> x = y.left; y.left = x.right; // Check for existence of X.right if (!isNil(x.right)) { x.right.parent = y; } x.parent = y.parent; // y.parent is nil if (isNil(y.parent)) { root = x; } // y is a right child of it's parent. else if (y.parent.right == y) { y.parent.right = x; } // y is a left child of it's parent. else { y.parent.left = x; } x.right = y; y.parent = x; }// end rightRotate(RedBlackNode y) // @param: y, the node around which the righRotate is to be performed. // Updates the numLeft and numRight values affected by the rotate private void rightRotateFixup(RedBlackNode y) { // Case 1: Only y, y.left and y.left.left exists. if (isNil(y.right) && isNil(y.left.right)) { y.numRight = 0; y.numLeft = 0; y.left.numRight = 1; } // Case 2: y.left.right also exists in addition to Case 1 else if (isNil(y.right) && !isNil(y.left.right)) { y.numRight = 0; y.numLeft = 1 + y.left.right.numRight + y.left.right.numLeft; y.left.numRight = 2 + y.left.right.numRight + y.left.right.numLeft; } // Case 3: y.right also exists in addition to Case 1 else if (!isNil(y.right) && isNil(y.left.right)) { y.numLeft = 0; y.left.numRight = 2 + y.right.numRight + y.right.numLeft; } // Case 4: y.right & y.left.right exist in addition to Case 1 else { y.numLeft = 1 + y.left.right.numRight + y.left.right.numLeft; y.left.numRight = 3 + y.right.numRight + y.right.numLeft + y.left.right.numRight + y.left.right.numLeft; } }// end rightRotateFixup(RedBlackNode y) public void insert(T key) { insert(new RedBlackNode<T>(key)); } // @param: z, the node to be inserted into the Tree rooted at root // Inserts z into the appropriate position in the RedBlackTree while // updating numLeft and numRight values. private void insert(RedBlackNode<T> z) { // Create a reference to root & initialize a node to nil RedBlackNode<T> y = nil; RedBlackNode<T> x = root; // While we haven't reached a the end of the tree keep // tryint to figure out where z should go while (!isNil(x)) { y = x; // if z.key is < than the current key, go left if (z.key.compareTo(x.key) < 0) { // Update X.numLeft as z is < than X x.numLeft++; x = x.left; } // else z.key >= X.key so go right. else { // Update X.numGreater as z is => X x.numRight++; x = x.right; } } // y will hold z's parent z.parent = y; // Depending on the value of y.key, put z as the left or // right child of y if (isNil(y)) { root = z; } else if (z.key.compareTo(y.key) < 0) { y.left = z; } else { y.right = z; } // Initialize z's children to nil and z's color to red z.left = nil; z.right = nil; z.color = RedBlackNode.RED; // Call insertFixup(z) insertFixup(z); }// end insert(RedBlackNode z) // @param: z, the node which was inserted and may have caused a violation // of the RedBlackTree properties // Fixes up the violation of the RedBlackTree properties that may have // been caused during insert(z) private void insertFixup(RedBlackNode<T> z) { RedBlackNode<T> y = nil; // While there is a violation of the RedBlackTree properties.. while (z.parent.color == RedBlackNode.RED) { // If z's parent is the the left child of it's parent. if (z.parent == z.parent.parent.left) { // Initialize y to z 's cousin y = z.parent.parent.right; // Case 1: if y is red...recolor if (y.color == RedBlackNode.RED) { z.parent.color = RedBlackNode.BLACK; y.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; z = z.parent.parent; } // Case 2: if y is black & z is a right child else if (z == z.parent.right) { // leftRotaet around z's parent z = z.parent; leftRotate(z); } // Case 3: else y is black & z is a left child else { // recolor and rotate round z's grandpa z.parent.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; rightRotate(z.parent.parent); } } // If z's parent is the right child of it's parent. else { // Initialize y to z's cousin y = z.parent.parent.left; // Case 1: if y is red...recolor if (y.color == RedBlackNode.RED) { z.parent.color = RedBlackNode.BLACK; y.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; z = z.parent.parent; } // Case 2: if y is black and z is a left child else if (z == z.parent.left) { // rightRotate around z's parent z = z.parent; rightRotate(z); } // Case 3: if y is black and z is a right child else { // recolor and rotate around z's grandpa z.parent.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; leftRotate(z.parent.parent); } } } // Color root black at all times root.color = RedBlackNode.BLACK; }// end insertFixup(RedBlackNode z) // @param: node, a RedBlackNode // @param: node, the node with the smallest key rooted at node public RedBlackNode<T> treeMinimum(RedBlackNode<T> node) { // while there is a smaller key, keep going left while (!isNil(node.left)) { node = node.left; } return node; }// end treeMinimum(RedBlackNode node) // @param: X, a RedBlackNode whose successor we must find // @return: return's the node the with the next largest key // from X.key public RedBlackNode<T> treeSuccessor(RedBlackNode<T> x) { // if X.left is not nil, call treeMinimum(X.right) and // return it's value if (!isNil(x.left)) { return treeMinimum(x.right); } RedBlackNode<T> y = x.parent; // while X is it's parent's right child... while (!isNil(y) && x == y.right) { // Keep moving up in the tree x = y; y = y.parent; } // Return successor return y; }// end treeMinimum(RedBlackNode X) // @param: z, the RedBlackNode which is to be removed from the the tree // Remove's z from the RedBlackTree rooted at root public void remove(RedBlackNode<T> v) { RedBlackNode<T> z = search(v.key); // Declare variables RedBlackNode<T> x = nil; RedBlackNode<T> y = nil; // if either one of z's children is nil, then we must remove z if (isNil(z.left) || isNil(z.right)) { y = z; } // else we must remove the successor of z else { y = treeSuccessor(z); } // Let X be the left or right child of y (y can only have one child) if (!isNil(y.left)) { x = y.left; } else { x = y.right; } // link X's parent to y's parent x.parent = y.parent; // If y's parent is nil, then X is the root if (isNil(y.parent)) { root = x; } // else if y is a left child, set X to be y's left sibling else if (!isNil(y.parent.left) && y.parent.left == y) { y.parent.left = x; } // else if y is a right child, set X to be y's right sibling else if (!isNil(y.parent.right) && y.parent.right == y) { y.parent.right = x; } // if y != z, trasfer y's satellite data into z. if (y != z) { z.key = y.key; } // Update the numLeft and numRight numbers which might need // updating due to the deletion of z.key. fixNodeData(x, y); // If y's color is black, it is a violation of the // RedBlackTree properties so call removeFixup() if (y.color == RedBlackNode.BLACK) { removeFixup(x); } }// end remove(RedBlackNode z) // @param: y, the RedBlackNode which was actually deleted from the tree // @param: key, the value of the key that used to be in y private void fixNodeData(RedBlackNode<T> x, RedBlackNode<T> y) { // Initialize two variables which will help us traverse the tree RedBlackNode<T> current = nil; RedBlackNode<T> track = nil; // if X is nil, then we will start updating at y.parent // Set track to y, y.parent's child if (isNil(x)) { current = y.parent; track = y; } // if X is not nil, then we start updating at X.parent // Set track to X, X.parent's child else { current = x.parent; track = x; } // while we haven't reached the root while (!isNil(current)) { // if the node we deleted has a different key than // the current node if (y.key != current.key) { // if the node we deleted is greater than // current.key then decrement current.numRight if (y.key.compareTo(current.key) > 0) { current.numRight--; } // if the node we deleted is less than // current.key thendecrement current.numLeft if (y.key.compareTo(current.key) < 0) { current.numLeft--; } } // if the node we deleted has the same key as the // current node we are checking else { // the cases where the current node has any nil // children and update appropriately if (isNil(current.left)) { current.numLeft--; } else if (isNil(current.right)) { current.numRight--; } // the cases where current has two children and // we must determine whether track is it's left // or right child and update appropriately else if (track == current.right) { current.numRight--; } else if (track == current.left) { current.numLeft--; } } // update track and current track = current; current = current.parent; } }//end fixNodeData() // @param: X, the child of the deleted node from remove(RedBlackNode v) // Restores the Red Black properties that may have been violated during // the removal of a node in remove(RedBlackNode v) private void removeFixup(RedBlackNode<T> x) { RedBlackNode<T> w; // While we haven't fixed the tree completely... while (x != root && x.color == RedBlackNode.BLACK) { // if X is it's parent's left child if (x == x.parent.left) { // set w = X's sibling w = x.parent.right; // Case 1, w's color is red. if (w.color == RedBlackNode.RED) { w.color = RedBlackNode.BLACK; x.parent.color = RedBlackNode.RED; leftRotate(x.parent); w = x.parent.right; } // Case 2, both of w's children are black if (w.left.color == RedBlackNode.BLACK && w.right.color == RedBlackNode.BLACK) { w.color = RedBlackNode.RED; x = x.parent; } // Case 3 / Case 4 else { // Case 3, w's right child is black if (w.right.color == RedBlackNode.BLACK) { w.left.color = RedBlackNode.BLACK; w.color = RedBlackNode.RED; rightRotate(w); w = x.parent.right; } // Case 4, w = black, w.right = red w.color = x.parent.color; x.parent.color = RedBlackNode.BLACK; w.right.color = RedBlackNode.BLACK; leftRotate(x.parent); x = root; } } // if X is it's parent's right child else { // set w to X's sibling w = x.parent.left; // Case 1, w's color is red if (w.color == RedBlackNode.RED) { w.color = RedBlackNode.BLACK; x.parent.color = RedBlackNode.RED; rightRotate(x.parent); w = x.parent.left; } // Case 2, both of w's children are black if (w.right.color == RedBlackNode.BLACK && w.left.color == RedBlackNode.BLACK) { w.color = RedBlackNode.RED; x = x.parent; } // Case 3 / Case 4 else { // Case 3, w's left child is black if (w.left.color == RedBlackNode.BLACK) { w.right.color = RedBlackNode.BLACK; w.color = RedBlackNode.RED; leftRotate(w); w = x.parent.left; } // Case 4, w = black, and w.left = red w.color = x.parent.color; x.parent.color = RedBlackNode.BLACK; w.left.color = RedBlackNode.BLACK; rightRotate(x.parent); x = root; } } }// end while // set X to black to ensure there is no violation of // RedBlack tree Properties x.color = RedBlackNode.BLACK; }// end removeFixup(RedBlackNode X) // @param: key, the key whose node we want to search for // @return: returns a node with the key, key, if not found, returns null // Searches for a node with key k and returns the first such node, if no // such node is found returns null public RedBlackNode<T> search(T key) { // Initialize a pointer to the root to traverse the tree RedBlackNode<T> current = root; // While we haven't reached the end of the tree while (!isNil(current)) { // If we have found a node with a key equal to key if (current.key.equals(key)) // return that node and exit search(int) { return current; } // go left or right based on value of current and key else if (current.key.compareTo(key) < 0) { current = current.right; } // go left or right based on value of current and key else { current = current.left; } } // we have not found a node whose key is "key" return null; }// end search(int key) // @param: key, any Comparable object // @return: return's the number of elements greater than key public int numGreater(T key) { // Call findNumGreater(root, key) which will return the number // of nodes whose key is greater than key return findNumGreater(root, key); }// end numGreater(int key) // @param: key, any Comparable object // @return: return's teh number of elements smaller than key public int numSmaller(T key) { // Call findNumSmaller(root,key) which will return // the number of nodes whose key is greater than key return findNumSmaller(root, key); }// end numSmaller(int key) // @param: node, the root of the tree, the key who we must // compare other node key's to. // @return: the number of nodes greater than key. public int findNumGreater(RedBlackNode<T> node, T key) { // Base Case: if node is nil, return 0 if (isNil(node)) { return 0; } // If key is less than node.key, all elements right of node are // greater than key, add this to our total and look to the left else if (key.compareTo(node.key) < 0) { return 1 + node.numRight + findNumGreater(node.left, key); } // If key is greater than node.key, then look to the right as // all elements to the left of node are smaller than key else { return findNumGreater(node.right, key); } }// end findNumGreater(RedBlackNode, int key) /** * Returns sorted list of keys greater than key. Size of list will not * exceed maxReturned * * @param key Key to search for * @param maxReturned Maximum number of results to return * @return List of keys greater than key. List may not exceed * maxReturned */ public List<T> getGreaterThan(T key, Integer maxReturned) { List<T> list = new ArrayList<T>(); getGreaterThan(root, key, list); return list.subList(0, Math.min(maxReturned, list.size())); } private void getGreaterThan(RedBlackNode<T> node, T key, List<T> list) { if (isNil(node)) { return; } else if (node.key.compareTo(key) > 0) { getGreaterThan(node.left, key, list); list.add(node.key); getGreaterThan(node.right, key, list); } else { getGreaterThan(node.right, key, list); } } // @param: node, the root of the tree, the key who we must compare other // node key's to. // @return: the number of nodes smaller than key. public int findNumSmaller(RedBlackNode<T> node, T key) { // Base Case: if node is nil, return 0 if (isNil(node)) { return 0; } // If key is less than node.key, look to the left as all // elements on the right of node are greater than key else if (key.compareTo(node.key) <= 0) { return findNumSmaller(node.left, key); } // If key is larger than node.key, all elements to the left of // node are smaller than key, add this to our total and look // to the right. else { return 1 + node.numLeft + findNumSmaller(node.right, key); } }// end findNumSmaller(RedBlackNode nod, int key) // @param: node, the RedBlackNode we must check to see whether it's nil // @return: return's true of node is nil and false otherwise private boolean isNil(RedBlackNode node) { // return appropriate value return node == nil; }// end isNil(RedBlackNode node) // @return: return's the size of the tree // Return's the # of nodes including the root which the RedBlackTree // rooted at root has. public int size() { // Return the number of nodes to the root's left + the number of // nodes on the root's right + the root itself. return root.numLeft + root.numRight + 1; }// end size() }// end class RedBlackTree }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
ca27411fa74de2cfff8f932559a5d531
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
//codeforces //package someAlgorithms; import java.util.*; import java.io.*; import java.lang.*; public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException{ String[] strNums = br.readLine().split(" "); int t=Integer.parseInt(strNums[0]); while(t-->0) { //todo String[] strNums1 = br.readLine().split(" "); long n=Long.parseLong(strNums1[0]); long q=Long.parseLong(strNums1[1]); // long r=Long.parseLong(strNums1[2]); Long[] arr = new Long[(int)n]; StringTokenizer tk = new StringTokenizer(br.readLine().trim()); for(int i=0;i<n;i++) { arr[i]=Long.parseLong(tk.nextToken()); } // Comp obj = new Comp(); // PriorityQueue<Pair> pq = new PriorityQueue<>(obj); // for(int i=0;i<n;i++) { // pq.add(new Pair(arr[i],i)); // } // // HashSet<Integer> set = new HashSet<>(); // while(q>0 && pq.size()>0) { // Pair p = pq.poll(); // // if(p.val<=q) { // set.add((int)p.id); // } // else { // q--; // set.add((int)p.id); // } // } StringBuffer str = new StringBuffer(""); int gtq = 0; for(int i=0;i<n;i++) { if(arr[i]>q) { gtq++; } } if(n==1) { System.out.println("1"); continue; } // if(q>n) { // // for(int i=0;i<n;i++) { // str.append('1'); // } // } // else if(gtq<q) { // for(int i=0;i<n;i++) { // str.append('1'); // } // } // else { // boolean[] temp = new boolean[(int)n]; for(int i=0;i<n;i++) { str.append('0'); } str.replace((int)n-1, (int)n, "1"); long c=1; for(int i=(int)n-2;i>=0;i--) { if(c<q) { if(arr[i]<=c) { str.replace(i, i+1, "1"); } else { str.replace(i, i+1, "1"); c++; } } else { if(arr[i]<=q) {//here q nahi original q!! (here left and right dono ka best pick kiya hai!) str.replace(i, i+1, "1"); } // else { // str.append('0'); // } } } // str.reverse(); // } System.out.println(str.toString()); } } } /* 3 3 2 3 1 1 4 2 4 3 1 4 1 */ //class Pair{ // public long a=0; // public long b=0; // public Pair(long val,long id){ // this.a=val; // this.b=id; // } // //} //class Pair{ // public long val; // public long id; // public Pair(long val,long id){ // this.val=val; // this.id=id; // } // //} //class Node{ // public int val; //// public Node left=null; //// public Node right=null; // ArrayList<Node> children = new ArrayList<>(); // //} //class Comp implements Comparator<Pair>{ // public int compare(Pair p1,Pair p2) { // if(p1.val<p2.val) { // return -1; // } // if(p1.val>p2.val){ // return 1; // } // else return 0; //MUST WRITE THIS RETURN 0 FOR EQUAL CASE SINCE GIVE RUNTIME ERROR IN SOME COMPLIERS // } //} //if take gcd of whole array the take default gcd=0 and keep doing gcd of 2 elements of array! //public static int gcd(int a, int b){ // if(b==0){ // return a; // } // return gcd(b,a%b); //} //ArrayList<Long>[] adjlist = new ArrayList[(int)n+1]; //for(int i=0;i<n;i++) { // String[] strNums2 = br.readLine().split(" "); // long a=Long.parseLong(strNums2[0]); // long b=Long.parseLong(strNums2[1]); // // adjlist[(int)a].add(b); // adjlist[(int)b].add(a); //} //int[][] vis = new int[(int)n+1][(int)n+1]; /* Long[] arr = new Long[(int)n]; StringTokenizer tk = new StringTokenizer(br.readLine().trim()); for(int i=0;i<n;i++) { arr[i]=Long.parseLong(tk.nextToken()); } Long[][] arr = new Long[(int)n][(int)m]; for(int i=0;i<n;i++) { String[] strNums2 = br.readLine().split(" "); for(int j=0;j<m;j++) { arr[i][j]=Long.parseLong(strNums2[j]); } } 4 4 4 3 2 4 4 4 3 Main m = new Main(); //no need since pair class main class ne niche banao Pair p = m.new Pair(i,i+1); li.add(p); */ //double num = 3.9634; //double onum=num; //num = (double)((int)(num*100))/100; //double down = (num); //float up =(float) down; //if take up as double then will get large value when add (3.96+0.01)!! //if(down<onum) { // up=(float)down+(float)0.01; //// System.out.println(((float)3.96+(float)0.01)); //// System.out.println(3.96+0.01);//here both double, so output double , so here get large output other than 3.97!! //} ////in c++ 3.96+0.01 is by default 3.97 but in java need to type cast to float to get this output!! //System.out.println(down +" "+up); /* #include <iostream> #include <string> #include<vector> #include<queue> #include<utility> #include<limits.h> #include <unordered_set> #include<algorithm> using namespace std; */
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
75a6b6771cf2d2d512ebf66b86ae0eac
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] arr = new int[n]; for(int i=0; i<n; i++) { arr[i]=sc.nextInt(); } int x=0; int[] ans = new int[n]; for(int i=n-1; i>=0; i--) { if(arr[i]<=x) ans[i]=1; else { if(x<q) { x++; ans[i]=1; } else ans[i]=0; } } for(int i=0; i<n; i++) { System.out.print(ans[i]); } System.out.println(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
c5f5d8ad355d2986e8fad06445202659
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
//package Algorithm; import java.awt.List; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; import java.util.PriorityQueue; import java.util.Queue; import java.util.StringTokenizer; public class Main { static int[] visited; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st = new StringTokenizer(br.readLine()); int T = Integer.parseInt(st.nextToken()); for (int test = 1; test <= T; test++) { st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int Q = Integer.parseInt(st.nextToken()); /* * 일단, 1이 최대한 많이 들어 있어야합니다. * Q를 다 소모하는 것이 좋습니다. * 즉 IDX를 찾습니다. 해당 Q 를 다 소모하는(USING BINARY SEARCH) * lower binary search 처믕을 찾기 위해서 */ st = new StringTokenizer(br.readLine()); int[] seq = new int[N+1]; for(int i=1;i<=N;i++) { seq[i] = Integer.parseInt(st.nextToken()); } int idx = 0; int start = 1; int end = N; while(start<end) { int mid = (start+end)/2; int q = Q; for(int i=mid;i<=N;i++) { if(seq[i]>q) { q--; } } if(q<0) { start = mid + 1; } else { end = mid; } } idx = start; StringBuilder sb = new StringBuilder(); for(int i=1;i<idx;i++) { if(seq[i]<=Q) { sb.append("1"); } else { sb.append("0"); } } sb.append("1".repeat(N-idx+1)); bw.write(sb.toString()+"\n"); } bw.flush(); } /* * 만약 idx 가 끝까지 가는경우와 q 가 처음부터든 어디든 저건 진행이 */ public static boolean binary(int start, int end, int num) { while (start <= end) { long mid = (start + end) / 2; } return false; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
f2e560f8887b9f1d8e6d982e32bb4654
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; // whole solution public class new1{ static int mod = 998244353; public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader s = new FastReader(); int t = s.nextInt(); for(int z = 1; z <= t; z++) { int n = s.nextInt(); int q = s.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = s.nextInt(); int be = 0; int en = n; int ans = -1; while(be < en) { int mid = (be + en) / 2; int q1 = q; int i = 0; for(i = mid; i < n; i++) { if(arr[i] > q1) { q1--; } } if(q1 >= 0) { ans = mid; en = mid; } else { be = mid + 1; } } StringBuilder str = new StringBuilder(""); for(int i = 0; i < ans; i++) { if(arr[i] <= q) str = str.append("1"); else str = str.append("0"); } for(int i = ans; i < n; i++) str = str.append("1"); output.write(str + "\n"); } output.flush(); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }}
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
6218e19bd942470c01d8dd50a2aee911
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; public class SolutionQ3{ public static void main(String[] args) { Scanner s = new Scanner (System.in); int times = s.nextInt(); for (int x = 0; x < times; x++){ int len = s.nextInt(); int Q = s.nextInt(); StringBuilder ans = new StringBuilder (); int[] data = new int[len]; for (int i = 0; i < len; i ++){ data[i] = s.nextInt(); } int testingQ = 0; for (int i = len - 1; i >= 0; i --){ if (testingQ >= data[i]){ ans.insert(0, "1"); } else if (testingQ < Q){ testingQ ++; ans.insert(0, "1"); } else{ ans.insert(0, "0"); } } System.out.println(ans); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
34ab08cd77dc4880523926ac1838adcb
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class Doremys_IQ { static FastScanner fs; static FastWriter fw; static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null; private static final int[][] kdir = new int[][]{{-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {2, 1}, {1, 2}}; private static final int[][] dir = new int[][]{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; private static final int iMax = (int) (1e9 + 100), iMin = (int) (-1e9 - 100); private static final long lMax = (long) (1e18 + 100), lMin = (long) (-1e18 - 100); private static final int mod1 = (int) (1e9 + 7); private static final int mod2 = 998244353; public static void main(String[] args) throws IOException { fs = new FastScanner(); fw = new FastWriter(); int t = 1; t = fs.nextInt(); while (t-- > 0) { solve(); } fw.out.close(); } private static void solve() { int n = fs.nextInt(), q = fs.nextInt(); int[] arr = readIntArray(n); List<Integer> indexes = new ArrayList<>(); for (int i = 0; i < n; i++) { if (arr[i] > q) indexes.add(i); } if (indexes.size() == 0) { fw.out.println("1".repeat(n)); return; } int l = 0, r = indexes.size() - 1; while (r - l > 1) { int mid = l + ((r - l) / 2); int idx = indexes.get(mid); if (check(idx, n, arr, q)) r = mid; else l = mid; } int idx = n; if (check(indexes.get(l), n, arr, q)) idx = indexes.get(l); else if (check(indexes.get(r), n, arr, q)) idx = indexes.get(r); StringBuilder ans = new StringBuilder(); for (int i = 0; i < idx; i++) { if (arr[i] <= q) ans.append("1"); else ans.append("0"); } ans.append("1".repeat(n - idx)); fw.out.println(ans); } private static boolean check(int idx, int n, int[] arr, int q) { for (int i = idx; i < n; i++) { if (q == 0) return false; if (arr[i] > q) q--; } return true; } private static class UnionFind { private final int[] parent; private final int[] rank; UnionFind(int n) { parent = new int[n + 5]; rank = new int[n + 5]; for (int i = 0; i <= n; i++) { parent[i] = i; rank[i] = 0; } } private int find(int i) { if (parent[i] == i) return i; return parent[i] = find(parent[i]); } private void union(int a, int b) { a = find(a); b = find(b); if (a != b) { if (rank[a] < rank[b]) { int temp = a; a = b; b = temp; } parent[b] = a; if (rank[a] == rank[b]) rank[a]++; } } } private static class Calc_nCr { private final long[] fact; private final long[] invfact; private final int p; Calc_nCr(int n, int prime) { fact = new long[n + 5]; invfact = new long[n + 5]; p = prime; fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = (i * fact[i - 1]) % p; } invfact[n] = pow(fact[n], p - 2, p); for (int i = n - 1; i >= 0; i--) { invfact[i] = (invfact[i + 1] * (i + 1)) % p; } } private long nCr(int n, int r) { if (r > n || n < 0 || r < 0) return 0; return (((fact[n] * invfact[r]) % p) * invfact[n - r]) % p; } } private static long gcd(long a, long b) { return (b == 0 ? a : gcd(b, a % b)); } private static long lcm(long a, long b) { return ((a * b) / gcd(a, b)); } private static long pow(long a, long b, int mod) { long result = 1; while (b > 0) { if ((b & 1L) == 1) { result = (result * a) % mod; } a = (a * a) % mod; b >>= 1; } return result; } private static long ceilDiv(long a, long b) { return ((a + b - 1) / b); } private static long getMin(long... args) { long min = lMax; for (long arg : args) min = Math.min(min, arg); return min; } private static long getMax(long... args) { long max = lMin; for (long arg : args) max = Math.max(max, arg); return max; } private static boolean isPalindrome(String s, int l, int r) { int i = l, j = r; while (j - i >= 1) { if (s.charAt(i) != s.charAt(j)) return false; i++; j--; } return true; } private static List<Integer> primes(int n) { boolean[] primeArr = new boolean[n + 5]; Arrays.fill(primeArr, true); for (int i = 2; (i * i) <= n; i++) { if (primeArr[i]) { for (int j = i * i; j <= n; j += i) { primeArr[j] = false; } } } List<Integer> primeList = new ArrayList<>(); for (int i = 2; i <= n; i++) { if (primeArr[i]) primeList.add(i); } return primeList; } private static int noOfSetBits(long x) { int cnt = 0; while (x != 0) { x = x & (x - 1); cnt++; } return cnt; } private static boolean isPerfectSquare(long num) { long sqrt = (long) Math.sqrt(num); return ((sqrt * sqrt) == num); } private static class Pair<U, V> { private final U first; private final V second; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return first.equals(pair.first) && second.equals(pair.second); } @Override public int hashCode() { return Objects.hash(first, second); } @Override public String toString() { return "(" + first + ", " + second + ")"; } private Pair(U ff, V ss) { this.first = ff; this.second = ss; } } private static void randomizeIntArr(int[] arr, int n) { Random r = new Random(); for (int i = (n - 1); i > 0; i--) { int j = r.nextInt(i + 1); swapInIntArr(arr, i, j); } } private static void randomizeLongArr(long[] arr, int n) { Random r = new Random(); for (int i = (n - 1); i > 0; i--) { int j = r.nextInt(i + 1); swapInLongArr(arr, i, j); } } private static void swapInIntArr(int[] arr, int a, int b) { int temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; } private static void swapInLongArr(long[] arr, int a, int b) { long temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; } private static int[] readIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = fs.nextInt(); return arr; } private static long[] readLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = fs.nextLong(); return arr; } private static List<Integer> readIntList(int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(fs.nextInt()); return list; } private static List<Long> readLongList(int n) { List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(fs.nextLong()); return list; } private static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws IOException { if (checkOnlineJudge) this.br = new BufferedReader(new FileReader("src/input.txt")); else this.br = new BufferedReader(new InputStreamReader(System.in)); this.st = new StringTokenizer(""); } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException err) { err.printStackTrace(); } } return st.nextToken(); } public String nextLine() { if (st.hasMoreTokens()) { return st.nextToken("").trim(); } try { return br.readLine().trim(); } catch (IOException err) { err.printStackTrace(); } return ""; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } private static class FastWriter { PrintWriter out; FastWriter() throws IOException { if (checkOnlineJudge) out = new PrintWriter(new FileWriter("src/output.txt")); else out = new PrintWriter(System.out); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
18bf0c0cfdf4f9769cd594686892e764
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.util.regex.*; // iske baare me padhna hai // sorting on the basis of count of set bits //Arrays.sort(arr, (a,b)-> Integer.compare(Integer.bitCount(b), Integer.bitCount(a))); // Arrays.sort(arr, (a, b) -> Integer.compare(a[0],b[0])); //increasing order // Arrays.sort(arr, (a, b) -> Integer.compare(b[0],a[0])); //decreasing order // provide key to pq, it will store the key according to the frequency (asc/desc) // PriorityQueue <Integer> pq = new PriorityQueue <>((n1, n2) -> mp.get(n1)-mp.get(n2)); // Collections.sort(Arrays.asList(arr)); //char c[] = fs.next().toCharArray(); //int [] tmp = Arrays.copyOf(arr, n); , it copies a new array and change in one arr won't reflect in other i.e deep copy is done // long ans = (long)a*(long)b; if a and b is of int type, otherwise overflow will occur // very careful with type conversion in java. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public class Main { // dont put 'long type' as index of the array,list or any Collections, only 'int' will work. // System.out.println(); static long mod = 1000000007; static double pi = 3.14159265358979323846; static FastScanner fs = new FastScanner(); public static void main(String[] args) { int tc = fs.nextInt(); for(int i = 0; i < tc; i++) { solve(); } } static void solve() { int n = fs.nextInt(); int q = fs.nextInt(); int [] arr = fs.readArray(n); int idx = binarySearch(0,n-1,arr,q); int [] res = new int[n]; for(int i = 0; i < idx; i++) { if(arr[i] <= q) { res[i] = 1; } } for(int i = idx; i < n; i++) { res[i] = 1; } for(int i = 0; i < n; i++) { System.out.print(res[i]); } System.out.println(); } static int binarySearch(int low, int high, int [] arr, int q) { int idx = -1; while(high >= low) { int mid = high-(high-low)/2; int q1 = q; for(int i = mid; i < arr.length; i++) { if(arr[i] > q1) { q1--; } } if(q1 < 0) { low = mid+1; } else { high = mid-1; idx = mid; } } return idx; } } class Pair { int fr; int sc; public Pair(int fr, int sc) { this.fr = fr; this.sc = sc; } } class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); // read only string and breaks if finds a space String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } // read a complete line of string including spaces String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
8f4f02e3e60ba182bde716f5729ff148
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
/* || श्री राम समर्थ || || जय जय रघुवीर समर्थ || */ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.util.*; import static java.util.Arrays.compare; import static java.util.Arrays.sort; /* Think until you get Good idea And then Code Easily Try Hard And Pay Attention to details (be positive always possible) think smart */ public class CodeforcesTemp { static Reader scan = new Reader(); static FastPrinter out = new FastPrinter(); public static void main(String[] args) throws IOException { int tt = scan.nextInt(); // int tt = 1; for (int tc = 1; tc <= tt; tc++) { int n= scan.nextInt(); int q= scan.nextInt(); int[] arr= scan.nextIntArray(n); if (q > n) { String ans=getAns(n); out.println(ans); out.flush(); continue; } List<Integer> li=new ArrayList<>(); StringBuilder sb=new StringBuilder(); int res=0; for (int i = 0; i < n; i++) { if(arr[i]>q){ li.add(i); sb.append("0"); }else{ res++; sb.append("1"); } } if(li.size()==0){ String ans=getAns(n); out.println(ans); out.flush(); continue; } int l=0; int r=li.size()-1; String ans=sb.toString(); while (l<=r){ int mid=(l+r)/2; Pair curr_res=getRes(arr,li.get(mid),q); if(curr_res.count>res){ ans=curr_res.str; res=curr_res.count; } if(curr_res.remain_q>0){ r=mid-1; }else l=mid+1; } out.println(ans); out.flush(); } out.close(); } private static Pair getRes(int[] arr, int ind,int q) { StringBuilder sb=new StringBuilder(); int ans=0; int n=arr.length; int temp_q=q; for (int i = 0; i < n; i++) { if(arr[i]>temp_q && ind>i){ sb.append("0"); continue; } if(arr[i]<=temp_q){ sb.append("1"); ans++; } else{ if(temp_q==0){ sb.append("0"); } else{ temp_q--; sb.append("1"); ans++; } } } return new Pair(sb.toString(),ans,temp_q); } static class Pair{ String str; int count; int remain_q; Pair(String str,int count,int q){ this.str=str; this.count=count; this.remain_q=q; } } private static String getAns(int n) { StringBuilder sb=new StringBuilder(); for (int i = 0; i < n; i++) sb.append("1"); return sb.toString(); } static class Reader { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public Reader(InputStream in) { this.in = in; } public Reader() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } } throw new ArithmeticException( String.format(" overflows long.")); } n = n * 10 + digit; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(long length) { long[] array = new long[(int) length]; for (int i = 0; i < length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = this.nextInt(); return array; } public int[][] nextIntArrayMulti(int length, int width) { int[][] arrays = new int[width][length]; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) arrays[j][i] = this.nextInt(); } return arrays; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width) { long[][] mat = new long[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width) { int[][] mat = new int[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width) { double[][] mat = new double[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width) { char[][] mat = new char[height][width]; for (int h = 0; h < height; h++) { String s = this.next(); for (int w = 0; w < width; w++) { mat[h][w] = s.charAt(w); } } return mat; } } static class FastPrinter extends PrintWriter { public FastPrinter(PrintStream stream) { super(stream); } public FastPrinter() { super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if (x < 0) { sb.append('-'); x = -x; } x += Math.pow(10, -n) / 2; sb.append((long) x); sb.append("."); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; sb.append((int) x); x -= (int) x; } return sb.toString(); } @Override public void print(float f) { super.print(dtos(f, 20)); } @Override public void println(float f) { super.println(dtos(f, 20)); } @Override public void print(double d) { super.print(dtos(d, 20)); } @Override public void println(double d) { super.println(dtos(d, 20)); } public void printArray(int[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(int[] array) { this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n - 1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map) { this.printArray(array, " ", map); } public void printArray(long[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(long[] array) { this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n - 1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map) { this.printArray(array, " ", map); } public void printMatrix(int[][] arr) { for (int i = 0; i < arr.length; i++) { this.printArray(arr[i]); } } public void printCharMatrix(char[][] arr, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { this.print(arr[i][j] + " "); } this.println(); } } } static Random __r = new Random(); static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] arr, int i, int j) { while (i < j) { char temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(int[] arr, int i, int j) { while (i < j) { int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(long[] arr, int i, int j) { while (i < j) { long temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
8cf94aa82fbb32a9309c5b1fcf8fe497
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { 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 int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int t = in.nextInt(); while(t-- > 0) { int n = in.nextInt(); int q = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } int x = 0; StringBuilder ans = new StringBuilder(); int i = n - 1; // while (a[i] <= q && i > 0) { // ans.append('1'); // i--; // } for (; i >= 0; i--) { if (a[i] <= x) { ans.append('1'); } else { if (x + 1 <= q) { ans.append('1'); x++; } else { ans.append('0'); } } } System.out.println(ans.reverse()); } out.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
3edf8dace574a94b853065296cd19d7a
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
//Utilities import java.io.*; import java.util.*; public class a { static int t; static int n, q; static int[] a; static char[] res; public static void main(String[] args) throws IOException { t = in.iscan(); while (t-- > 0) { n = in.iscan(); q = in.iscan(); a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.iscan(); } int l = -1, r = n-1, mid; int split = n-1; while (l <= r) { mid = (l+r)/2; if (works(mid)) { split = mid; r = mid-1; } else { l = mid+1; } } res = new char[n]; for (int i = 0; i <= split; i++) { if (a[i] <= q) { res[i] = '1'; } else { res[i] = '0'; } } for (int i = split+1; i < n; i++) { res[i] = '1'; } out.println(res); } out.close(); } static boolean works(int split) { int tmp = q; for (int i = split+1; i < n; i++) { if (a[i] > tmp) { if (tmp > 0) tmp--; else return false; } } return true; } static INPUT in = new INPUT(System.in); static PrintWriter out = new PrintWriter(System.out); private static class INPUT { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar, numChars; public INPUT (InputStream stream) { this.stream = stream; } public INPUT (String file) throws IOException { this.stream = new FileInputStream (file); } public int cscan () throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read (buf); } if (numChars == -1) return numChars; return buf[curChar++]; } public int iscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } int res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public String sscan () throws IOException { int c = cscan (); while (space (c)) c = cscan (); StringBuilder res = new StringBuilder (); do { res.appendCodePoint (c); c = cscan (); } while (!space (c)); return res.toString (); } public double dscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } double res = 0; while (!space (c) && c != '.') { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); res *= 10; res += c - '0'; c = cscan (); } if (c == '.') { c = cscan (); double m = 1; while (!space (c)) { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); m /= 10; res += (c - '0') * m; c = cscan (); } } return res * sgn; } public long lscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } long res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public boolean space (int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } public static class UTILITIES { static final double EPS = 10e-6; public static void sort(int[] a, boolean increasing) { ArrayList<Integer> arr = new ArrayList<Integer>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(long[] a, boolean increasing) { ArrayList<Long> arr = new ArrayList<Long>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(double[] a, boolean increasing) { ArrayList<Double> arr = new ArrayList<Double>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static int lower_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } public static void updateMap(HashMap<Integer, Integer> map, int key, int v) { if (!map.containsKey(key)) { map.put(key, v); } else { map.put(key, map.get(key) + v); } if (map.get(key) == 0) { map.remove(key); } } public static long gcd (long a, long b) { return b == 0 ? a : gcd (b, a % b); } public static long lcm (long a, long b) { return a * b / gcd (a, b); } public static long fast_pow_mod (long b, long x, int mod) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod; return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod; } public static long fast_pow (long b, long x) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow (b * b, x / 2); return b * fast_pow (b * b, x / 2); } public static long choose (long n, long k) { k = Math.min (k, n - k); long val = 1; for (int i = 0; i < k; ++i) val = val * (n - i) / (i + 1); return val; } public static long permute (int n, int k) { if (n < k) return 0; long val = 1; for (int i = 0; i < k; ++i) val = (val * (n - i)); return val; } // start of permutation and lower/upper bound template public static void nextPermutation(int[] nums) { //find first decreasing digit int mark = -1; for (int i = nums.length - 1; i > 0; i--) { if (nums[i] > nums[i - 1]) { mark = i - 1; break; } } if (mark == -1) { reverse(nums, 0, nums.length - 1); return; } int idx = nums.length-1; for (int i = nums.length-1; i >= mark+1; i--) { if (nums[i] > nums[mark]) { idx = i; break; } } swap(nums, mark, idx); reverse(nums, mark + 1, nums.length - 1); } public static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } public static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i, j); i++; j--; } } static int lower_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= cmp) high = mid; else low = mid + 1; } return low; } static int upper_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > cmp) high = mid; else low = mid + 1; } return low; } // end of permutation and lower/upper bound template } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
9bb228b17edd352ad88667904f7432da
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class Main { static BufferedReader bf; static PrintWriter out; static Scanner sc; static StringTokenizer st; static long mod = (long)(1e9+7); static long mod2 = 998244353; static long fact[] = new long[1000001]; static long inverse[] = new long[1000001]; public static void main (String[] args)throws IOException { bf = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new Scanner(System.in); // fact[0] = 1; // inverse[0] = 1; // for(int i = 1;i<fact.length;i++){ // fact[i] = (fact[i-1] * i)%mod; // // inverse[i] = binaryExpo(fact[i], mod-2); // } int t = nextInt(); while(t-->0){ solve(); } } public static void solve() throws IOException{ int n = nextInt(); int q = nextInt(); int[]arr = new int[n]; List<Integer>list = new ArrayList<>(); for(int i = 0;i<n;i++){ arr[i] = nextInt(); if(arr[i] > q){ list.add(i); } } int ans = n+1; int l = 0; int r = list.size()-1; while(l <= r){ int mid = l + (r-l)/2; int k = q; for(int i = list.get(mid);i<n;i++){ if(arr[i] > k){ k--; } } if(k >= 0){ ans = list.get(mid); r = mid-1; } else{ l = mid+1; } } StringBuilder sb = new StringBuilder(); // println(ans); for(int i = 0;i<n;i++){ if(i < ans){ if(arr[i] > q){ sb.append('0'); } else{ sb.append('1'); } } else{ sb.append('1'); } } println(sb.toString()); } public static long help(long[][]dp,List<List<Integer>>list,long[]mid,int cur,int parent,long des[][]){ List<Integer>temp = list.get(cur); long nonTake = 0; long take = 0; for(int i = 0;i<temp.size();i++){ int next = temp.get(i); if(next != parent){ help(dp,list,mid,next,cur,des); nonTake += Math.min(dp[next][0] + Math.abs(des[cur][1] - des[next][1]) , dp[next][1] + Math.abs(mid[next] - des[cur][1])); take += dp[next][0] + Math.abs(mid[cur] - des[next][1]); } } dp[cur][1] = take; dp[cur][0] = nonTake; // println(take + " " + nonTake + " " + cur); return Math.min(dp[cur][1],dp[cur][0]); } public static long nck(int n,int k){ return fact[n] * inverse[n-k] %mod * inverse[k]%mod; } public static void plus(int node,int low,int high,int tlow,int thigh,int[]tree){ if(low >= tlow && high <= thigh){ tree[node]++; return; } if(high < tlow || low > thigh)return; int mid = (low + high)/2; plus(node*2,low,mid,tlow,thigh,tree); plus(node*2 + 1 , mid + 1, high,tlow, thigh,tree); } public static boolean allEqual(int[]arr,int x){ for(int i = 0;i<arr.length;i++){ if(arr[i] != x)return false; } return true; } public static long helper(StringBuilder sb){ return Long.parseLong(sb.toString()); } public static int min(int node,int low,int high,int tlow,int thigh,int[][]tree){ if(low >= tlow&& high <= thigh)return tree[node][0]; if(high < tlow || low > thigh)return Integer.MAX_VALUE; int mid = (low + high)/2; // println(low+" "+high+" "+tlow+" "+thigh); return Math.min(min(node*2,low,mid,tlow,thigh,tree) ,min(node*2+1,mid+1,high,tlow,thigh,tree)); } public static int max(int node,int low,int high,int tlow,int thigh,int[][]tree){ if(low >= tlow && high <= thigh)return tree[node][1]; if(high < tlow || low > thigh)return Integer.MIN_VALUE; int mid = (low + high)/2; return Math.max(max(node*2,low,mid,tlow,thigh,tree) ,max(node*2+1,mid+1,high,tlow,thigh,tree)); } public static long[] help(List<List<Integer>>list,int[][]range,int cur){ List<Integer>temp = list.get(cur); if(temp.size() == 0)return new long[]{range[cur][1],1}; long sum = 0; long count = 0; for(int i = 0;i<temp.size();i++){ long []arr = help(list,range,temp.get(i)); sum += arr[0]; count += arr[1]; } if(sum < range[cur][0]){ count++; sum = range[cur][1]; } return new long[]{sum,count}; } public static long findSum(int node,int low, int high,int tlow,int thigh,long[]tree,long mod){ if(low >= tlow && high <= thigh)return tree[node]%mod; if(low > thigh || high < tlow)return 0; int mid = (low + high)/2; return((findSum(node*2,low,mid,tlow,thigh,tree,mod) % mod) + (findSum(node*2+1,mid+1,high,tlow,thigh,tree,mod)))%mod; } public static boolean allzero(long[]arr){ for(int i =0 ;i<arr.length;i++){ if(arr[i]!=0)return false; } return true; } public static long count(long[][]dp,int i,int[]arr,int drank,long sum){ if(i == arr.length)return 0; if(dp[i][drank]!=-1 && arr[i]+sum >=0)return dp[i][drank]; if(sum + arr[i] >= 0){ long count1 = 1 + count(dp,i+1,arr,drank+1,sum+arr[i]); long count2 = count(dp,i+1,arr,drank,sum); return dp[i][drank] = Math.max(count1,count2); } return dp[i][drank] = count(dp,i+1,arr,drank,sum); } public static void help(int[]arr,char[]signs,int l,int r){ if( l < r){ int mid = (l+r)/2; help(arr,signs,l,mid); help(arr,signs,mid+1,r); merge(arr,signs,l,mid,r); } } public static void merge(int[]arr,char[]signs,int l,int mid,int r){ int n1 = mid - l + 1; int n2 = r - mid; int[]a = new int[n1]; int []b = new int[n2]; char[]asigns = new char[n1]; char[]bsigns = new char[n2]; for(int i = 0;i<n1;i++){ a[i] = arr[i+l]; asigns[i] = signs[i+l]; } for(int i = 0;i<n2;i++){ b[i] = arr[i+mid+1]; bsigns[i] = signs[i+mid+1]; } int i = 0; int j = 0; int k = l; boolean opp = false; while(i<n1 && j<n2){ if(a[i] <= b[j]){ arr[k] = a[i]; if(opp){ if(asigns[i] == 'R'){ signs[k] = 'L'; } else{ signs[k] = 'R'; } } else{ signs[k] = asigns[i]; } i++; k++; } else{ arr[k] = b[j]; int times = n1 - i; if(times%2 == 1){ if(bsigns[j] == 'R'){ signs[k] = 'L'; } else{ signs[k] = 'R'; } } else{ signs[k] = bsigns[j]; } j++; opp = !opp; k++; } } while(i<n1){ arr[k] = a[i]; if(opp){ if(asigns[i] == 'R'){ signs[k] = 'L'; } else{ signs[k] = 'R'; } } else{ signs[k] = asigns[i]; } i++; k++; } while(j<n2){ arr[k] = b[j]; signs[k] = bsigns[j]; j++; k++; } } public static long binaryExpo(long base,long expo){ if(expo == 0)return 1; long val; if(expo%2 == 1){ val = (binaryExpo(base, expo-1)*base)%mod; } else{ val = binaryExpo(base, expo/2); val = (val*val)%mod; } return (val%mod); } public static boolean isSorted(int[]arr){ for(int i =1;i<arr.length;i++){ if(arr[i] < arr[i-1]){ return false; } } return true; } //function to find the topological sort of the a DAG public static boolean hasCycle(int[]indegree,List<List<Integer>>list,int n,List<Integer>topo){ Queue<Integer>q = new LinkedList<>(); for(int i =1;i<indegree.length;i++){ if(indegree[i] == 0){ q.add(i); topo.add(i); } } while(!q.isEmpty()){ int cur = q.poll(); List<Integer>l = list.get(cur); for(int i = 0;i<l.size();i++){ indegree[l.get(i)]--; if(indegree[l.get(i)] == 0){ q.add(l.get(i)); topo.add(l.get(i)); } } } if(topo.size() == n)return false; return true; } // function to find the parent of any given node with path compression in DSU public static int find(int val,int[]parent){ if(val == parent[val])return val; return parent[val] = find(parent[val],parent); } // function to connect two components public static void union(int[]rank,int[]parent,int u,int v){ int a = find(u,parent); int b= find(v,parent); if(a == b)return; if(rank[a] == rank[b]){ parent[b] = a; rank[a]++; } else{ if(rank[a] > rank[b]){ parent[b] = a; } else{ parent[a] = b; } } } // public static int findN(int n){ int num = 1; while(num < n){ num *=2; } return num; } // code for input public static void print(String s ){ System.out.print(s); } public static void print(int num ){ System.out.print(num); } public static void print(long num ){ System.out.print(num); } public static void println(String s){ System.out.println(s); } public static void println(int num){ System.out.println(num); } public static void println(long num){ System.out.println(num); } public static void println(){ System.out.println(); } public static int Int(String s){ return Integer.parseInt(s); } public static long Long(String s){ return Long.parseLong(s); } public static String[] nextStringArray()throws IOException{ return bf.readLine().split(" "); } public static String nextString()throws IOException{ return bf.readLine(); } public static long[] nextLongArray(int n)throws IOException{ String[]str = bf.readLine().split(" "); long[]arr = new long[n]; for(int i =0;i<n;i++){ arr[i] = Long.parseLong(str[i]); } return arr; } public static int[][] newIntMatrix(int r,int c)throws IOException{ int[][]arr = new int[r][c]; for(int i =0;i<r;i++){ String[]str = bf.readLine().split(" "); for(int j =0;j<c;j++){ arr[i][j] = Integer.parseInt(str[j]); } } return arr; } public static long[][] newLongMatrix(int r,int c)throws IOException{ long[][]arr = new long[r][c]; for(int i =0;i<r;i++){ String[]str = bf.readLine().split(" "); for(int j =0;j<c;j++){ arr[i][j] = Long.parseLong(str[j]); } } return arr; } static class pair{ int one; int two; pair(int one,int two){ this.one = one ; this.two =two; } } public static long gcd(long a,long b){ if(b == 0)return a; return gcd(b,a%b); } public static long lcm(long a,long b){ return (a*b)/(gcd(a,b)); } public static boolean isPalindrome(String s){ int i = 0; int j = s.length()-1; while(i<=j){ if(s.charAt(i) != s.charAt(j)){ return false; } i++; j--; } return true; } // these functions are to calculate the number of smaller elements after self public static void sort(int[]arr,int l,int r){ if(l < r){ int mid = (l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); smallerNumberAfterSelf(arr, l, mid, r); } } public static void smallerNumberAfterSelf(int[]arr,int l,int mid,int r){ int n1 = mid - l +1; int n2 = r - mid; int []a = new int[n1]; int[]b = new int[n2]; for(int i = 0;i<n1;i++){ a[i] = arr[l+i]; } for(int i =0;i<n2;i++){ b[i] = arr[mid+i+1]; } int i = 0; int j =0; int k = l; while(i<n1 && j < n2){ if(a[i] < b[j]){ arr[k++] = a[i++]; } else{ arr[k++] = b[j++]; } } while(i<n1){ arr[k++] = a[i++]; } while(j<n2){ arr[k++] = b[j++]; } } public static String next(){ while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bf.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 = bf.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // use some math tricks it might help // sometimes just try to think in straightforward plan in A and B problems don't always complecate the questions with thinking too much differently // always use long number to do 10^9+7 modulo // if a problem is related to binary string it could also be related to parenthesis // *****try to use binary search(it is a very beautiful thing it can work in some of the very unexpected problems ) in the question it might work****** // try sorting // try to think in opposite direction of question it might work in your way // if a problem is related to maths try to relate some of the continuous subarray with variables like - > a+b+c+d or a,b,c,d in general // if the question is to much related to left and/or right side of any element in an array then try monotonic stack it could work. // in range query sums try to do binary search it could work // analyse the time complexity of program thoroughly // anylyse the test cases properly // if we divide any number by 2 till it gets 1 then there will be (number - 1) operation required // try to do the opposite operation of what is given in the problem //think about the base cases properly //If a question is related to numbers try prime factorisation or something related to number theory // keep in mind unique strings //you can calculate the number of inversion in O(n log n) // in a matrix you could sometimes think about row and cols indenpendentaly. // Try to think in more constructive(means a way to look through various cases of a problem) way. // observe the problem carefully the answer could be hidden in the given test cases itself. (A, B , C); // when we have equations like (a+b = N) and we have to find the max of (a*b) then the values near to the N/2 must be chosen as (a and b); // give emphasis to the number of occurences of elements it might help. // if a number is even then we can find the pair for each and every number in that range whose bitwise AND is zero. // if a you find a problem related to the graph make a graph
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
1202c7fe1e77a2d1a333885cd33cb728
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(st==null || !st.hasMoreTokens()) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { 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(); } } public static void main(String[] args) { try { FastReader sc = new FastReader(); FastWriter out = new FastWriter(); int t = sc.nextInt(); while(t -- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] ar = new int[n]; for(int i=0; i<n; i++) { ar[i] = sc.nextInt(); } char[] ans = new char[n]; int q1 = 0; for(int i=n-1; i>=0; i--) { if(q1<q) { ans[i] = '1'; if(q1<ar[i]) q1++; } else if(q1>=ar[i]) { ans[i] = '1'; } else { ans[i] = '0'; } } out.println(String.valueOf(ans)); } out.close(); } catch (Exception ignored) { } } static void printArray(int[] ar) { for (int j : ar) { System.out.println(j); } //System.out.println(); } static void reverseArray(int[] ar, int l, int h) { int m = (l+h)/2; while(l<=m) { int temp = ar[l]; ar[l] = ar[h]; ar[h] = temp; l++; h--; } } static void printA(int[][] ar, int n) { for(int i=0; i<n; i++) { for(int j=0 ;j<n; j++) { System.out.print(ar[i][j]+" "); } System.out.println(); } } static void SieveOfEratosthenes(int n, boolean[] prime, boolean[] primeSquare, int[] a) { for (int i = 2; i <= n; i++) prime[i] = true; for (int i = 0; i < ((n * n) + 1); i++) primeSquare[i] = false; prime[1] = false; for (int p = 2; p * p <= n; p++) { if (prime[p]) { for (int i = p * 2; i <= n; i += p) prime[i] = false; } } int j = 0; for (int p = 2; p <= n; p++) { if (prime[p]) { a[j] = p; primeSquare[p * p] = true; j++; } } } static int countDivisors(int n) { if (n == 1) return 1; boolean[] prime = new boolean[n + 1]; boolean[] primeSquare = new boolean[(n * n) + 1]; int[] a = new int[n]; SieveOfEratosthenes(n, prime, primeSquare, a); int ans = 1; for (int i = 0;; i++) { if (a[i] * a[i] * a[i] > n) break; int cnt = 1; while (n % a[i] == 0) { n = n / a[i]; cnt = cnt + 1; } ans = ans * cnt; } if (prime[n]) ans = ans * 2; else if (primeSquare[n]) ans = ans * 3; else if (n != 1) ans = ans * 4; return ans; } static int mostFrequent(int arr[], int n) { // Insert all elements in hash Map<Integer, Integer> hp = new HashMap<Integer, Integer>(); for(int i = 0; i < n; i++) { int key = arr[i]; if(hp.containsKey(key)) { int freq = hp.get(key); freq++; hp.put(key, freq); } else { hp.put(key, 1); } } // find max frequency. int max_count = 0, res = -1; for(Map.Entry<Integer, Integer> val : hp.entrySet()) { if (max_count < val.getValue()) { res = val.getKey(); max_count = val.getValue(); } } return hp.get(res); } } class pair implements Comparable<pair> { int value; int idx; // Constructor pair(int value, int idx) { this.value = value; this.idx = idx; } // overriding method to sort // the student data public int compareTo(pair sd) { return this.value - sd.value; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
0f5619983ace9e4a4a3533f6665c4b18
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class C { static class Pair { int f; int s; // Pair() { } Pair(int f, int s) { this.f = f; this.s = s; } } static class sortbyfirst implements Comparator<Pair> { public int compare(Pair a, Pair b) { return a.f - b.f; } } static class Fast { BufferedReader br; StringTokenizer st; public Fast() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArray1(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (IOException e) { e.printStackTrace(); } return str; } } /* static long noOfDivisor(long a) { long count=0; long t=a; for(long i=1;i<=(int)Math.sqrt(a);i++) { if(a%i==0) count+=2; } if(a==((long)Math.sqrt(a)*(long)Math.sqrt(a))) { count--; } return count; }*/ static boolean isPrime(long a) { for (long i = 2; i <= (long) Math.sqrt(a); i++) { if (a % i == 0) return false; } return true; } static void primeFact(int n) { int temp = n; HashMap<Integer, Integer> h = new HashMap<>(); for (int i = 2; i * i <= n; i++) { if (temp % i == 0) { int c = 0; while (temp % i == 0) { c++; temp /= i; } h.put(i, c); } } if (temp != 1) h.put(temp, 1); } static void reverseArray(int a[]) { int n = a.length; for (int i = 0; i < n / 2; i++) { a[i] = a[i] ^ a[n - i - 1]; a[n - i - 1] = a[i] ^ a[n - i - 1]; a[i] = a[i] ^ a[n - i - 1]; } } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int a, int b) { return a > b ? a : b; } static int min(int a, int b) { return a < b ? a : b; } static boolean check(int a[],int id,int q) { int n=a.length;int q1=q; for(int i=id;i<n;i++) { if(a[i]>q1) { q1--; } else continue; } if(q1>=0) return true; return false; } public static void main(String args[]) throws IOException { Fast sc = new Fast(); PrintWriter out = new PrintWriter(System.out); int t1 = sc.nextInt(); while (t1-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int a[] = sc.readArray(n); // StringBuffer ans = new StringBuffer(); ArrayList<Integer> good=new ArrayList<>(); ArrayList<Integer> bad=new ArrayList<>(); for(int i=0;i<n;i++) { if(a[i]>q) bad.add(i); else good.add(i); } int low=0;int high=bad.size()-1; // out.println(high); while(low<=high) { int mid =(low+high)>>1; /// out.println(low+" "+high+" "+mid); int id=bad.get(mid); if(check(a,id,q)) high=mid-1; else low=mid+1; } if(low>=bad.size()) { for(int i=0;i<n;i++) { if(a[i]<=q) out.print('1'); else out.print('0'); } } else { int mark=bad.get(low); for(int i=0;i<mark;i++) { if(a[i]<=q) out.print('1'); else out.print('0'); } for(int i=mark;i<n;i++) out.print('1'); } out.println(); } out.close(); } } /* public static void main(String args[]) throws IOException { Fast sc = new Fast(); PrintWriter out = new PrintWriter(System.out); int t1 = sc.nextInt(); while (t1-- > 0) { int n=sc.nextInt();int q=sc.nextInt(); int a[]=sc.readArray(n); StringBuffer ans=new StringBuffer(); int q1=q; int suf[]=new int[n+1]; int pos[]=new int[n+1]; for(int i=0;i<n;i++) pos[a[i]]=i; for(int i=0;i<n;i++) { if(a[i]>q) { if(i!=n-1&&q-1>=n-i-1) { q--; ans.append('1'); } else if(i==n-1&&q>0) { q--; ans.append('1'); } else ans.append('0'); } else { ans.append('1'); } } suf[n]=0; for(int i=n-1;i>=0;i--) { if(ans.charAt(i)=='1') { suf[i] =a[i]; break; } else suf[i]=0; } for(int i=n-2;i>=0;i--) { if(ans.charAt(i)=='1') suf[i]=max(suf[i+1],a[i]); else suf[i]=suf[i+1]; } for(int i=0;i<n&&q>0;i++) { if(ans.charAt(i)=='0') { if(q-1>=suf[i+1]||q-1>=suf[pos[suf[i+1]]+1]) { ans.replace(i, i + 1, "1"); q--; } } } out.println(ans); } out.close(); } }*/ /* 1 8 3 4 1 2 5 3 6 7 8 6 7 8 4 1 3 5 2 */
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
4ac477131e541a31bdd6289f02f0c56f
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; public class CF808 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int q = sc.nextInt(); int q1 = 0; int[] a = new int[n]; for(int i =0 ; i<n;i++) { a[i] = sc.nextInt(); } int[] b = new int[n]; for(int i = n-1;i>=0;i--) { if(a[i]<=q1) { b[i] = 1; } else { if(q1<q) { b[i] = 1; q1++; } } } for(int bb:b) { System.out.print(bb); } System.out.println(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
ce5156cfec9b102fcba262ba04f8d04f
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
// package c1708; // // Codeforces Round #808 (Div. 2) 2022-07-16 07:35 // C. Doremy's IQ // https://codeforces.com/contest/1708/problem/C // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // Doremy is asked to test n contests. Contest i can only be tested on day i. The difficulty of // contest i is a_i. Initially, Doremy's IQ is q. On day i Doremy will choose whether to test // contest i or not. She can only test a contest if her current IQ is strictly greater than 0. // // If Doremy chooses to test contest i on day i, the following happens: // * if a_i>q, Doremy will feel she is not wise enough, so q decreases by 1; // * otherwise, nothing changes. If she chooses not to test a contest, nothing changes. // // Doremy wants to test as many contests as possible. Please give Doremy a solution. // // Input // // The input consists of multiple test cases. The first line contains a single integer t (1<= t<= // 10^4)-- the number of test cases. The description of the test cases follows. // // The first line contains two integers n and q (1 <= n <= 10^5, 1 <= q <= 10^9)-- the number of // contests and Doremy's IQ in the beginning. // // The second line contains n integers a_1,a_2,*s,a_n (1 <= a_i <= 10^9)-- the difficulty of each // contest. // // It is guaranteed that the sum of n over all test cases does not exceed 10^5. // // Output // // For each test case, you need to output a binary string s, where s_i=1 if Doremy should choose to // test contest i, and s_i=0 otherwise. The number of ones in the string should be maximum possible, // and she should never test a contest when her IQ is zero or less. // // If there are multiple solutions, you may output any. // // Example /* input: 5 1 1 1 2 1 1 2 3 1 1 2 1 4 2 1 4 3 1 5 2 5 1 2 4 3 output: 1 11 110 1110 01111 */ // Note // // In the first test case, Doremy tests the only contest. Her IQ doesn't decrease. // // In the second test case, Doremy tests both contests. Her IQ decreases by 1 after testing contest // 2. // // In the third test case, Doremy tests contest 1 and 2. Her IQ decreases to 0 after testing contest // 2, so she can't test contest 3. // import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Random; import java.util.StringTokenizer; import java.util.TreeMap; public class C1708C { static final int MOD = 998244353; static final Random RAND = new Random(); static char[] solve(int[] a, int q) { int n = a.length; char[] ans = new char[n]; Arrays.fill(ans, '1'); if (q >= n) { return ans; } // Imagine we gradually build map from q to number of tests in backward. // We started with (0,0), and traverse consider test in reverse order. // For example: 5 1 2 4 3 // i a[i] map maxp // 5 3 (0,0) (1,1) 1 // 4 4 (0,0) (1,1) (2,2) 2 // 3 2 (0,0) (1,1) (2,2) (3,3) 3 // 2 1 (0,0) (1,1) (2,3) (3,4) 3 // 1 5 (0,0) (1,2) (2,4) (3,5) 3 // We trace the largest p needed so far as maxp // If a[i] >= maxp + 1, we add (maxp, 1) // otherwise, we increase all entries with key >= a[i] by 1. // Such operation can be achieved with LazyRangeSegmentTree st, // and the final count with start q is st.getAt(q). // However we ONLY need find all the contributors to st[q] which can be easily tracked. int maxp = 0; for (int i = n - 1; i >= 0; i--) { int v = Math.min(a[i], maxp + 1); ans[i] = v <= q ? '1' : '0'; maxp = Math.max(v, maxp); } return ans; } // A few explorations NOT end up to be a valid solution. static char[] incubation(int[] a, int q) { int n = a.length; char[] ans = new char[n]; Arrays.fill(ans, '1'); if (q >= n) { return ans; } { // suf[i] is the minimal q at i to take all tests in [i,n) int[] suf = new int[n + 1]; suf[n] = 0; for (int i = n - 1; i >= 0; i--) { suf[i] = (a[i] <= suf[i+1]) ? suf[i+1] : 1 + suf[i+1]; } System.out.format(" suf:%s\n", Arrays.toString(suf)); } TreeMap<Integer, List<Integer>> dim = new TreeMap<>(); TreeMap<Integer, Integer> dcm = new TreeMap<>(); for (int i = 0; i < n; i++) { int d = Math.min(n, a[i]); dim.computeIfAbsent(d, x -> new ArrayList<>()).add(i); dcm.put(d, dcm.getOrDefault(d, 0) + 1); } // precm[d] is count of test with difficulty <= d TreeMap<Integer, Integer> prem = new TreeMap<>(); prem.put(0, 0); int precnt = 0; for (Map.Entry<Integer, Integer> e : dcm.entrySet()) { precnt += e.getValue(); prem.put(e.getKey(), precnt); } // System.out.format(" prem:%s\n", Utils.traceMap(prem)); int maxc = -1; int maxk = -1; int extra = -1; for (int k = 0; k <= q; k++) { // Number of tests taken without decreasing q int pre = prem.floorEntry(k).getValue(); // Number of tests taken with q decrease int suf = Math.min(q, n - pre); int count = pre + suf; if (count > maxc) { maxc = count; maxk = k; extra = suf; } } System.out.format(" maxc:%d maxk:%d extra:%d\n", maxc, maxk, extra); for (int i = n - 1; i >= 0; i--) { System.out.format(" i:%d a[i]:%d extra:%d\n", i, a[i], extra); if (a[i] > maxk) { ans[i] = extra > 0 ? '1' : '0'; extra--; } else { ans[i] = '1'; } } return ans; } static boolean test = false; static void doTest() { if (!test) { return; } long t0 = System.currentTimeMillis(); System.out.format("%d msec\n", System.currentTimeMillis() - t0); System.exit(0); } public static void main(String[] args) { doTest(); MyScanner in = new MyScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); int q = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } char[] ans = solve(a, q); System.out.println(new String(ans)); } } static void output(int[] a) { if (a == null) { System.out.println("-1"); return; } StringBuilder sb = new StringBuilder(); for (int v : a) { sb.append(v); sb.append(' '); if (sb.length() > 500) { System.out.print(sb.toString()); sb.setLength(0); } } System.out.println(sb.toString()); } static void myAssert(boolean cond) { if (!cond) { throw new RuntimeException("Unexpected"); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { try { final String USERDIR = System.getProperty("user.dir"); String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", ""); cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname; final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in"); br = new BufferedReader(new InputStreamReader(fin.exists() ? new FileInputStream(fin) : System.in)); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } catch (Exception e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
6236e58f3c096067448891a33d4e5959
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
// package c1708; // // Codeforces Round #808 (Div. 2) 2022-07-16 07:35 // C. Doremy's IQ // https://codeforces.com/contest/1708/problem/C // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // Doremy is asked to test n contests. Contest i can only be tested on day i. The difficulty of // contest i is a_i. Initially, Doremy's IQ is q. On day i Doremy will choose whether to test // contest i or not. She can only test a contest if her current IQ is strictly greater than 0. // // If Doremy chooses to test contest i on day i, the following happens: // * if a_i>q, Doremy will feel she is not wise enough, so q decreases by 1; // * otherwise, nothing changes. If she chooses not to test a contest, nothing changes. // // Doremy wants to test as many contests as possible. Please give Doremy a solution. // // Input // // The input consists of multiple test cases. The first line contains a single integer t (1<= t<= // 10^4)-- the number of test cases. The description of the test cases follows. // // The first line contains two integers n and q (1 <= n <= 10^5, 1 <= q <= 10^9)-- the number of // contests and Doremy's IQ in the beginning. // // The second line contains n integers a_1,a_2,*s,a_n (1 <= a_i <= 10^9)-- the difficulty of each // contest. // // It is guaranteed that the sum of n over all test cases does not exceed 10^5. // // Output // // For each test case, you need to output a binary string s, where s_i=1 if Doremy should choose to // test contest i, and s_i=0 otherwise. The number of ones in the string should be maximum possible, // and she should never test a contest when her IQ is zero or less. // // If there are multiple solutions, you may output any. // // Example /* input: 5 1 1 1 2 1 1 2 3 1 1 2 1 4 2 1 4 3 1 5 2 5 1 2 4 3 output: 1 11 110 1110 01111 */ // Note // // In the first test case, Doremy tests the only contest. Her IQ doesn't decrease. // // In the second test case, Doremy tests both contests. Her IQ decreases by 1 after testing contest // 2. // // In the third test case, Doremy tests contest 1 and 2. Her IQ decreases to 0 after testing contest // 2, so she can't test contest 3. // import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Random; import java.util.StringTokenizer; import java.util.TreeMap; public class C1708C { static final int MOD = 998244353; static final Random RAND = new Random(); static char[] solve(int[] a, int q) { int n = a.length; char[] ans = new char[n]; Arrays.fill(ans, '1'); if (q >= n) { return ans; } LazyRangeSumSegmentTree st = new LazyRangeSumSegmentTree(new int[n + 1]); int maxvp = 0; for (int i = n - 1; i >= 0; i--) { int v = Math.min(a[i], maxvp + 1); ans[i] = v <= q ? '1' : '0'; st.updateRange(v, n, 1); maxvp = Math.max(v, maxvp); } int maxc = st.getAt(q); // System.out.format("maxc:%d\n", maxc); return ans; } static class LazyRangeSumSegmentTree { int n; int tree[]; int lazy[]; LazyRangeSumSegmentTree(int[] arr) { this.n = arr.length; int m = nextPowerOf2(n); this.tree = new int[m * 2 - 1]; this.lazy = new int[m * 2 - 1]; constructSegTree(arr, 0, n - 1, 0); } void constructSegTree(int arr[], int lo, int hi, int idx) { if (lo > hi) { return; } if (lo == hi) { tree[idx] = arr[lo]; return; } int mid = (lo + hi) / 2; constructSegTree(arr, lo, mid, idx * 2 + 1); constructSegTree(arr, mid + 1, hi, idx * 2 + 2); tree[idx] = tree[idx * 2 + 1] + tree[idx * 2 + 2]; } // Update by adding inc to all values in [b, e] public void updateRange(int b, int e, int inc) { if (b > e) { return; } updateRangeInner(0, 0, n - 1, b, e, inc); } // Set value at a specific index. public void set(int index, int value) { checkIndex(index); int vcurr = getRangeSum(index, index); int inc = value - vcurr; updateRange(index, index, inc); } // Gets value at the specific index public int getAt(int index) { checkIndex(index); return getRangeSum(0, 0, n - 1, index, index); } // Get sum in range [b, e] public int getRangeSum(int b, int e) { if (b < 0 || e > n - 1 || b > e) { return 0; } return getRangeSum(0, 0, n - 1, b, e); } private void checkIndex(int index) { if (index < 0 || index >= n) { throw new RuntimeException("Invalid index " + index); } } private void updateRangeInner(int idx, int lo, int hi, int b, int e, int inc) { applyLazy(idx, lo, hi); if (lo > hi || lo > e || hi < b) { return; } if (lo >= b && hi <= e) { tree[idx] += inc * (hi - lo + 1); if (lo != hi) { lazy[idx * 2 + 1] += inc; lazy[idx * 2 + 2] += inc; } return; } int mid = (lo + hi) / 2; updateRangeInner(idx * 2 + 1, lo, mid, b, e, inc); updateRangeInner(idx * 2 + 2, mid + 1, hi, b, e, inc); tree[idx] = tree[idx * 2 + 1] + tree[idx * 2 + 2]; } private int getRangeSum(int idx, int lo, int hi, int b, int e) { applyLazy(idx, lo, hi); if (lo > hi || lo > e || hi < b) { return 0; } if (lo >= b && hi <= e) { return tree[idx]; } int mid = (lo + hi) / 2; return getRangeSum(2 * idx + 1, lo, mid, b, e) + getRangeSum(2 * idx + 2, mid + 1, hi, b, e); } private void applyLazy(int idx, int lo, int hi) { if (lazy[idx] != 0) { tree[idx] += lazy[idx] * (hi - lo + 1); if (lo != hi) { lazy[idx * 2 + 1] += lazy[idx]; lazy[idx * 2 + 2] += lazy[idx]; } lazy[idx] = 0; } } public static int nextPowerOf2(int num){ if (num == 0) { return 1; } if (num > 0 && (num & (num-1)) == 0) { return num; } while ((num & (num-1)) > 0) { num = num & (num - 1); } return num << 1; } } static char[] solveB(int[] a, int q) { int n = a.length; char[] ans = new char[n]; Arrays.fill(ans, '1'); if (q >= n) { return ans; } { // suf[i] is the minimal q at i to take all tests in [i,n) int[] suf = new int[n + 1]; suf[n] = 0; for (int i = n - 1; i >= 0; i--) { suf[i] = (a[i] <= suf[i+1]) ? suf[i+1] : 1 + suf[i+1]; } System.out.format(" suf:%s\n", Arrays.toString(suf)); } TreeMap<Integer, List<Integer>> dim = new TreeMap<>(); TreeMap<Integer, Integer> dcm = new TreeMap<>(); for (int i = 0; i < n; i++) { int d = Math.min(n, a[i]); dim.computeIfAbsent(d, x -> new ArrayList<>()).add(i); dcm.put(d, dcm.getOrDefault(d, 0) + 1); } // precm[d] is count of test with difficulty <= d TreeMap<Integer, Integer> prem = new TreeMap<>(); prem.put(0, 0); int precnt = 0; for (Map.Entry<Integer, Integer> e : dcm.entrySet()) { precnt += e.getValue(); prem.put(e.getKey(), precnt); } // System.out.format(" prem:%s\n", Utils.traceMap(prem)); int maxc = -1; int maxk = -1; int extra = -1; for (int k = 0; k <= q; k++) { // Number of tests taken without decreasing q int pre = prem.floorEntry(k).getValue(); // Number of tests taken with q decrease int suf = Math.min(q, n - pre); int count = pre + suf; if (count > maxc) { maxc = count; maxk = k; extra = suf; } } System.out.format(" maxc:%d maxk:%d extra:%d\n", maxc, maxk, extra); for (int i = n - 1; i >= 0; i--) { System.out.format(" i:%d a[i]:%d extra:%d\n", i, a[i], extra); if (a[i] > maxk) { ans[i] = extra > 0 ? '1' : '0'; extra--; } else { ans[i] = '1'; } } return ans; } static boolean test = false; static void doTest() { if (!test) { return; } long t0 = System.currentTimeMillis(); System.out.format("%d msec\n", System.currentTimeMillis() - t0); System.exit(0); } public static void main(String[] args) { doTest(); MyScanner in = new MyScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); int q = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } char[] ans = solve(a, q); System.out.println(new String(ans)); } } static void output(int[] a) { if (a == null) { System.out.println("-1"); return; } StringBuilder sb = new StringBuilder(); for (int v : a) { sb.append(v); sb.append(' '); if (sb.length() > 500) { System.out.print(sb.toString()); sb.setLength(0); } } System.out.println(sb.toString()); } static void myAssert(boolean cond) { if (!cond) { throw new RuntimeException("Unexpected"); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { try { final String USERDIR = System.getProperty("user.dir"); String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", ""); cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname; final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in"); br = new BufferedReader(new InputStreamReader(fin.exists() ? new FileInputStream(fin) : System.in)); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } catch (Exception e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
30f621a9bb157fce26d891b8e6fed777
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.System.mapLibraryName; import static java.lang.System.out; public class C { public static void println(Object o) { System.out.println(o); } public static void print(Object o) { System.out.print(o); } static final int mod = 1_000_000_007; // Pair<Integer, Integer> pair=new Pair<>(); // Map<Integer, Integer> map=new HashMap<>(); // Set<Integer> set=new HashSet<>(); // ArrayList<Integer> ls=new ArrayList<>(); public static void main(String[] args) { FScanner sc = new FScanner(); PrintWriter out = new PrintWriter(System.out); int T = sc.nextInt(); // int T=1; while (T-- > 0) { int n = sc.nextInt(), q = sc.nextInt(); int[] a=new int[n]; ArrayList<Integer> ls=new ArrayList<>(n); for(int i=0; i<n; i++){ a[i]=sc.nextInt(); ls.add(0); } int curIQ=0; for (int i=n-1; i >= 0; i--) { if(curIQ<a[i]){ if(curIQ==q) ls.set(i, 0); else { curIQ++; ls.set(i, 1); } } else ls.set(i, 1); } for(int i=0; i<n; i++){ print(ls.get(i)); } println(""); } out.close(); } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
f7140ae727474b53b39725d541f099c9
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
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 tc=0;tc<t;tc++){ int n = sc.nextInt(); int q = sc.nextInt(); int a[] = new int[n+1]; int sol[] = new int[n+1]; for(int i=1;i<=n;i++) a[i] = sc.nextInt(); int res = 0; for(int i=n;i>=1;i--){ if(a[i]>res){ if(q>res){ res++; sol[i] = 1; }else sol[i] = 0; }else sol[i] = 1; } for(int i=1;i<=n;i++) System.out.print(sol[i]); System.out.println(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
1935a06974cb0996e07fc986e4248661
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; /** * For deep recursion */ public class MainFaster{ void solve(){ int n = scanner.nextInt(), q = scanner.nextInt(); int[] arr = scanner.nextIntArray(n, 0); StringBuilder str = new StringBuilder(); for(int i = 0; i < n; i++){str.append(0);} int start = 0, end = n; while(start + 1< end){ int mid = start + (end - start) / 2; int mid1 = mid + 1; int c = count(arr, mid, q); int c1 = count(arr, mid, q); if(c1 == Integer.MIN_VALUE || c == Integer.MIN_VALUE){ start = mid1; } else{ if(c >= c1){ end = mid; } else{ start = mid; } } } int r1 = count(arr, start, q); int r2 = count(arr, end, q); int res = r1 >= r2? start: end; for(int i = 0; i < n; i++){ if(i < res){ if(arr[i] <= q){ str.setCharAt(i, '1'); } } else{ str.setCharAt(i, '1'); } } out.println(str.toString()); } int count(int[] arr, int x, int q){ int res = 0; for(int i = 0; i < arr.length; i++){ if(i < x){ if(arr[i] <= q){ res++; } } else{ res++; if(arr[i] > q){ q--; } if(q < 0){ return Integer.MIN_VALUE; } } } return res; } private static final boolean memory = true; private static final boolean singleTest = false; // read inputs and call solvers void run() { int numOfTests = singleTest? 1: scanner.nextInt(); for(int testIdx = 1; testIdx <= numOfTests; testIdx++){ solve(); } out.flush(); out.close(); } public static void main(String[] args) { if(memory) { new Thread(null, new Runnable() { @Override public void run() { new MainFaster().run(); } }, "go", 1 << 26).start(); } else{ new MainFaster().run(); } } /** * IO utils */ public static MyScanner scanner = new MyScanner(); public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArray(int n, int base){ int[] arr = new int[n + base]; for(int i = base; i < n + base; i++){ arr[i] = scanner.nextInt(); } return arr; } long[] nextLongArray(int n, int base){ long[] arr = new long[n + base]; for(int i = base; i < n + base; i++){ arr[i] = scanner.nextLong(); } return arr; } } void debug(Object...o){ out.println(Arrays.deepToString(o)); } void print(Object...o) { for(int i = 0; i < o.length; i++){ out.print(o); out.print(i == o.length-1? '\n':' '); } } void println(Object ...o){ for(int i = 0; i < o.length; i++){ out.println(o); } } void println(Object o){ out.println(o); } static void sort(int[] arr){ List<Integer> temp = new ArrayList<>(); for(int val: arr){temp.add(val);} Collections.sort(temp); for(int i = 0; i < arr.length; i++){arr[i] = temp.get(i);} } static void sort(long[] arr){ List<Long> temp = new ArrayList<>(); for(long val: arr){temp.add(val);} Collections.sort(temp); for(int i = 0; i < arr.length; i++){arr[i] = temp.get(i);} } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
44983a159162a139353714d715c4125d
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Collections; /* Name of the class has to be "Main" only if the class is public. */ public class DoremyIq { static FastScanner sc= new FastScanner(); public static void main (String[] args) throws Exception { // your code goes here int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int q = sc.nextInt(); int arr[] = sc.nextInts(n); int iq=0; StringBuilder sb = new StringBuilder(); for(int i=n-1;i>=0;i--){ if(arr[i]<=iq){ sb.append('1'); }else if(iq<q){ iq++; sb.append('1'); }else{ sb.append('0'); } } System.out.println(sb.reverse()); } } public static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } public static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } public static ArrayList<Integer> findDiv(int N) { //gens all divisors of N ArrayList<Integer> ls1 = new ArrayList<Integer>(); ArrayList<Integer> ls2 = new ArrayList<Integer>(); for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++) if(N%i == 0) { ls1.add(i); ls2.add(N/i); } Collections.reverse(ls2); for(int b: ls2) if(b != ls1.get(ls1.size()-1)) ls1.add(b); return ls1; } public static void sort(int[] arr) { //because Arrays.sort() uses quicksort which is dumb //Collections.sort() uses merge sort ArrayList<Integer> ls = new ArrayList<Integer>(); for(int x: arr) ls.add(x); Collections.sort(ls); for(int i=0; i < arr.length; i++) arr[i] = ls.get(i); } public static long power(long x, long y, long p) { //0^0 = 1 long res = 1L; x = x%p; while(y > 0) { if((y&1)==1) res = (res*x)%p; y >>= 1; x = (x*x)%p; } return res; } static class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
1489639273e7357db075cceb55ce6ace
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class C { private static final long MOD = 1_000_000_007; private static long binpow(long a, long b, long m) { if(b == 0) { return 1%m; } long res1 = binpow(a,b/2,m); if(b%2 == 0) { return res1 * res1 % m; } else { return a * res1 * res1 % m; } } private static long mulInverseUnderModulo(long a, long m) { return binpow(a, m-2, m);//Fermats little theorm } static class FastScanner { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while(!st.hasMoreTokens()) { try { st = new StringTokenizer(bf.readLine()); } catch(IOException e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return next().charAt(0); } String nextLine() throws IOException{ return bf.readLine().trim(); } } static class Pair<T extends Comparable<T>, U extends Comparable<U>> implements Comparable<Pair<T,U>> { T first; U second; Pair(){} Pair(T first, U second) { this.first = first; this.second = second; } public String toString() { return this.first + " " + this.second; } public int compareTo(Pair<T,U> rhs) { int firstCompareResult = this.first.compareTo(rhs.first); if(firstCompareResult == 0) { return this.second.compareTo(rhs.second); } else { return firstCompareResult; } } } private static StringBuilder ans; private static String ogAns; private static int onesInAns = 0; private static int ones = 0; private static Map<Pair<Integer,Integer>, Integer> dp; private static int solve(int i, int q, int[] a) { if(i >= a.length || q == 0) { if(ones > onesInAns) { ogAns = ans.toString(); onesInAns = ones; // System.out.println(ans.toString()); } return 0; } if(dp.containsKey(new Pair(i,q))) return dp.get(new Pair(i,q)); int toRet = 0; if(a[i] <= q) { ans.append("1"); ones++; toRet = 1 + solve(i+1,q,a); ans.deleteCharAt(ans.length()-1); ones--; } else { ans.append("0"); int r1 = solve(i+1,q,a); ans.deleteCharAt(ans.length()-1); ans.append("1"); ones++; int r2 = 1 + solve(i+1,q-1,a); ans.deleteCharAt(ans.length()-1); ones--; if(r1 > r2) { toRet = r1; } else { toRet = r2; } } dp.put(new Pair(i,q), toRet); return toRet; } public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); // int t = 1; while(t-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = sc.nextInt(); int x = 1; int[] ans = new int[n]; ans[n-1] = 1; for(int i=n-2;i>=0;i--) { if(a[i] <= x) { ans[i] = 1; } else if(x<q) { x+=1; ans[i] = 1; } } for(int curr: ans) out.print(curr); out.println(); } out.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
36fac0096079fd0586a6c1482040051e
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.Scanner; import java.util.Arrays; import java.util.stream.Collectors; import static java.lang.Math.max; public class C { public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); while (t > 0) { checkContests(input); t--; } } public static void checkContests(Scanner input) { int n = input.nextInt(); int q = input.nextInt(); int[] a = new int[n]; int maxContests = 0; int Q = 0; String[] contestOrder = new String[n]; Arrays.fill(contestOrder, "0"); for (int i=0; i < n; i++) { a[i] = input.nextInt(); } // Bruteforce for (int i=n; i > 0 ; i--) { if (a[i-1] <= Q) { contestOrder[i-1] = "1"; } if (Q < q && a[i-1] > Q) { contestOrder[i-1] = "1"; Q++; } } System.out.println(Arrays.stream(contestOrder).collect(Collectors.joining(""))); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
c613aa9adb1e6fc1ecbf2ecdb2140741
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.lang.*; public class jin { public static int n; static Scanner source = new Scanner(System.in); static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void make(int n) { while (n > 0) { int x = source.nextInt(); int q = source.nextInt(); int[] arr = new int[x]; for(int i=0;i<x;i++){ arr[i] = source.nextInt(); } int sum=0,oq=0; StringBuilder ans = new StringBuilder(); if(x==1){ if(q!=0){ ans.append('1'); } } else{ for(int i=x-1;i>=0;i--){ if(arr[i]>(oq) && oq<q){ ans.append('1'); oq++; } else if(oq>=arr[i]){ ans.append('1'); } else{ ans.append('0'); } } if(oq>q){ } } System.out.println(ans.reverse()); n--; } } public static void main(String[] args) { n = source.nextInt(); make(n); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
d477eb74c2adedc657cb196fded2eb1b
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class D { static boolean check(int i, int j, int n, int m,int arr[][]) { if(i<0 || i>=n || j<0 || j>=m) return false; if(arr[i][j]!=1) return false; return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static void solve() { Scanner sc = new Scanner(System.in); sc.close(); } static int bsearch(int arr[], int l, int h, int key) { return -1; } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t=sc.nextInt(); StringBuilder ans= new StringBuilder(""); for(int k=1;k<=t;k++) { int n=sc.nextInt(); int q=sc.nextInt(); int arr[]= new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } int nums[]= new int[n]; Arrays.fill(nums, -1); int p=0; for(int i=n-1;i>=0 && p<q;i--) { if(arr[i]>p) { p++; } nums[i]=-2; } for(int i=0;i<n;i++) { if(nums[i]==-1) { if(arr[i]<=q) { ans.append("1"); } else { ans.append("0"); } } else { ans.append("1"); } } ans.append("\n"); // System.out.println(ans); } System.out.println(ans); sc.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
967d50c3b8aaad8ef3c8a6b78cedd910
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.*; public class weird_algrithm { static BufferedWriter output = new BufferedWriter( new OutputStreamWriter(System.out)); static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); static int mod = 1000000007; static String toReturn = ""; static int steps = Integer.MAX_VALUE; static int maxlen = 1000005; /*MATHEMATICS FUNCTIONS START HERE MATHS MATHS MATHS MATHS*/ static long gcd(long a, long b) { if(b == 0) return a; else return gcd(b, a % b); } static long powerMod(long x, long y, int mod) { if(y == 0) return 1; long temp = powerMod(x, y / 2, mod); temp = ((temp % mod) * (temp % mod)) % mod; if(y % 2 == 0) return temp; else return ((x % mod) * (temp % mod)) % mod; } static long modInverse(long n, int p) { return powerMod(n, p - 2, p); } static long nCr(int n, int r, int mod, long [] fact, long [] ifact) { return ((fact[n] % mod) * ((ifact[r] * ifact[n - r]) % mod)) % mod; } static boolean isPrime(long a) { if(a == 1) return false; else if(a == 2 || a == 3 || a== 5) return true; else if(a % 2 == 0 || a % 3 == 0) return false; for(int i = 5; i * i <= a; i = i + 6) { if(a % i == 0 || a % (i + 2) == 0) return false; } return true; } static int [] seive(int a) { int [] toReturn = new int [a + 1]; for(int i = 0; i < a; i++) toReturn[i] = 1; toReturn[0] = 0; toReturn[1] = 0; toReturn[2] = 1; for(int i = 2; i * i <= a; i++) { if(toReturn[i] == 0) continue; for(int j = 2 * i; j <= a; j += i) toReturn[j] = 0; } return toReturn; } static long [] fact(int a) { long [] arr = new long[a + 1]; arr[0] = 1; for(int i = 1; i < a + 1; i++) { arr[i] = (arr[i - 1] * i) % mod; } return arr; } /*MATHS MATHS MATHS MATHS MATHEMATICS FUNCTIONS END HERE */ /*SWAP FUNCTION START HERE SWAP SWAP SWAP SWAP */ static void swap(int i, int j, long[] arr) { long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int i, int j, int[] arr) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int i, int j, String [] arr) { String temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int i, int j, char [] arr) { char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } /*SWAP SWAP SWAP SWAP SWAP FUNCTION END HERE*/ /*BINARY SEARCH METHODS START HERE * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH */ static boolean BinaryCheck(long test, long [] arr, long health) { for(int i = 0; i <= arr.length - 1; i++) { if(i == arr.length - 1) health -= test; else if(arr[i + 1] - arr[i] > test) { health = health - test; }else { health = health - (arr[i + 1] - arr[i]); } if(health <= 0) return true; } return false; } static long binarySearchModified(long start1, long n, ArrayList<Long> arr, int a, long r) { long start = start1, end = n, ans = -1; while(start < end) { long mid = (start + end) / 2; //System.out.println(mid); if(arr.get((int)mid) + arr.get(a) <= r && mid != start1) { ans = mid; start = mid + 1; }else{ end = mid; } } //System.out.println(); return ans; } static int binarySearch(int start, int end, long [] arr, long val) { while(start < end) { int mid = (int)Math.ceil((start + end) / 2.0); //System.out.println(mid); if(arr[mid] > val) end = mid - 1; else start = mid; } return start; } /*BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH BINARY SEARCH METHODS END HERE*/ /*RECURSIVE FUNCTION START HERE * RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE */ static int recurse(int x, int y, int n, int steps1, Integer [][] dp) { if(x > n || y > n) return 0; if(dp[x][y] != null) { return dp[x][y]; } else if(x == n || y == n) { return steps1; } return dp[x][y] = Math.max(recurse(x + y, y, n, steps1 + 1, dp), recurse(x, x + y, n, steps1 + 1, dp)); } /*RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE RECURSIVE FUNCTION END HERE*/ /*GRAPH FUNCTIONS START HERE * GRAPH * GRAPH * GRAPH * GRAPH * */ static class edge{ int from, to; long weight; public edge(int x, int y, long weight2) { this.from = x; this.to = y; this.weight = weight2; } } static class sort implements Comparator<pair>{ @Override public int compare(pair o1, pair o2) { // TODO Auto-generated method stub return (int)o1.a - (int)o2.a; } } static void addEdge(ArrayList<ArrayList<edge>> graph, int from, int to, long weight) { edge temp = new edge(from, to, weight); edge temp1 = new edge(to, from, weight); graph.get(from).add(temp); //graph.get(to).add(temp1); } static int ans = 0; static int dfs(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, int [] childs) { //System.out.println(graph.get(vertex).size()); if(visited[vertex]) return 0; visited[vertex] = true; int ans = 0; for(int i = 0; i < graph.get(vertex).size(); i++) { int temp = graph.get(vertex).get(i); if(!visited[temp]) { ans += dfs(graph, temp, visited, childs) + 1; } } childs[vertex] = ans; return ans; } static void topoSort(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, ArrayList<Integer> toReturn) { if(visited[vertex]) return; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { if(!visited[graph.get(vertex).get(i)]) topoSort(graph, graph.get(vertex).get(i), visited, toReturn); } toReturn.add(vertex); } static boolean isCyclicDirected(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, boolean [] reStack) { if(reStack[vertex]) return true; if(visited[vertex]) return false; reStack[vertex] = true; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { if(isCyclicDirected(graph, graph.get(vertex).get(i), visited, reStack)) return true; } reStack[vertex] = false; return false; } static int e = 0; static long mst(PriorityQueue<edge> pq, int nodes) { long weight = 0; while(!pq.isEmpty()) { edge temp = pq.poll(); int x = parent(parent, temp.to); int y = parent(parent, temp.from); if(x != y) { //System.out.println(temp.weight); union(x, y, rank, parent); weight += temp.weight; e++; } } return weight; } static void floyd(long [][] dist) { // to find min distance between two nodes for(int k = 0; k < dist.length; k++) { for(int i = 0; i < dist.length; i++) { for(int j = 0; j < dist.length; j++) { if(dist[i][j] > dist[i][k] + dist[k][j]) { dist[i][j] = dist[i][k] + dist[k][j]; } } } } } static void dijkstra(ArrayList<ArrayList<edge>> graph, long [] dist, int src) { for(int i = 0; i < dist.length; i++) dist[i] = Long.MAX_VALUE / 2; dist[src] = 0; boolean visited[] = new boolean[dist.length]; PriorityQueue<pair> pq = new PriorityQueue<>(new sort()); pq.add(new pair(src, 0)); while(!pq.isEmpty()) { pair temp = pq.poll(); int index = (int)temp.a; for(int i = 0; i < graph.get(index).size(); i++) { if(dist[graph.get(index).get(i).to] > dist[index] + graph.get(index).get(i).weight) { dist[graph.get(index).get(i).to] = dist[index] + graph.get(index).get(i).weight; pq.add(new pair(graph.get(index).get(i).to, graph.get(index).get(i).weight)); } } } } static int parent1 = -1; static boolean ford(ArrayList<ArrayList<edge>> graph1, ArrayList<edge> graph, long [] dist, int src, int [] parent) { for(int i = 0; i < dist.length; i++) dist[i] = Long.MIN_VALUE / 2; dist[src] = 0; boolean hasNeg = false; for(int i = 0; i < dist.length - 1; i++) { for(int j = 0; j < graph.size(); j++) { int from = graph.get(j).from; int to = graph.get(j).to; long weight = graph.get(j).weight; if(dist[to] < dist[from] + weight) { dist[to] = dist[from] + weight; parent[to] = from; } } } for(int i = 0; i < graph.size(); i++) { int from = graph.get(i).from; int to = graph.get(i).to; long weight = graph.get(i).weight; if(dist[to] < dist[from] + weight) { parent1 = from; hasNeg = true; /* * dfs(graph1, parent1, new boolean[dist.length], dist.length - 1); * //System.out.println(ans); dfs(graph1, 0, new boolean[dist.length], parent1); */ //System.out.println(ans); if(ans == 2) break; else ans = 0; } } return hasNeg; } /*GRAPH FUNCTIONS END HERE * GRAPH * GRAPH * GRAPH * GRAPH */ /*disjoint Set START HERE * disjoint Set * disjoint Set * disjoint Set * disjoint Set */ static int [] rank; static int [] parent; static int parent(int [] parent, int x) { if(parent[x] == x) return x; else return parent[x] = parent(parent, parent[x]); } static boolean union(int x, int y, int [] rank, int [] parent) { if(parent(parent, x) == parent(parent, y)) { return true; } if(rank[x] > rank[y]) { swap(x, y, rank); } rank[x] += rank[y]; parent[y] = x; return false; } /*disjoint Set END HERE * disjoint Set * disjoint Set * disjoint Set * disjoint Set */ /*INPUT START HERE * INPUT * INPUT * INPUT * INPUT * INPUT */ static int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(sc.readLine()); } static long nextLong() throws NumberFormatException, IOException { return Long.parseLong(sc.readLine()); } static long [] inputLongArr() throws NumberFormatException, IOException{ String [] s = sc.readLine().split(" "); long [] toReturn = new long[s.length]; for(int i = 0; i < s.length; i++) { toReturn[i] = Long.parseLong(s[i]); } return toReturn; } static int max = 0; static int [] inputIntArr() throws NumberFormatException, IOException{ String [] s = sc.readLine().split(" "); //System.out.println(s.length); int [] toReturn = new int[s.length]; for(int i = 0; i < s.length; i++) { toReturn[i] = Integer.parseInt(s[i]); } return toReturn; } static void print(int n) throws IOException { output.write(Integer.toString(n)); output.flush(); } static void print(String s) throws IOException { output.write(s); output.flush(); } static void print(long n) throws IOException { output.write(Long.toString(n) + "\n"); output.flush(); } static void print(char n) throws IOException { output.write(n); output.flush(); } /*INPUT * INPUT * INPUT * INPUT * INPUT * INPUT END HERE */ static long [] preCompute(int level) { long [] toReturn = new long[level]; toReturn[0] = 1; toReturn[1] = 16; for(int i = 2; i < level; i++) { toReturn[i] = ((toReturn[i - 1] % mod) * (toReturn[i - 1] % mod)) % mod; } return toReturn; } static class pair{ long a; long b; long d; public pair(long in, long y) { this.a = in; this.b = y; this.d = 0; } } static long smallestFactor(long a) { for(long i = 2; i * i <= a; i++) { if(a % i == 0) { return i; } } return a; } static int recurseRow(int [][] mat, int i, int j, int prev, int ans) { if(j >= mat[0].length) return ans; if(mat[i][j] == prev) { return recurseRow(mat, i, j + 1, prev, ans + 1); } else return ans; } static int recurseCol(int [][] mat, int i, int j, int prev, int ans) { if(i >= mat.length) return ans; if(mat[i][j] == prev) { return recurseCol(mat, i + 1, j, prev, ans + 1); } else return ans; } static int diff(char [] a, char [] b) { int sum = 0; for(int i = 0; i < a.length; i++) { sum += Math.abs((int)a[i] - (int)b[i]); } return sum; } static int [] nextGreaterBack(char [] s) { Stack<Integer> stack = new Stack<>(); int [] toReturn = new int[s.length]; for(int i = 0; i < s.length; i++) { if(!stack.isEmpty() && s[stack.peek()] >= s[i]) { stack.pop(); } if(stack.isEmpty()) { stack.push(i); toReturn[i] = -1; }else { toReturn[i] = stack.peek(); stack.push(i); } } return toReturn; } static int [] nextGreaterFront(char [] s) { Stack<Integer> stack = new Stack<>(); int [] toReturn = new int[s.length]; for(int i = s.length - 1; i >= 0; i--) { if(!stack.isEmpty() && s[stack.peek()] >= s[i]) { stack.pop(); } if(stack.isEmpty()) { stack.push(i); toReturn[i] = -1; }else { toReturn[i] = stack.peek(); stack.push(i); } } return toReturn; } static int lps(String s) { int max = 0; int [] lps = new int[s.length()]; lps[0] = 0; int j = 0; for(int i = 1; i < lps.length; i++) { j = lps[i - 1]; while(j > 0 && s.charAt(i) != s.charAt(j)) j = lps[j - 1]; if(s.charAt(i) == s.charAt(j)) { lps[i] = j + 1; max = Math.max(max, lps[i]); } } return max; } static int [][] vectors = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; static String dir = "DRUL"; static boolean check(int i, int j, boolean [][] visited) { if(i >= visited.length || j >= visited[0].length) return false; if(i < 0 || j < 0) return false; return true; } static int count = 0; static void recurse(boolean [][] visited, int i, int j, String p, int z, Integer [][][] dp) throws IOException { if(p.length() == z) { //System.out.println(i + " " + j); if(i == visited.length - 1 && j == 0) { count++; return; }else return; } if(i == visited.length - 1 && j == 0) { return; } if(visited[i][j]) return; visited[i][j] = true; for(int k = 0; k < vectors.length; k++) { int x = i + vectors[k][0], y = j + vectors[k][1]; char toAdd = dir.charAt(k); if(p.charAt(z) == '?' || p.charAt(z) == toAdd) { if(check(x, y, visited) && !visited[x][y]) { //recurse(visited, x, y, p, z + 1); } } } visited[i][j] = false; } static boolean check1(int k, long [] arr, long minSum) { int subArrays = 0; long sum = 0; for(int i = 0; i < arr.length; i++) { if(sum + arr[i] > minSum) { sum = arr[i]; subArrays++; if(arr[i] > minSum) return false; }else sum += arr[i]; } if(subArrays < k) return true; return false; } static long bin(long start, long end, long [] arr, int k) { long ans = 0; while(start < end) { long mid = (start + end) / 2; //System.out.println(mid); if(check1(k, arr, mid)) { ans = mid; end = mid; }else { start = mid + 1; } } return ans; } static void selectionSort(long arr[], long [] arr1, ArrayList<ArrayList<Integer>> ans) { int n = arr.length; for (int i = 0; i < n-1; i++) { int min_idx = i; for (int j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; else if(arr[j] == arr[min_idx]) { if(arr1[j] < arr1[min_idx]) min_idx = j; } if(i == min_idx) { continue; } ArrayList<Integer> p = new ArrayList<Integer>(); p.add(min_idx + 1); p.add(i + 1); ans.add(new ArrayList<Integer>(p)); swap(i, min_idx, arr); swap(i, min_idx, arr1); } } static void solve1() throws IOException { /* * for(int i = 0; i < dp.length; i++) { for(int j = 0; j < dp[0].length; j++) { * System.out.print(dp[i][j] + " "); } System.out.println(); } */ //print(recurse1(n[0], n[1], new Long[Math.max(n[0], n[1]) + 1][Math.max(n[0], n[1]) + 1])); } static int saved = Integer.MAX_VALUE; static String ans1 = ""; public static boolean isValid(int x, int y, String [] mat) { if(x >= mat.length || x < 0) return false; if(y >= mat[0].length() || y < 0) return false; return true; } static boolean recurse1(int i, int j, int [][] arr, int sum, Boolean [][][] dp) { if(i == arr.length - 1 && j == arr[0].length - 1) { if(sum + arr[i][j] == 0) return true; return false; } if(i == arr.length) return false; else if(j == arr[0].length) return false; if(sum < 0 && dp[i][j][arr.length + arr[0].length + 1 + sum] != null) return dp[i][j][arr.length + arr[0].length + 1 + sum]; if(sum > 0 && dp[i][j][sum] != null) return dp[i][j][sum]; if(sum < 0) dp[i][j][arr.length + arr[0].length + 1 + sum] = recurse1(i + 1, j, arr, sum + arr[i][j], dp) || recurse1(i, j + 1, arr, sum + arr[i][j], dp); return dp[i][j][sum] = recurse1(i + 1, j, arr, sum + arr[i][j], dp) || recurse1(i, j + 1, arr, sum + arr[i][j], dp); } static void bfs(String [] grid, int [][] distance, Queue<pair> q) { boolean [][] visited = new boolean[grid.length][grid[0].length()]; while(!q.isEmpty()) { pair head = q.poll(); for(int i = 0; i < vectors.length; i++) { int x = (int)head.a + vectors[i][0], y = (int)head.b + vectors[i][1]; if(isValid(x, y, grid) && grid[x].charAt(y) != '#' && distance[x][y] == -1) { distance[x][y] = (int)head.d + 1; pair toAdd = new pair(x, y); toAdd.d = distance[x][y]; q.add(toAdd); } } } } static pair bfs1(String [] grid, int [][] distance, Queue<pair> q, char [][] path) { boolean [][] visited = new boolean[grid.length][grid[0].length()]; while(!q.isEmpty()) { pair head = q.poll(); if(head.a == grid.length - 1 || head.b == grid[0].length() - 1 || head.a == 0 || head.b == 0) { return head; } for(int i = 0; i < vectors.length; i++) { int x = (int)head.a + vectors[i][0], y = (int)head.b + vectors[i][1]; int dist = (int)head.d + 1; if(isValid(x, y, grid) && grid[x].charAt(y) != '#' && !visited[x][y] && (dist < distance[x][y] || distance[x][y] == -1)) { path[x][y] = dir.charAt(i); visited[x][y] = true; pair toAdd = new pair(x, y); toAdd.d = dist; q.add(toAdd); } } } return null; } static int search(ArrayList<Integer> arr, int target) { int start = 0; int end = arr.size() - 1; while(start <= end) { int mid = (start + end) / 2; if(arr.get(mid) < target) start = mid + 1; else if(arr.get(mid) > target) end = mid - 1; else if(arr.get(mid) == target) { if(mid + 1 < arr.size() && arr.get(mid + 1) == target) { start = mid + 1; }else return start; } } return start; } static int end = -1; static boolean dfs1(int src, ArrayList<ArrayList<Integer>> graph, boolean [] visited, int k, HashMap<Integer, Integer> map) { visited[src] = true; if(k == 0) return true; //System.out.println(src + " " + k); for(int x : graph.get(src)) { if(!visited[x]) { if(map.containsKey(x)) { end = x; if(dfs1(x, graph, visited, k - 1, map)) return true; }else { if(dfs1(x, graph, visited, k, map)) return true; } } } return false; } public static void recurse3(ArrayList<Character> arr, int index, String s, int max, ArrayList<String> toReturn) { if(s.length() == max) { toReturn.add(s); return; } if(index == arr.size()) return; recurse3(arr, index + 1, s + arr.get(index), max, toReturn); recurse3(arr, index + 1, s, max, toReturn); } /* if(arr[i] > q) return Math.max(f(i + 1, q - 1) + 1, f(i + 1, q); else return f(i + 1, q) + 1 */ static boolean [] taken; static boolean check2(long [] arr, long t, long q) { taken = new boolean[arr.length]; int count = 0; int after = 0; for(int i = 0; i < arr.length; i++) { if(i < t) { if(arr[i] <= q) { count++; taken[i] = true; } }else { if(q == 0) return false; if(arr[i] > q) { after++; count++; q--; }else { after++; count++; } taken[i] = true; } } if(q < 0) return false; return true; } static void solve() throws IOException { long [] n = inputLongArr(); long [] arr = inputLongArr(); taken = new boolean[arr.length]; int start = 0; int end = arr.length - 1; int ans = 1; while(start <= end) { int mid = (start + end) / 2; if(check2(arr, mid, n[1])) { ans = mid; end = mid - 1; }else start = mid + 1; } check2(arr, end + 1, n[1]); //System.out.println(ans); for(int i = 0; i < taken.length; i++) { if(taken[i]) { print(1); }else print(0); } print("\n"); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int t = Integer.parseInt(sc.readLine()); for(int i = 0; i < t; i++) solve(); } } class TreeNode { int val; TreeNode next; public TreeNode(int x, TreeNode y) { this.val = x; this.next = y; } } /* 1 10 6 10 7 9 11 99 45 20 88 31 */
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
f5b819473e46b7e7d75c884f641812bc
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; import java.math.BigInteger; import java.util.stream.Collectors; public class Main { InputStream is; PrintWriter out; String INPUT = ""; void run() throws Exception { boolean oj = false; if(System.getProperty("ONLINE_JUDGE") == null) oj = true; if(!oj) { is = System.in; out = new PrintWriter(System.out); solve(); out.flush(); out.close(); } else { PrintStream ps = new PrintStream(new File("output2.txt")); InputStream iss = new FileInputStream("input.txt"); System.setIn(iss); System.setOut(ps); is = System.in; out = new PrintWriter(System.out); solve(); out.flush(); out.close(); } } public static void main(String[] args) throws Exception { new Main().run(); } public byte[] inbuf = new byte[1 << 16]; public int lenbuf = 0, ptrbuf = 0; public int readByte() { if (lenbuf == -1) { throw new InputMismatchException(); } if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public double nd() { return Double.parseDouble(ns()); } public char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private int ni() { return (int) nl(); } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } class Pair { int first; int second; Pair(int a, int b) { first = a; second = b; } } long[] nal(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nl(); } return arr; } // Sorting an array (O(nlogn)):- int partition(long[] array, int begin, int end) { int pivot = end; int counter = begin; for (int i = begin; i < end; i++) { if (array[i] < array[pivot]) { long temp = array[counter]; array[counter] = array[i]; array[i] = temp; counter++; } } long temp = array[pivot]; array[pivot] = array[counter]; array[counter] = temp; return counter; } void sort(long[] array, int begin, int end) { if (end <= begin) return; int pivot = partition(array, begin, end); sort(array, begin, pivot-1); sort(array, pivot+1, end); } void printArr(long[] arr) { for(int i=0; i<arr.length; i++) { out.print(arr[i] + " "); } out.println(); } long[] arr; // ********************************************************************************** class Segment_Tree { long[] t = new long[4 * arr.length]; void build(int index, int left, int right) { if(left == right) { t[index] = arr[left]; return; } int mid = (left + right) / 2; build(index * 2, left, mid); build(index * 2 + 1, mid + 1, right); t[index] = t[2 * index] + t[2 * index + 1]; } // indexPos -> For what index we have to update the value of an array. void update(int index, int left, int right, int indexPos, int value) { if(indexPos < left || indexPos > right) return; if(left == right) { t[index] = value; arr[left] = value; return; } int mid = (left + right) / 2; update(2 * index, left, mid, indexPos, value); update(2 * index + 1, mid + 1, right, indexPos, value); t[index] = t[2 * index] + t[2 * index + 1]; } long query(int index, int left, int right, int leftRange, int rightRange) { if(left > rightRange || leftRange > right) return 0; if(leftRange <= left && right <= rightRange) { return t[index]; } int mid = (left + right) / 2; long a = query(index * 2, left, mid, leftRange, rightRange); long b = query(index * 2 + 1, mid + 1, right, leftRange, rightRange); return a + b; } } // ********************************************************************************** void solve() { int test_case = 1; test_case = ni(); while (test_case-- > 0) { go(); } } // WRITE CODE FROM HERE :- void go() { int n = ni(), q = ni(); arr = nal(n); long[] b = new long[n]; // some operation and observation long sum = 0, nq = 0; for(int i=n-1; i>=0; i--) { if(arr[i] <= nq) b[i] = 1; else if(nq < q) { nq++; b[i] = 1; } else { b[i]=0; } } StringBuilder sb = new StringBuilder(); for(int i=0; i<n; i++) { sb.append(b[i]); } out.println(sb); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
c0cf008bdbc55c2f6b71fd266649b525
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class Main { static PrintWriter pw; static Scanner sc; public static void main(String[] args) throws Exception { sc = new Scanner(System.in); pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<>(); int[] arr = sc.nextIntArray(n); int k = 1; Integer[] sorted = new Integer[n]; for (int i = 0; i < n; i++) { sorted[i] = arr[i]; } Arrays.sort(sorted); for (int i = 0; i < n;) { int val = sorted[i]; while (i < n && sorted[i] == val) { i++; } map.put(val, k++); } boolean[] taken = new boolean[n]; for (int i = 0; i < n; i++) { if (arr[i] <= q) { taken[i] = true; } else { if (q > 0) { if (map.floorKey(q) == map.floorKey(q - 1)) { taken[i] = true; q--; } } } } int max = 0; int x = 0; for (int i = n - 1; i >= 0 && x != q; i--) { if (x < arr[i] && arr[i] > max) { x++; taken[i] = true; } else max = Math.max(max, arr[i]); } for (boolean f : taken) pw.print(f ? 1 : 0); pw.println(); } pw.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(String s) throws IOException { br = new BufferedReader(new FileReader(new File(s))); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
0e22d1159bad726f62b868f5a280c701
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class Main { static PrintWriter pw; static Scanner sc; public static void main(String[] args) throws Exception { sc = new Scanner(System.in); pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<>(); int[] arr = sc.nextIntArray(n); int k = 1; Integer[] sorted = new Integer[n]; for (int i = 0; i < n; i++) { sorted[i] = arr[i]; } Arrays.sort(sorted); for (int i = 0; i < n;) { int val = sorted[i]; while (i < n && sorted[i] == val) { i++; } map.put(val, k++); } FenwickTree ft = new FenwickTree(n + 5); for (int i = 0; i < n; i++) { ft.point_update(map.get(arr[i]), 1); } boolean[] taken = new boolean[n]; for (int i = 0; i < n; i++) { if (arr[i] <= q) { taken[i] = true; } else { if (q > 0) { if (q == 1) { if (ft.rsq(1) == 0) { taken[i] = true; q--; } } else { if (map.getOrDefault(map.floorKey(q) == null ? -1 : map.floorKey(q), -1) == map .getOrDefault(map.floorKey(q - 1) == null ? -1 : map.floorKey(q - 1), -1)) { taken[i] = true; q--; } } } } } int max = 0; int x = 0; for (int i = n - 1; i >= 0 && x != q; i--) { if (x < arr[i] && arr[i] > max) { x++; taken[i] = true; } else max = Math.max(max, arr[i]); } for (boolean f : taken) pw.print(f ? 1 : 0); pw.println(); } pw.flush(); } static class FenwickTree { // one-based DS int n; long[] ft; FenwickTree(int size) { n = size; ft = new long[n + 1]; } long rsq(int b) // O(log n) { b++; long sum = 0; while (b > 0) { sum += ft[b]; b -= b & -b; } // min? return sum; } long rsq(int a, int b) { b = Math.min(b, n - 1); return rsq(b) - rsq(a - 1); } void point_update(int k, long val) // O(log n), update = increment { k++; while (k <= n) { ft[k] += val; k += k & -k; } } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(String s) throws IOException { br = new BufferedReader(new FileReader(new File(s))); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
3fe9ab2375f0cfb31e3e75997a48c6bf
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class C { void go() { int n = Reader.nextInt(); int q = Reader.nextInt(); int[] A = new int[n]; for(int i = 0; i < n; i++) { A[i] = Reader.nextInt(); } int lo = 0; int hi = n - 1; int res = -1; // do only good before res, and do all [res, n - 1], // do a hard contest will potentially make some contests hard, // so we should do hard as late as possible. while(lo <= hi) { int mid = lo + hi >> 1; int curQ = q; boolean isOk = true; for(int i = mid; i < n; i++) { if(curQ == 0) { isOk = false; break; } if(curQ < A[i]) { curQ--; } } if(isOk) { res = mid; hi = mid - 1; } else { lo = mid + 1; } } StringBuilder sb = new StringBuilder(); for(int i = 0; i < n; i++) { if(i < res) { sb.append(A[i] <= q ? 1 : 0); } else { sb.append(1); } } Writer.println(sb.toString()); } void solve() { for(int T = Reader.nextInt(); T > 0; T--) go(); } void run() throws Exception { Reader.init(System.in); Writer.init(System.out); solve(); Writer.close(); } public static void main(String[] args) throws Exception { new C().run(); } public static class Reader { public static StringTokenizer st; public static BufferedReader br; public static void init(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } public static String next() { while(!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new InputMismatchException(); } } return st.nextToken(); } public static int nextInt() { return Integer.parseInt(next()); } public static long nextLong() { return Long.parseLong(next()); } public static double nextDouble() { return Double.parseDouble(next()); } } public static class Writer { public static PrintWriter pw; public static void init(OutputStream os) { pw = new PrintWriter(new BufferedOutputStream(os)); } public static void print(String s) { pw.print(s); } public static void print(char c) { pw.print(c); } public static void print(int x) { pw.print(x); } public static void print(long x) { pw.print(x); } public static void println(String s) { pw.println(s); } public static void println(char c) { pw.println(c); } public static void println(int x) { pw.println(x); } public static void flush() { pw.flush(); } public static void println(long x) { pw.println(x); } public static void close() { pw.close(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
b0d221ff0d1e8a5f87d163e9dbc2eaac
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import javax.print.attribute.HashAttributeSet; //import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache; //import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache; import java.io.*; import java.math.*; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLIntegrityConstraintViolationException; public class Main { private static class MyScanner { private static final int BUF_SIZE = 2048; BufferedReader br; private MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } private boolean isSpace(char c) { return c == '\n' || c == '\r' || c == ' '; } String next() { try { StringBuilder sb = new StringBuilder(); int r; while ((r = br.read()) != -1 && isSpace((char)r)); if (r == -1) { return null; } sb.append((char) r); while ((r = br.read()) != -1 && !isSpace((char)r)) { sb.append((char)r); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); } return null; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long mod = (long)(1e9 + 7); static void sort(long[] arr ) { ArrayList<Long> al = new ArrayList<>(); for(long e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(int[] arr ) { ArrayList<Integer> al = new ArrayList<>(); for(int e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(char[] arr) { ArrayList<Character> al = new ArrayList<Character>(); for(char cc:arr) al.add(cc); Collections.sort(al); for(int i = 0 ;i<arr.length ;i++) arr[i] = al.get(i); } static long mod_mul( long... a) { long ans = a[0]%mod; for(int i = 1 ; i<a.length ; i++) { ans = (ans * (a[i]%mod))%mod; } return ans; } static long mod_sum( long... a) { long ans = 0; for(long e:a) { ans = (ans + e)%mod; } return ans; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void print(long[] arr) { System.out.println("---print---"); for(long e:arr) System.out.print(e+" "); System.out.println("-----------"); } static void print(int[] arr) { System.out.println("---print---"); for(long e:arr) System.out.print(e+" "); System.out.println("-----------"); } static boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static long modInverse(long a, long m) { long g = gcd(a, m); return power(a, m - 2); } static long lcm(long a , long b) { return (a*b)/gcd(a, b); } static int lcm(int a , int b) { return (int)((a*b)/gcd(a, b)); } static long power(long x, long y){ if(y<0) return 0; long m = mod; if (y == 0) return 1; long p = power(x, y / 2) % m; p = (int)((p * (long)p) % m); if (y % 2 == 0) return p; else return (int)((x * (long)p) % m); } static class Combinations{ private long[] z; // factorial private long[] z1; // inverse factorial private long[] z2; // incerse number private long mod; public Combinations(long N , long mod) { this.mod = mod; z = new long[(int)N+1]; z1 = new long[(int)N+1]; z[0] = 1; for(int i =1 ; i<=N ; i++) z[i] = (z[i-1]*i)%mod; z2 = new long[(int)N+1]; z2[0] = z2[1] = 1; for (int i = 2; i <= N; i++) z2[i] = z2[(int)(mod % i)] * (mod - mod / i) % mod; z1[0] = z1[1] = 1; for (int i = 2; i <= N; i++) z1[i] = (z2[i] * z1[i - 1]) % mod; } long fac(long n) { return z[(int)n]; } long invrsNum(long n) { return z2[(int)n]; } long invrsFac(long n) { return z1[(int)n]; } long ncr(long N, long R) { if(R<0 || R>N ) return 0; long ans = ((z[(int)N] * z1[(int)R]) % mod * z1[(int)(N - R)]) % mod; return ans; } } static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } } } static int max(int... a ) { int max = a[0]; for(int e:a) max = Math.max(max, e); return max; } static long max(long... a ) { long max = a[0]; for(long e:a) max = Math.max(max, e); return max; } static int min(int... a ) { int min = a[0]; for(int e:a) min = Math.min(e, min); return min; } static long min(long... a ) { long min = a[0]; for(long e:a) min = Math.min(e, min); return min; } static int[] KMP(String str) { int n = str.length(); int[] kmp = new int[n]; for(int i = 1 ; i<n ; i++) { int j = kmp[i-1]; while(j>0 && str.charAt(i) != str.charAt(j)) { j = kmp[j-1]; } if(str.charAt(i) == str.charAt(j)) j++; kmp[i] = j; } return kmp; } /************************************************ Query **************************************************************************************/ /***************************************** Sparse Table ********************************************************/ static class SparseTable{ private long[][] st; SparseTable(long[] arr){ int n = arr.length; st = new long[n][25]; log = new int[n+2]; build_log(n+1); build(arr); } private void build(long[] arr) { int n = arr.length; for(int i = n-1 ; i>=0 ; i--) { for(int j = 0 ; j<25 ; j++) { int r = i + (1<<j)-1; if(r>=n) break; if(j == 0 ) st[i][j] = arr[i]; else st[i][j] = min(st[i][j-1] , st[ i + ( 1 << (j-1) ) ][ j-1 ] ); } } } public long gcd(long a ,long b) { if(a == 0) return b; return gcd(b%a , a); } public long query(int l ,int r) { int w = r-l+1; int power = log[w]; return min(st[l][power],st[r - (1<<power) + 1][power]); } private int[] log; void build_log(int n) { log[1] = 0; for(int i = 2 ; i<=n ; i++) { log[i] = 1 + log[i/2]; } } } /******************************************************** Segement Tree *****************************************************/ static class SegmentTree{ long[] tree; long[] arr; int n; SegmentTree(long[] arr){ this.n = arr.length; tree = new long[4*n+1]; this.arr = arr; buildTree(0, n-1, 1); } void buildTree(int s ,int e ,int index ) { if(s == e) { tree[index] = arr[s]; return; } int mid = (s+e)/2; buildTree( s, mid, 2*index); buildTree( mid+1, e, 2*index+1); tree[index] = gcd(tree[2*index] , tree[2*index+1]); } long query(int si ,int ei) { return query(0 ,n-1 , si ,ei , 1 ); } private long query( int ss ,int se ,int qs , int qe,int index) { if(ss>=qs && se<=qe) return tree[index]; if(qe<ss || se<qs) return (long)(0); int mid = (ss + se)/2; long left = query( ss , mid , qs ,qe , 2*index); long right= query(mid + 1 , se , qs ,qe , 2*index+1); return min(left, right); } public void update(int index , int val) { arr[index] = val; update(index , 0 , n-1 , 1); } private void update(int id ,int si , int ei , int index) { if(id < si || id>ei) return; if(si == ei ) { tree[index] = arr[id]; return; } if(si > ei) return; int mid = (ei + si)/2; update( id, si, mid , 2*index); update( id , mid+1, ei , 2*index+1); tree[index] = Math.min(tree[2*index] ,tree[2*index+1]); } } /* ***************************************************************************************************************************************************/ // static MyScanner sc = new MyScanner(); // only in case of less memory static Reader sc = new Reader(); static int TC; static StringBuilder sb = new StringBuilder(); static PrintWriter out=new PrintWriter(System.out); public static void main(String args[]) throws IOException { int tc = 1; tc = sc.nextInt(); TC = 0; for(int i = 1 ; i<=tc ; i++) { TC++; // sb.append("Case #" + i + ": " ); // During KickStart && HackerCup TEST_CASE(); } System.out.print(sb); } static void TEST_CASE() { int n = sc.nextInt(); long q = sc.nextLong(); int[] arr = new int[n]; for(int i = 0 ;i<n ; i++) arr[i] = sc.nextInt(); TreeMap<Long ,Long > map = new TreeMap<>(); int[] ans = new int[n]; int l = 0 , r = n; while(l<=r) { int m = (l+r)/2; if(!fnc(arr, q, m)) l = m+1; else r = m-1; } // System.out.println(l); // System.out.println(fnc(arr, q,l )); for(int i = 0 ;i<n ; i++) { if(arr[i]<=q || l == 0) { ans[i] = 1; continue; } if(l>0) { l--; continue; } } for(int e:ans) sb.append(e); sb.append("\n"); } static boolean fnc(int[] arr , long q , int off) { for(int e:arr) { if(e<=q) continue; if(off<=0) { q--; continue; } off--; } // System.out.println(q); return q>=0; } } /*******************************************************************************************************************************************************/ /** 1 5 3 7 3 6 12 */
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
fbaff9190cce7d8ceb2cc815aefc317c
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Test { final static private FastReader fr = new FastReader(); final static private PrintWriter out = new PrintWriter(System.out) ; static private long mod = (long)1e9 + 7; private static void solve() { int n = fr.nextInt(); int q = fr.nextInt() ; long[] arr = inputArr(n) ; StringBuilder ans = new StringBuilder("") ; int cnt = 0 ; for (int i = n-1; i >= 0 ; i--) { if (cnt < arr[i]) { if (cnt < q) { cnt++ ; ans.append("1") ; } else { ans.append("0") ; } } else { ans.append("1") ; } } ans.reverse() ; out.println(ans); } public static void main(String[] args) { int t = 1 ; t = fr.nextInt() ; while (t-- > 0) { solve() ; } out.close() ; } private static long[] inputArr(int n){ long[] arr = new long[n] ; for (int i = 0 ;i < n ; i++) { arr[i] = fr.nextLong() ; } return arr; } private static void sort(int[] arr){ ArrayList<Integer> al = new ArrayList<>() ; for (int x : arr){ al.add(x) ; } Collections.sort(al); for (int i = 0 ; i < arr.length; i++){ arr[i] = al.get(i) ; } } private static void sort(long[] arr){ ArrayList<Long> al = new ArrayList<>() ; for (long x : arr){ al.add(x) ; } Collections.sort(al); for (int i = 0 ; i < arr.length; i++){ arr[i] = al.get(i) ; } } private static long getMax(long ... a) { long max = Long.MIN_VALUE ; for (long x : a) max = Math.max(x, max) ; return max ; } private static long getMin(long ... a) { long max = Long.MAX_VALUE ; for (long x : a) max = Math.min(x, max) ; return max ; } private static long fastPower(double a, long b) { double ans = 1 ; while (b > 0) { if ((b & 1) != 0) ans *= a ; a *= a ; b >>= 1 ; } return (long)(ans + 0.5) ; } private static long fastPower(long a, long b, long mod) { long ans = 1 ; while (b > 0) { if ((b&1) != 0) ans = (ans%mod * a%mod) %mod; b >>= 1 ; a = (a%mod * a%mod)%mod ; } return ans ; } private static int lower_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key) ; if (pos < 0) { pos = - (pos + 1) ; } return pos ; } private static int upper_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key); pos++ ; if (pos < 0) { pos = -(pos) ; } return pos ; } private static int upper_bound(int[] arr, int key) { int start = 0 , end = arr.length ; int ans = -1 ; while (start < end) { int mid = start + ((end - start) >> 1) ; if (arr[mid] <= key) start = mid + 1 ; else end = mid ; } return start ; } private static int lower_bound(int[] arr, int key) { int start = 0 , end = arr.length -1; int ans = -1 ; while (start <= end) { int mid = start + ((end - start )>>1) ; if (arr[mid] == key) { ans = mid ; } if (arr[mid] >= key){ end = mid - 1 ; } else start = mid + 1 ; } return ans ; } private static class Pair{ long x ; long y ; Pair(long x, long y){ this.x = x ; this.y = y ; } @Override public int hashCode() { return super.hashCode(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return x == pair.x && y == pair.y; } } private static long gcd(long a, long b) { if (b == 0) return a ; return gcd(b, a%b) ; } private static long lcm(long a, long b) { return (a * b)/gcd(a, b); } private static boolean isPrime(int num) { if (num <= 2) return true ; for (int i = 2; i <= Math.sqrt(num); i++) { if (num%i == 0) return false ; } return true; } private static List<Long> seive(int n) { // all are false by default // false -> prime, true -> composite boolean[] nums = new boolean[n+1] ; for (int i = 2 ; i <= Math.sqrt(n); i++) { if (!nums[i]) { for (int j = i*i ; j <= n ; j += i) { nums[j] = true ; } } } ArrayList<Long>primes = new ArrayList<>() ; for (int i = 2 ; i <=n ; i++) { if (!nums[i]) primes.add((long) i) ; } return primes ; } private static boolean isVowel(char ch) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'; } private 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
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
fe79805f9744ec677d0573fb98568d09
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.*; /** * 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); TaskA solver = new TaskA(); int testNum = in.nextInt(); solver.solve(testNum, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { for (int z = 0; z < testNumber; z++) { int n = in.nextInt(); int q = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } ArrayList<Character> list = new ArrayList<Character>(); int counter = 0; for (int i = n-1; i >= 0; i--) { if (counter == q) { if (a[i] > q) { list.add('0'); } else { list.add('1'); } } else { if (a[i] <= counter) { list.add('1'); } else { list.add('1'); counter++; } } } for (int i = list.size()-1; i >= 0; i--) { out.print(list.get(i)); } out.println(); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
08bd681a9e7a55c463a5749c5f329b3f
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class codeforces_808_C { private static void solve(FastIOAdapter in, PrintWriter out) { int n = in.nextInt(); int q = in.nextInt(); int[] a = in.readArray(n); int iq = Math.min(n, q); int[] ans = new int[n]; int needed = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] <= needed) ans[i] = 1; else if (needed < iq) { ans[i] = 1; needed++; } } for (int i = 0; i < n; i++) { out.print(ans[i]); } out.println(); } public static void main(String[] args) throws Exception { try (FastIOAdapter ioAdapter = new FastIOAdapter()) { int count = 1; count = ioAdapter.nextInt(); while (count-- > 0) { solve(ioAdapter, ioAdapter.out); } } } static void ruffleSort(int[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } Arrays.sort(arr); } static class FastIOAdapter implements AutoCloseable { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter((System.out)))); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); return null; } } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } @Override public void close() throws Exception { out.flush(); out.close(); br.close(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
6e7ac73295ff4ef9795d6e17d433718d
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class CF1708C extends PrintWriter { CF1708C() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1708C o = new CF1708C(); o.main(); o.flush(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] aa = new int[n]; for (int i = 0; i < n; i++) aa[i] = sc.nextInt(); int lower = -1, upper = n; while (upper - lower > 1) { int h = (lower + upper) / 2; int p = q; for (int i = h; i < n - 1; i++) if (p < aa[i]) p--; if (p > 0) upper = h; else lower = h; } byte[] cc = new byte[n]; for (int i = upper; i < n; i++) cc[i] = '1'; for (int i = 0; i < upper; i++) cc[i] = (byte) (q < aa[i] ? '0' : '1'); println(new String(cc)); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
a9b7ac31eb0243e93ec5d3aa61e109a9
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class Conests{ public static void main(String[] args) throws IOException{ BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int t=Integer.parseInt(f.readLine()); while(t-->0) { StringTokenizer st=new StringTokenizer(f.readLine()); int n=Integer.parseInt(st.nextToken()); int q=Integer.parseInt(st.nextToken()); int[] arr=new int[n]; st=new StringTokenizer(f.readLine()); for(int i=0;i<n;i++) { arr[i]=Integer.parseInt(st.nextToken()); } int l=0; int r=n; int max=0; boolean[] ans=new boolean[n]; while(l<r) { int mid=(l+r+1)/2; int temp=q; boolean[] a=new boolean[n]; for(int i=n-mid;i<n;i++) { if(arr[i]>temp) { temp--; } a[i]=true; } int tests=mid; for(int i=0;i<n-mid;i++) { if(arr[i]<=q) { tests++; a[i]=true; } } if(temp>=0) { l=mid; if(tests>max) { for(int i=0;i<n;i++) { ans[i]=a[i]; } max=tests; } } else { r=mid-1; } } for(int i=0;i<n;i++) { if(ans[i]) { out.print(1); } else { out.print(0); } } out.println(); } out.close(); f.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
be9213892ecd856cb16172241459b259
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class TimePass { public static void main (String[] args) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int testCases=Integer.parseInt(br.readLine()); // int testCases=1; while(testCases-->0){ String input[]=br.readLine().split(" "); int n=Integer.parseInt(input[0]); int q=Integer.parseInt(input[1]); input=br.readLine().split(" "); int arr[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=Integer.parseInt(input[i]); } int l=0; int h=n-1; int ans=n; while(l<=h) { int mid=(l+h)/2; int temp=q; for(int i=mid;i<n;i++) { if(arr[i]>temp) temp--; } if(temp>=0) { ans=mid; h=mid-1; }else { l=mid+1; } } for(int i=0;i<ans;i++) { if(arr[i]<=q) out.print("1"); else out.print("0"); } for(int i=ans;i<n;i++) { out.print("1"); } out.println(); } out.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
91befdff624a483bbcf0fa4c8d65bb03
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class TimePass { public static void main (String[] args) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int testCases=Integer.parseInt(br.readLine()); // int testCases=1; while(testCases-->0){ String input[]=br.readLine().split(" "); int n=Integer.parseInt(input[0]); int q=Integer.parseInt(input[1]); input=br.readLine().split(" "); int arr[]=new int[n]; List<Integer>index=new ArrayList<>(); for(int i=0;i<n;i++) { arr[i]=Integer.parseInt(input[i]); if(arr[i]>q) index.add(i); } int l=0; int h=index.size()-1; int ans=n; while(l<=h) { int mid=(l+h)/2; int temp=q; for(int i=index.get(mid);i<n;i++) { if(arr[i]>temp) temp--; } if(temp>=0) { ans=index.get(mid); h=mid-1; }else { l=mid+1; } } for(int i=0;i<ans;i++) { if(arr[i]<=q) out.print("1"); else out.print("0"); } for(int i=ans;i<n;i++) { out.print("1"); } out.println(); } out.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
63738d7c85deb54525346d25181bda78
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import javax.swing.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static AReader scan = new AReader(); static int N = 100010; static int[] a = new int[N]; static void solve() { int n = scan.nextInt(); int q = scan.nextInt(); for(int i = 1;i<=n;i++) a[i] = scan.nextInt(); StringBuffer sb = new StringBuffer(); // if(q >= n){ // for(int i = 1;i<=n;i++) sb.append(1); // }else { // // 5 - 3 // for (int i = 1;i<=n - q;i++){ // if(a[i] <= q) sb.append(1); // else sb.append(0); // } // for(int i = n-q+1;i<=n;i++) sb.append("1"); // } int Q = 0; for(int i = n;i>0;i--){ if(a[i] <= Q) sb.append(1); else if(Q < q){ Q++;sb.append(1); }else sb.append(0); } sb.reverse(); System.out.println(sb.toString()); } public static void main(String[] args) { int T = scan.nextInt(); while (T-- > 0) { solve(); } } } class Pair{ int x,y; public Pair(int x, int y) { this.x = x; this.y = y; } } class AReader { private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer tokenizer = new StringTokenizer(""); private String innerNextLine() { try { return reader.readLine(); } catch (IOException ex) { return null; } } public boolean hasNext() { while (!tokenizer.hasMoreTokens()) { String nextLine = innerNextLine(); if (nextLine == null) { return false; } tokenizer = new StringTokenizer(nextLine); } return true; } public String nextLine() { tokenizer = new StringTokenizer(""); return innerNextLine(); } public String next() { hasNext(); return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
1784fc9036aced71dd4538cf640eddb7
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class B { static int MOD = (int)(1e9+7); public static boolean isPossible(int[] arr, int index,int q) { for(int i = index;i<arr.length;i++) { if(arr[i]>q) { if(q>0)q--; else return false; } } return true; } public static void main(String[] args)throws IOException { FastReader sc = new FastReader(); StringBuilder sb = new StringBuilder(); int t = sc.nextInt(); out:while(t-->0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] arr = sc.readArray(n); ArrayList<Integer> bad = new ArrayList<>(); for(int i =0;i<n;i++) { if(arr[i]>q)bad.add(i); } int l = 0; int r = bad.size()-1; int ans = -1; while(r>=l) { int mid = l + (r-l)/2; int index = bad.get(mid); if(isPossible(arr, index, q)) { ans = index; r= mid-1; } else l= mid+1; } int good = 0; if(ans==-1) { ans = n; } for(int i =0;i<n;i++) { if(i>=ans) { sb.append(1); continue; } if(arr[i]<=q) { sb.append(1); } else sb.append(0); } sb.append("\n"); } System.out.println(sb); } 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()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
b1c704f616b04a2928c26b1063874af6
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class C_Doremy_s_IQ{ public static void main(String[] args) throws Exception{ FastReader fr = new FastReader(System.in); int t = fr.nextInt(); while(t-->0){ int n = fr.nextInt(); int iq = fr.nextInt(); int[] vals = new int[n]; for(int i = 0;i<n;i++){ vals[i] = fr.nextInt(); } int currentIQ = 0; for(int i=n-1;i>=0;i--){ if(vals[i]<=currentIQ){ vals[i]=1; }else if(currentIQ<iq){ currentIQ++; vals[i]=1; }else{ vals[i]=0; } } for (int i = 0; i < vals.length; i++) { System.out.print(vals[i]); } System.out.println(""); } } public static void print(Object val){ System.out.print(val); } public static void println(Object val){ System.out.println(val); } public static int[] sort(int[] vals){ ArrayList<Integer> values = new ArrayList<>(); for(int i = 0;i<vals.length;i++){ values.add(vals[i]); } Collections.sort(values); for(int i =0;i<values.size();i++){ vals[i] = values.get(i); } return vals; } public static long[] sort(long[] vals){ ArrayList<Long> values = new ArrayList<>(); for(int i = 0;i<vals.length;i++){ values.add(vals[i]); } Collections.sort(values); for(int i =0;i<values.size();i++){ vals[i] = values.get(i); } return vals; } public static void reverseArray(long[] vals){ int startIndex = 0; int endIndex = vals.length-1; while(startIndex<=endIndex){ long temp = vals[startIndex]; vals[startIndex] = vals[endIndex]; vals[endIndex] = temp; startIndex++; endIndex--; } } public static void reverseArray(int[] vals){ int startIndex = 0; int endIndex = vals.length-1; while(startIndex<=endIndex){ int temp = vals[startIndex]; vals[startIndex] = vals[endIndex]; vals[endIndex] = temp; startIndex++; endIndex--; } } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } public static int GCD(int numA, int numB){ if(numA==0){ return numB; }else if(numB==0){ return numA; }else{ if(numA>numB){ return GCD(numA%numB,numB); }else{ return GCD(numA,numB%numA); } } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
801b61311331e9043d6d4c772388c926
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0) { int n=sc.nextInt(); int q=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int c=0; int r[]=new int[n]; for(int i=n-1;i>=0;i--) { if(a[i]<=c) { r[i]=1; } else if(c<q) { r[i]=1; c++; } else { r[i]=0; } } for(int i=0;i<n;i++) System.out.print(r[i]); System.out.println(); t--; } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
7abe3b16f4469df1efece58a976490b3
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class test2 { public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } static final class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int read() throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read(buf); if (numChars <= 0) { return -1; } } return buf[curChar++]; } public final int readInt() throws IOException { return (int) readLong(); } public final long readLong() throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); if (c == -1) throw new IOException(); } boolean negative = false; if (c == '-') { negative = true; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return negative ? -res : res; } public final int[] readIntArray(int size) throws IOException { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = readInt(); } return array; } public final long[] readLongArray(int size) throws IOException { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = readLong(); } return array; } public final String readString() throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } static long mulmod(long a, long b, long mod) { long res = 0; // Initialize result a = a % mod; while (b > 0) { // If b is odd, add 'a' to result if (b % 2 == 1) { res = (res + a) % mod; } // Multiply 'a' with 2 a = (a * 2) % mod; // Divide b by 2 b /= 2; } // Return result return res % mod; } static long pow(long a, long b, long MOD) { long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > MOD) x %= MOD; } y = (y * y); if (y > MOD) y %= MOD; b /= 2; } return x; } static long[] f = new long[100001]; static long InverseEuler(long n, long MOD) { return pow(n, MOD - 2, MOD); } static long C(int n, int r, long MOD) { return (f[n] * ((InverseEuler(f[r], MOD) * InverseEuler(f[n - r], MOD)) % MOD)) % MOD; } static int[] h = {0, 0, -1, 1}; static int[] v = {1, -1, 0, 0}; static class Pair2 { public long cost; int node; public Pair2(long cos, int node) { this.cost = cos; this.node = node; } } static long compute_hash(String s) { int p = 31; int m = 1000000007; long hash_value = 0; long p_pow = 1; for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m; p_pow = (p_pow * p) % m; } return hash_value; } public static class SegmentTree { long[][] tree; int n; public SegmentTree(int[] nodes) { tree = new long[nodes.length * 4][2]; n = nodes.length; build(0, n - 1, 0, nodes); } private void build(int l, int r, int pos, int[] nodes) { if (l == r) { tree[pos][0] = nodes[l]; tree[pos][1] = l; return; } int mid = (l + r) / 2; build(l, mid, 2 * pos + 1, nodes); build(mid + 1, r, 2 * pos + 2, nodes); if (tree[2 * pos + 1][0] > tree[2 * pos + 2][0]) { tree[pos][1] = tree[2 * pos + 1][1]; } else { tree[pos][1] = tree[2 * pos + 2][1]; } tree[pos][0] = Math.max(tree[2 * pos + 1][0], tree[2 * pos + 2][0]); } // public void update(int pos, int val) { // updateUtil(0, n - 1, 0, pos, val); // } public long[] get(int l, int r) { return getUtil(0, n - 1, 0, l, r); } private long[] getUtil(int l, int r, int pos, int ql, int qr) { if (ql > r || qr < l) { return new long[]{-1, -1}; } if (l >= ql && r <= qr) { return tree[pos]; } int mid = (l + r) / 2; long[] left = getUtil(l, mid, 2 * pos + 1, ql, qr); long[] right = getUtil(mid + 1, r, 2 * pos + 2, ql, qr); long choice = right[1]; if (left[0] > right[0]) choice = left[1]; return new long[]{Math.max(left[0], right[0]), choice}; } // private void updateUtil(int l, int r, int pos, int i, int val) { // if (i < l || i > r) { // return; // } // if (l == r) { // tree[pos] = val; // return; // } // int mid = (l + r) / 2; // updateUtil(l, mid, 2 * pos + 1, i, val); // updateUtil(mid + 1, r, 2 * pos + 2, i, val); // tree[pos] = tree[2 * pos + 1] + tree[2 * pos + 2]; // } } static int counter = 0; static int[] rIn; static int[] rOut; static int[] lIn; static int[] lOut; private static int[] flatten; private static int[] lFlatten; static long answer = 0; static int VISITED = 1; static int VISITING = 2; static int[] DIRX = new int[]{0, 0, 1, -1}; static int[] DIRY = new int[]{1, -1, 0, 0}; public static class Pair22 { int num, pos; public Pair22(int x, int y) { this.num = x; this.pos = y; } } public static long sumofdig(long n) { long sum = 0; while (n > 0) { sum += n%10; n/=10; } return sum; } static int binarySearch(long[] arr, long target) { int start = 0, end = arr.length - 1; int ans = 0; while (start <= end) { int mid = start + (end - start) / 2; if (arr[mid] <= target) { ans = mid +1; start = mid + 1; } else { end = mid - 1; } } return ans; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static boolean isPerfectSquare(long num) { long left = 1, right = num; while (left <= right) { long mid = (left + right) / 2; // Check if mid is perfect square if (mid * mid == num) { return true; } // Mid is small -> go right to increase mid if (mid * mid < num) { left = mid + 1; } // Mid is large -> to left to decrease mid else { right = mid - 1; } } return false; } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long MOD = 1000000007; static long power( long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if ((y & 1)>0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long modInverse( long n, long p) { return power(n, p - 2, p); } static long nCrModPFermat( int n, int r, long p) { // If n<r, then nCr should return 0 if (n < r) return 0; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r long fac[] = new long[n+1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } public static int upperBound(Integer[] a,int size,Integer key) { int first=0,last=size-1; while(first<last) { int mid=(first+last)/2; if(key<a[mid]) last=mid; else first=mid+1; } if(a[first]>key) return first; return size; } public static int lowerBound(Integer[] a,int size,Integer key) { int first=0,last=size-1; while(first<last) { int mid=(first+last)/2; if(key>a[mid]) first=mid+1; else last=mid; } if(a[first]>=key) return first; return size; } static class class_Pair{ long x; long y; class_Pair(long x,long y){ this.x = x; this.y = y; } } static int function(int mid,long a[],long q) { long c = q; int ans = 0; for(int i=0;i<a.length;i++) { if(a[i] > c && mid > 0) { mid--; } else if(a[i] > c) { ans++; c--; } else { ans++; } if(c == -1) { return -1; } } return ans; } public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int testcase = scanner.nextInt(); while(testcase-->0) { int n = scanner.nextInt(); long q = scanner.nextLong(); long a[] = new long[n]; for(int i=0;i<n;i++) { a[i] = scanner.nextLong(); } int l = 0; int r = n; int ans = -1; while(l <= r) { int mid = l + (r-l)/2; if(function(mid,a,q)== -1) { l = mid+1; } else { ans = function(mid,a,q); r = mid-1; } } ans = n - ans; // System.out.println(ans); StringBuilder string = new StringBuilder(); for(int i=0;i<n;i++) { if(a[i]>q && ans>0) { ans--; string.append('0'); } else if(a[i]>q) { q--; string.append('1'); } else { string.append('1'); } } System.out.println(string); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
320594cf79c5b5541252ac269bc4a7ab
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
/* It's always like another kick for me to make sure I get what I want to get done, because honestly you never know. */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main extends PrintWriter { Main() { super(System.out); } static boolean cases = true; // Solution void solve(int t) { int n = sc.nextInt(); int q = sc.nextInt(); int a[] = sc.readIntArray(n); char ans[] = new char[n]; Arrays.fill(ans, '0'); int x = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] <= x) { ans[i] = '1'; } else { if (x < q) { x++; ans[i] = '1'; } } } System.out.println(new String(ans)); } void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static void main(String[] args) { Main obj = new Main(); int c = 1; for (int t = (cases ? sc.nextInt() : 0); t > 1; t--, c++) obj.solve(c); obj.solve(c); obj.flush(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } char[] readCharArray(int n) { char a[] = new char[n]; String s = sc.next(); for (int i = 0; i < n; i++) { a[i] = s.charAt(i); } return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } final int ima = Integer.MAX_VALUE; final int imi = Integer.MIN_VALUE; final long lma = Long.MAX_VALUE; final long lmi = Long.MIN_VALUE; static final long mod = (long) 1e9 + 7; private static final FastScanner sc = new FastScanner(); private PrintWriter out = new PrintWriter(System.out); }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
413691d6cabdf536832b4dc3885e0b72
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
/* It's always like another kick for me to make sure I get what I want to get done, because honestly you never know. */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main extends PrintWriter { Main() { super(System.out); } static boolean cases = true; // Solution void solve(int t) { int n = sc.nextInt(); int q = sc.nextInt(); int a[] = sc.readIntArray(n); char ans[] = new char[n]; Arrays.fill(ans, '0'); int x = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] <= x) { ans[i] = '1'; } else { if (x < q) { x++; ans[i] = '1'; } } } System.out.println(new String(ans)); } void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static void main(String[] args) { Main obj = new Main(); int c = 1; for (int t = (cases ? sc.nextInt() : 0); t > 1; t--, c++) obj.solve(c); obj.solve(c); obj.flush(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } char[] readCharArray(int n) { char a[] = new char[n]; String s = sc.next(); for (int i = 0; i < n; i++) { a[i] = s.charAt(i); } return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } final int ima = Integer.MAX_VALUE; final int imi = Integer.MIN_VALUE; final long lma = Long.MAX_VALUE; final long lmi = Long.MIN_VALUE; static final long mod = (long) 1e9 + 7; private static final FastScanner sc = new FastScanner(); private PrintWriter out = new PrintWriter(System.out); }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
80c59a04cb0ae80d2ed5238a9fc96d57
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; public class C { static FastScanner sc; static PrintWriter pw; static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); st = null; } public FastScanner(String fileName){ try{ br = new BufferedReader(new FileReader(new File(System.getProperty("user.dir")+"/"+fileName))); st = null; }catch(Exception e){ } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) ret[i] = ni(); return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) ret[i] = nl(); return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws Exception{ if(System.getProperty("ONLINE_JUDGE") == null){ try { pw = new PrintWriter("output.txt"); sc = new FastScanner("input.txt"); }catch (Exception e) { } }else{ sc = new FastScanner(); pw = new PrintWriter(System.out); } try{ int T = sc.ni(); while(T-->0){ solve(); } }catch(Exception e){ return; } pw.close(); } static void solve(){ int n = sc.ni(); int q = sc.ni(); int a[] = sc.intArray(n); int ans[] = new int[n]; int nq = 0; for(int i=n-1; i>=0; i--){ if(a[i]<=nq){ ans[i] = 1; }else if(nq<q){ nq++; ans[i] = 1; } } for(int num: ans){ pw.print(num); } pw.println(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
bcace70ddcd944be74c4704d37a3aa9b
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; import javax.print.attribute.HashAttributeSet; public class C { static FastScanner sc; static PrintWriter pw; static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); st = null; } public FastScanner(String fileName){ try{ br = new BufferedReader(new FileReader(new File(System.getProperty("user.dir")+"/"+fileName))); st = null; }catch(Exception e){ } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) ret[i] = ni(); return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) ret[i] = nl(); return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws Exception{ sc = new FastScanner(); pw = new PrintWriter(System.out); if (System.getProperty("ONLINE_JUDGE") == null) { try { pw = new PrintWriter("output.txt"); sc = new FastScanner("input.txt"); }catch (Exception e) { } } try{ int T = sc.ni(); while(T-->0){ solve(); } }catch(Exception e){ return; } pw.close(); } static void solve(){ int n = sc.ni(); int q = sc.ni(); int a[] = sc.intArray(n); int ans[] = new int[n]; int nq = 0; for(int i=n-1; i>=0; i--){ if(a[i]<=nq){ ans[i] = 1; }else if(nq<q){ nq++; ans[i] = 1; } } for(int num: ans){ pw.print(num); } pw.println(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
b6a8a586347ca5ece101558651bf1499
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
// JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA import java.util.*; import java.util.Map.Entry; import java.util.stream.*; import java.lang.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.io.*; public class CodeForces { static private final String INPUT = "input.txt"; static private final String OUTPUT = "output.txt"; static BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer ST; static PrintWriter out = new PrintWriter(System.out); static DecimalFormat df = new DecimalFormat("0.00000"); final static int MAX = Integer.MAX_VALUE, MIN = Integer.MIN_VALUE, mod = (int) (1e9 + 7); final static long LMAX = Long.MAX_VALUE, LMIN = Long.MIN_VALUE; final static long INF = (long) 1e18, Neg_INF = (long) -1e18; static Random rand = new Random(); // ======================= MAIN ================================== public static void main(String[] args) throws IOException { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; // ==== start ==== input(); preprocess(); int t = 1; t = readInt(); while (t-- > 0) { solve(); } out.flush(); // ==== end ==== if (!oj) System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" })); } private static void solve() throws IOException { int n = readInt(), q = readInt(); int[] arr = readIntArray(n); int lo = 0, hi = n - 1, ans = n; while (lo <= hi) { int mid = (lo + hi) >> 1; int iq = q; for (int i = mid; i < n; i++) { if (arr[i] > iq) iq--; } if (iq < 0) lo = mid + 1; else { ans = mid; hi = mid - 1; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < ans; i++) sb.append(arr[i] <= q ? "1" : "0"); for (int i = ans; i < n; i++) sb.append("1"); out.println(sb.toString()); } private static void preprocess() throws IOException { } // cd C:\Users\Eshan Bhatt\Visual Studio Code\Competitive Programming\CodeForces // javac CodeForces.java && java CodeForces // change Stack size -> java -Xss16M CodeForces.java // ==================== CUSTOM CLASSES ================================ static class Pair implements Comparable<Pair> { int first, second; Pair(int f, int s) { first = f; second = s; } public int compareTo(Pair o) { if (this.first == o.first) return this.second - o.second; return this.first - o.first; } @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) return false; if (this.getClass() != obj.getClass()) return false; Pair other = (Pair) (obj); if (this.first != other.first) return false; if (this.second != other.second) return false; return true; } @Override public int hashCode() { return this.first ^ this.second; } @Override public String toString() { return this.first + " " + this.second; } } static class DequeNode { DequeNode prev, next; int val; DequeNode(int val) { this.val = val; } DequeNode(int val, DequeNode prev, DequeNode next) { this.val = val; this.prev = prev; this.next = next; } } // ======================= FOR INPUT ================================== private static void input() { FileInputStream instream = null; PrintStream outstream = null; try { instream = new FileInputStream(INPUT); outstream = new PrintStream(new FileOutputStream(OUTPUT)); System.setIn(instream); System.setOut(outstream); } catch (Exception e) { System.err.println("Error Occurred."); } BR = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } static String next() throws IOException { while (ST == null || !ST.hasMoreTokens()) ST = new StringTokenizer(readLine()); return ST.nextToken(); } static long readLong() throws IOException { return Long.parseLong(next()); } static int readInt() throws IOException { return Integer.parseInt(next()); } static double readDouble() throws IOException { return Double.parseDouble(next()); } static char readCharacter() throws IOException { return next().charAt(0); } static String readString() throws IOException { return next(); } static String readLine() throws IOException { return BR.readLine().trim(); } static int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = readInt(); return arr; } static int[][] read2DIntArray(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) arr[i] = readIntArray(m); return arr; } static List<Integer> readIntList(int n) throws IOException { List<Integer> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(readInt()); return list; } static long[] readLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = readLong(); return arr; } static long[][] read2DLongArray(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) arr[i] = readLongArray(m); return arr; } static List<Long> readLongList(int n) throws IOException { List<Long> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(readLong()); return list; } static char[] readCharArray() throws IOException { return readString().toCharArray(); } static char[][] readMatrix(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) mat[i] = readCharArray(); return mat; } // ========================= FOR OUTPUT ================================== private static void printIList(List<Integer> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printLList(List<Long> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printIArray(int[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DIArray(int[][] arr) { for (int i = 0; i < arr.length; i++) printIArray(arr[i]); } private static void printLArray(long[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DLArray(long[][] arr) { for (int i = 0; i < arr.length; i++) printLArray(arr[i]); } private static void yes() { out.println("YES"); } private static void no() { out.println("NO"); } // ====================== TO CHECK IF STRING IS NUMBER ======================== private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static boolean isLong(String s) { try { Long.parseLong(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } // ==================== FASTER SORT ================================ private static void sort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void reverseSort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void sort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void reverseSort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // ==================== MATHEMATICAL FUNCTIONS =========================== private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static int mod_pow(long a, long b, int mod) { if (b == 0) return 1; int temp = mod_pow(a, b >> 1, mod); temp %= mod; temp = (int) ((1L * temp * temp) % mod); if ((b & 1) == 1) temp = (int) ((1L * temp * a) % mod); return temp; } private static long multiply(long a, long b) { return (((a % mod) * (b % mod)) % mod); } private static long divide(long a, long b) { return multiply(a, mod_pow(b, mod - 2, mod)); } private static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } private static long nCr(long n, long r) { if (n - r > r) r = n - r; long ans = 1L; for (long i = r + 1; i <= n; i++) ans *= i; for (long i = 2; i <= n - r; i++) ans /= i; return ans; } private static List<Integer> factors(int n) { List<Integer> list = new ArrayList<>(); for (int i = 1; 1L * i * i <= n; i++) if (n % i == 0) { list.add(i); if (i != n / i) list.add(n / i); } return list; } private static List<Long> factors(long n) { List<Long> list = new ArrayList<>(); for (long i = 1; i * i <= n; i++) if (n % i == 0) { list.add(i); if (i != n / i) list.add(n / i); } return list; } // ==================== Primes using Seive ===================== private static List<Integer> getPrimes(int n) { boolean[] prime = new boolean[n + 1]; Arrays.fill(prime, true); for (int i = 2; 1L * i * i <= n; i++) if (prime[i]) for (int j = i * i; j <= n; j += i) prime[j] = false; // return prime; List<Integer> list = new ArrayList<>(); for (int i = 2; i <= n; i++) if (prime[i]) list.add(i); return list; } private static int[] SeivePrime(int n) { int[] primes = new int[n]; for (int i = 0; i < n; i++) primes[i] = i; for (int i = 2; 1L * i * i < n; i++) { if (primes[i] != i) continue; for (int j = i * i; j < n; j += i) if (primes[j] == j) primes[j] = i; } return primes; } // ==================== STRING FUNCTIONS ================================ private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } // check if a is subsequence of b private static boolean isSubsequence(String a, String b) { int idx = 0; for (int i = 0; i < b.length() && idx < a.length(); i++) if (a.charAt(idx) == b.charAt(i)) idx++; return idx == a.length(); } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } private static String sortString(String str) { int[] arr = new int[256]; for (char ch : str.toCharArray()) arr[ch]++; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 256; i++) while (arr[i]-- > 0) sb.append((char) i); return sb.toString(); } // ==================== LIS & LNDS ================================ private static int LIS(int arr[], int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find1(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find1(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) >= val) { ret = mid; j = mid - 1; } else { i = mid + 1; } } return ret; } private static int LNDS(int[] arr, int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find2(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find2(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) <= val) { i = mid + 1; } else { ret = mid; j = mid - 1; } } return ret; } // =============== Lower Bound & Upper Bound =========== // less than or equal private static int lower_bound(List<Integer> list, int val) { int ans = -1, lo = 0, hi = list.size() - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } private static int lower_bound(List<Long> list, long val) { int ans = -1, lo = 0, hi = list.size() - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } private static int lower_bound(int[] arr, int val) { int ans = -1, lo = 0, hi = arr.length - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } private static int lower_bound(long[] arr, long val) { int ans = -1, lo = 0, hi = arr.length - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } // greater than or equal private static int upper_bound(List<Integer> list, int val) { int ans = list.size(), lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } private static int upper_bound(List<Long> list, long val) { int ans = list.size(), lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } private static int upper_bound(int[] arr, int val) { int ans = arr.length, lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } private static int upper_bound(long[] arr, long val) { int ans = arr.length, lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } // ==================== UNION FIND ===================== private static int find(int x, int[] parent) { if (parent[x] == x) return x; return parent[x] = find(parent[x], parent); } private static boolean union(int x, int y, int[] parent, int[] rank) { int lx = find(x, parent), ly = find(y, parent); if (lx == ly) return false; if (rank[lx] > rank[ly]) parent[ly] = lx; else if (rank[lx] < rank[ly]) parent[lx] = ly; else { parent[lx] = ly; rank[ly]++; } return true; } // ==================== TRIE ================================ static class Trie { class Node { Node[] children; boolean isEnd; Node() { children = new Node[26]; } } Node root; Trie() { root = new Node(); } void insert(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) curr.children[ch - 'a'] = new Node(); curr = curr.children[ch - 'a']; } curr.isEnd = true; } boolean find(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) return false; curr = curr.children[ch - 'a']; } return curr.isEnd; } } // ================== SEGMENT TREE (RANGE SUM & RANGE UPDATE) ================== public static class SegmentTree { int n; long[] arr, tree, lazy; SegmentTree(long arr[]) { this.arr = arr; this.n = arr.length; this.tree = new long[(n << 2)]; this.lazy = new long[(n << 2)]; build(1, 0, n - 1); } void build(int id, int start, int end) { if (start == end) tree[id] = arr[start]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; build(left, start, mid); build(right, mid + 1, end); tree[id] = tree[left] + tree[right]; } } void update(int l, int r, long val) { update(1, 0, n - 1, l, r, val); } void update(int id, int start, int end, int l, int r, long val) { distribute(id, start, end); if (end < l || r < start) return; if (start == end) tree[id] += val; else if (l <= start && end <= r) { lazy[id] += val; distribute(id, start, end); } else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; update(left, start, mid, l, r, val); update(right, mid + 1, end, l, r, val); tree[id] = tree[left] + tree[right]; } } long query(int l, int r) { return query(1, 0, n - 1, l, r); } long query(int id, int start, int end, int l, int r) { if (end < l || r < start) return 0L; distribute(id, start, end); if (start == end) return tree[id]; else if (l <= start && end <= r) return tree[id]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; return query(left, start, mid, l, r) + query(right, mid + 1, end, l, r); } } void distribute(int id, int start, int end) { if (start == end) tree[id] += lazy[id]; else { tree[id] += lazy[id] * (end - start + 1); lazy[(id << 1)] += lazy[id]; lazy[(id << 1) + 1] += lazy[id]; } lazy[id] = 0; } } // ==================== FENWICK TREE ================================ static class FT { int n; int[] arr; int[] tree; FT(int[] arr, int n) { this.arr = arr; this.n = n; this.tree = new int[n + 1]; for (int i = 1; i <= n; i++) { update(i, arr[i - 1]); } } FT(int n) { this.n = n; this.tree = new int[n + 1]; } // 1 based indexing void update(int idx, int val) { while (idx <= n) { tree[idx] += val; idx += idx & -idx; } } // 1 based indexing int query(int l, int r) { return getSum(r) - getSum(l - 1); } int getSum(int idx) { int ans = 0; while (idx > 0) { ans += tree[idx]; idx -= idx & -idx; } return ans; } } // ==================== BINARY INDEX TREE ================================ static class BIT { long[][] tree; int n, m; BIT(int[][] mat, int n, int m) { this.n = n; this.m = m; tree = new long[n + 1][m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { update(i, j, mat[i - 1][j - 1]); } } } void update(int x, int y, int val) { while (x <= n) { int t = y; while (t <= m) { tree[x][t] += val; t += t & -t; } x += x & -x; } } long query(int x1, int y1, int x2, int y2) { return getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1); } long getSum(int x, int y) { long ans = 0L; while (x > 0) { int t = y; while (t > 0) { ans += tree[x][t]; t -= t & -t; } x -= x & -x; } return ans; } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
45058003229db7ebd8ae955609bca548
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.Scanner; public class Solution{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t-- > 0){ int n = scanner.nextInt(); int iq = scanner.nextInt(); int[] tests = new int[n]; for(int i = 0 ; i < n ; i++) tests[i] = scanner.nextInt(); StringBuilder ans = new StringBuilder(); int nq = 0; for(int i = n - 1 ; i >= 0 ; i--){ if(tests[i] <= nq) ans.append('1'); else if (nq < iq){ ans.append('1'); nq++; }else ans.append(0); } System.out.println(ans.reverse()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
c7c056980c4412ac3e199efe97faf0b2
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.Scanner; public class Solution{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t-- > 0){ int n = scanner.nextInt(); int iq = scanner.nextInt(); int[] tests = new int[n]; for(int i = 0 ; i < n ; i++) tests[i] = scanner.nextInt(); StringBuilder ans = new StringBuilder(); int l = 0 , h = n - 1; while(l <= h){ int mid = (l + (h - l) / 2); StringBuilder x = new StringBuilder(); if(check(tests, mid, iq, x)) { h = mid - 1; ans = x; } else l = mid + 1; } System.out.println(ans); } } private static boolean check(int[] tests, int mid, int iq, StringBuilder ans) { for(int i = 0; i < mid ; i++) { if (tests[i] <= iq) ans.append('1'); else ans.append('0'); } for(int i = mid ; i < tests.length ; i++){ ans.append('1'); if(iq == 0) return false; if(tests[i] > iq) iq--; } return true; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
df6bf787e1c10f60870a63e40f57bb5c
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
// 20:18 ; 2'50" ; %%I02V2L4L // import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class C { static class pair implements Comparable<pair> { int a; int b; pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(pair o) { return this.a - o.a; } } static HashMap<String, Integer> dp; static boolean vis[]; static int n, a[]; public static void main(String[] args) { FastScanner sc = new FastScanner(); int tt = sc.nextInt(); while (tt-- > 0) { n = sc.nextInt(); int q = sc.nextInt(); a = sc.readArray(n); char ca[] = new char[n]; int iq = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] <= iq) { ca[i] = '1'; } else if (iq == q) { ca[i] = '0'; } else if (a[i] > iq) { iq++; ca[i] = '1'; } } for (char e : ca) { System.out.print(e); } System.out.println(); } } static void sort(int[] a) { // ruffle int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n), temp = a[i]; a[i] = a[oi]; a[oi] = temp; } // then sort Arrays.sort(a); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } String str = ""; String nextLine() { try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static final int mod = 1_000_000_000 + 7; static final int max_val = 2147483647; static final int min_val = max_val + 1; static long fastPow(long base, long exp) { if (exp == 0) return 1; long half = fastPow(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } static long mul(long a, long b) { return a * b % mod; } static int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } static int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } // a -> z == 97 -> 122 // String.format("%.9f", ans) ,--> to get upto 9 decimal places , (ans is // double) }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
cce268f39964f8f84ef6f8d8c23f8c0b
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int A = scn.nextInt(); StringBuilder sb = new StringBuilder(""); while(A-- > 0) { int n = scn.nextInt(); int q = scn.nextInt(); int[] arr = new int[n]; for(int i=0 ; i<n ; i++) arr[i] = scn.nextInt(); int[] ans = new int[n]; int Q = 0; for(int i=n-1 ; i>=0 ; i--) { if(arr[i] <= Q) ans[i] = 1; else if(arr[i] > Q && Q < q) { ans[i] = 1; Q++; } else ans[i] = 0; } for(int v : ans) sb.append(v); sb.append("\n"); } System.out.println(sb); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
0b755b44031b0eb5877725801d91bf89
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.lang.*; public class Solution{ static int mod=(int)1e9+7; static int mod1=998244353; static FastScanner sc = new FastScanner(); public static void solve() { int n=sc.nextInt(); int q=sc.nextInt(); int[] a=sc.readArray(n); char[] c=new char[n]; int curr=0; for (int i=n-1;i>=0;i--) { if (a[i]<=curr) { c[i]='1'; }else{ if (curr<q) { curr++; c[i]='1'; }else{ c[i]='0'; } } } System.out.println(new String(c)); } public static void main(String[] args) { int t = sc.nextInt(); // int t=1; outer: for (int tt = 0; tt < t; tt++) { solve(); } } static int[] leftRotate(int arr[], int n, int k) { int[] b=new int[n]; int mod = k % n; for (int i = 0; i < n; ++i) b[i]=arr[(i + mod) % n] ; return b; } static boolean isSubSequence(String str1, String str2, int m, int n) { int j = 0; for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == str2.charAt(i)) j++; return (j == m); } static int reverseDigits(int num) { int rev_num = 0; while (num > 0) { rev_num = rev_num * 10 + num % 10; num = num / 10; } return rev_num; } /* Function to check if n is Palindrome*/ static boolean isPalindrome(int n) { // get the reverse of n int rev_n = reverseDigits(n); // Check if rev_n and n are same or not. if (rev_n == n) return true; else return false; } static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static int[] LPS(String s){ int[] lps=new int[s.length()]; int i=0,j=1; while (j<s.length()) { if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; j++; continue; }else{ if (i==0) { j++; continue; } i=lps[i-1]; while(s.charAt(i)!=s.charAt(j) && i!=0) { i=lps[i-1]; } if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; } j++; } } return lps; } static long getPairsCount(int n, double sum,int[] arr) { HashMap<Double, Integer> hm = new HashMap<>(); for (int i = 0; i < n; i++) { if (!hm.containsKey((double)arr[i])) hm.put((double)arr[i], 0); hm.put((double)arr[i], hm.get((double)arr[i]) + 1); } long twice_count = 0; for (int i = 0; i < n; i++) { if (hm.get(sum - arr[i]) != null) twice_count += hm.get(sum - arr[i]); if (sum - (double)arr[i] == (double)arr[i]) twice_count--; } return twice_count / 2l; } static boolean[] sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } prime[1]=false; return prime; } static long power(long x, long y, long p) { long res = 1l; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y>>=1; x = (x * x) % p; } return res; } public static int log2(int N) { int result = (int)(Math.log(N) / Math.log(2)); return result; } //////////////////////////////////////////////////////////////////////////////////// ////////////////////DO NOT READ AFTER THIS LINE ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// static long modFact(int n, int p) { if (n >= p) return 0; long result = 1l; for (int i = 2; i <= n; i++) result = (result * i) % p; return result; } static boolean isPalindrom(char[] arr, int i, int j) { boolean ok = true; while (i <= j) { if (arr[i] != arr[j]) { ok = false; break; } i++; j--; } return ok; } static int max(int a, int b) { return Math.max(a, b); } static int min(int a, int b) { return Math.min(a, b); } static long max(long a, long b) { return Math.max(a, b); } static long min(long a, long b) { return Math.min(a, b); } static int abs(int a) { return Math.abs(a); } static long abs(long a) { return Math.abs(a); } static void swap(long arr[], int i, int j) { long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int arr[], int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static int maxArr(int arr[]) { int maxi = Integer.MIN_VALUE; for (int x : arr) maxi = max(maxi, x); return maxi; } static int minArr(int arr[]) { int mini = Integer.MAX_VALUE; for (int x : arr) mini = min(mini, x); return mini; } static long maxArr(long arr[]) { long maxi = Long.MIN_VALUE; for (long x : arr) maxi = max(maxi, x); return maxi; } static long minArr(long arr[]) { long mini = Long.MAX_VALUE; for (long x : arr) mini = min(mini, x); return mini; } static int lcm(int a,int b){ return (int)(((long)a*b)/(long)gcd(a,b)); } static long lcm(long a,long b){ return ((a*b)/(long)gcd(a,b)); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } public static int binarySearch(int a[], int target) { int left = 0; int right = a.length - 1; int mid = (left + right) / 2; int i = 0; while (left <= right) { if (a[mid] <= target) { i = mid + 1; left = mid + 1; } else { right = mid - 1; } mid = (left + right) / 2; } return i-1; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] read2dArray(int n, int m) { int arr[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = nextInt(); } } return arr; } ArrayList<Integer> readArrayList(int n) { ArrayList<Integer> arr = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { int a = nextInt(); arr.add(a); } return arr; } long nextLong() { return Long.parseLong(next()); } } static class Pair{ int first, second; Pair(int f, int s){ first = f; second = s; } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
60cc5536343dae82a11eee9857c33349
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
//package com.rajan.codeforces.contests.contest808; import java.io.*; import java.util.Arrays; public class ProblemC { private static int[] choose, a; private static int q, n; public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); int tt = Integer.parseInt(reader.readLine()); while (tt-- > 0) { int[] input = parseInt(reader.readLine(), 2); n = input[0]; q = input[1]; a = parseInt(reader.readLine(), n); choose = new int[n]; int max = -1; for (int item : a) max = Math.max(max, item); if (max <= q || q >= n) { for (int i = 0; i < n; i++) writer.write("1"); writer.write("\n"); } else { int l = 0, r = n - 1; while (l <= r) { int m = l + (r - l) / 2; if (check(m)) r = m - 1; else l = m + 1; } check(r + 1); for (int i = 0; i < n; i++) writer.write(choose[i] + ""); writer.write("\n"); } } writer.flush(); } private static boolean check(int mid) { Arrays.fill(choose, 0); int iq = q; for (int i = 0; i < mid; i++) choose[i] = a[i] <= iq ? 1 : 0; for (int i = mid; i < n; i++) { choose[i] = 1; if (iq <= 0) return false; if (a[i] > iq) iq--; } if (iq < 0) return false; return true; } private static int[] parseInt(String str, int n) { int[] ans = new int[n]; int idx = 0; for (int k = 0; k < str.length(); ) { int j = k; int sum = 0; while (j < str.length() && str.charAt(j) != ' ') { if (str.charAt(j) == '-') { j++; continue; } sum = sum * 10 + str.charAt(j) - '0'; j++; } ans[idx++] = (str.charAt(k) == '-' ? -1 : 1) * sum; k = j + 1; } return ans; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
de90412bdd76ed68f26ad112f2f5c7cf
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner scn = new Scanner(System.in); int tc = scn.nextInt(); while (tc != 0) { int n = scn.nextInt(); int q = scn.nextInt(); int[] arr = new int[n + 1]; for (int i = 1 ; i <= n ; i++) { arr[i] = scn.nextInt(); } solve(n, q, arr); tc--; } } public static void solve(int n, int q, int[] arr) { int[] ans = new int[n + 1]; int current = 0; for (int i = n ; i >= 1 ; i--) { if (current < arr[i]) { if (current < q) { current++; ans[i] = 1; } else { ans[i] = 0; } } else { ans[i] = 1; } } for (int i = 1 ; i <= n ; i++) { System.out.print(ans[i]); } System.out.println(); return; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
6407ee2309a5757892c728415382730b
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static long mod = (int)1e9+7; // static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc =new FastReader(); int t=sc.nextInt(); // int t=1; while(t-->0) { int n = sc.nextInt(); int q = sc.nextInt(); int arr[] = sc.readArray(n); int ans[] = new int[n]; int ok = 0; for(int i=n-1;i>=0;i--) { if(ok < q || arr[i] <= ok) { ans[i] = 1; if(arr[i] > ok) { ok++; } } } for(int x:ans) { System.out.print(x); } System.out.println(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } static class FenwickTree { //Binary Indexed Tree //1 indexed public int[] tree; public int size; public FenwickTree(int size) { this.size = size; tree = new int[size+5]; } public void add(int i, int v) { while(i <= size) { tree[i] += v; i += i&-i; } } public int find(int i) { int res = 0; while(i >= 1) { res += tree[i]; i -= i&-i; } return res; } public int find(int l, int r) { return find(r)-find(l-1); } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } private static long mergeAndCount(int[] arr, int l, int m, int r) { // Left subarray int[] left = Arrays.copyOfRange(arr, l, m + 1); // Right subarray int[] right = Arrays.copyOfRange(arr, m + 1, r + 1); int i = 0, j = 0, k = l;long swaps = 0; while (i < left.length && j < right.length) { if (left[i] < right[j]) arr[k++] = left[i++]; else { arr[k++] = right[j++]; swaps += (m + 1) - (l + i); } } while (i < left.length) arr[k++] = left[i++]; while (j < right.length) arr[k++] = right[j++]; return swaps; } // Merge sort function private static long mergeSortAndCount(int[] arr, int l, int r) { // Keeps track of the inversion count at a // particular node of the recursion tree long count = 0; if (l < r) { int m = (l + r) / 2; // Total inversion count = left subarray count // + right subarray count + merge count // Left subarray count count += mergeSortAndCount(arr, l, m); // Right subarray count count += mergeSortAndCount(arr, m + 1, r); // Merge count count += mergeAndCount(arr, l, m, r); } return count; } static void my_sort(long[] arr) { ArrayList<Long> list = new ArrayList<>(); for(int i=0;i<arr.length;i++) { list.add(arr[i]); } Collections.sort(list); for(int i=0;i<arr.length;i++) { arr[i] = list.get(i); } } static void reverse_sorted(int[] arr) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<arr.length;i++) { list.add(arr[i]); } Collections.sort(list , Collections.reverseOrder()); for(int i=0;i<arr.length;i++) { arr[i] = list.get(i); } } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value int l=-1,r=list.size(); while(l+1<r) { int m=(l+r)>>>1; if(list.get(m)<=x) l=m; else r=m; } return l+1; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static class Queue_Pair implements Comparable<Queue_Pair> { int first , second; public Queue_Pair(int first, int second) { this.first=first; this.second=second; } public int compareTo(Queue_Pair o) { return Integer.compare(o.first, first); } } static void leftRotate(int arr[], int d, int n) { for (int i = 0; i < d; i++) leftRotatebyOne(arr, n); } static void leftRotatebyOne(int arr[], int n) { int i, temp; temp = arr[0]; for (i = 0; i < n - 1; i++) arr[i] = arr[i + 1]; arr[n-1] = temp; } static boolean isPalindrome(String str) { // Pointers pointing to the beginning // and the end of the string int i = 0, j = str.length() - 1; // While there are characters to compare while (i < j) { // If there is a mismatch if (str.charAt(i) != str.charAt(j)) return false; // Increment first pointer and // decrement the other i++; j--; } // Given string is a palindrome return true; } static boolean palindrome_array(char arr[], int n) { // Initialise flag to zero. int flag = 0; // Loop till array size n/2. for (int i = 0; i <= n / 2 && n != 0; i++) { // Check if first and last element are different // Then set flag to 1. if (arr[i] != arr[n - i - 1]) { flag = 1; break; } } // If flag is set then print Not Palindrome // else print Palindrome. if (flag == 1) return false; else return true; } static boolean allElementsEqual(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]==arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } static boolean allElementsDistinct(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]!=arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } public static void reverse(int[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily int temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } public static void reverse_Long(long[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily long temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } static boolean isReverseSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] < a[i + 1]) { return false; } } return true; } static int[] rearrangeEvenAndOdd(int arr[], int n) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); int[] array = list.stream().mapToInt(i->i).toArray(); return array; } static long[] rearrangeEvenAndOddLong(long arr[], int n) { ArrayList<Long> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); long[] array = list.stream().mapToLong(i->i).toArray(); return array; } static boolean isPrime(long n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (long i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static long getSum(long n) { long sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcdLong(long a, long b) { if (b == 0) return a; return gcdLong(b, a % b); } static void swap(int i, int j) { int temp = i; i = j; j = temp; } static int countDigit(int n) { return (int)Math.floor(Math.log10(n) + 1); } } class Pair { int first; int second; Pair(int first , int second) { this.first = first; this.second = second; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
90e93690149c88da582a9ae3f6f5887e
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Queue; import java.util.Scanner; import java.util.StringTokenizer; public class Problem3 { static class Pair{ boolean took; int change; int count; public Pair(boolean t, int ch, int c) { took = t; change = ch; count = c; } } public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(in.readLine()); for(int i = 0; i<t; i++) { StringTokenizer st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int q = Integer.parseInt(st.nextToken()); int[] nums = new int[n]; st = new StringTokenizer(in.readLine()); for(int j = 0; j<n; j++) { nums[j] = Integer.parseInt(st.nextToken()); } System.out.println(solve(nums,n,q)); } } public static String solve(int[] nums, int n, int q) { StringBuilder s = new StringBuilder(); int currentIQ = 1; s.append(1); for(int i = n-2; i>=0; i--) { if(currentIQ == q) { if(nums[i]<=currentIQ) { s.append(1); } else s.append(0); } else { if(nums[i]<=currentIQ) { s.append(1); } else { currentIQ++; s.append(1); } } } return s.reverse().toString(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
c7b0010a62febdea3ef3c94fc74d4b06
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); MyReader in = new MyReader(); int t = in.nextInt(); for (int i = 1; i < t+1; i++) { int n = in.nextInt(); int q = in.nextInt(); int[] ar = new int[n]; for (int j = 0; j < n; j++) { ar[j] = in.nextInt(); } LinkedList<Integer> soln = new LinkedList<>(); int after = 0; for (int k = n-1; k >= 0; k--) { if (after == q) { if (ar[k] <= after) { soln.addFirst(1); } else { soln.addFirst(0); } } else { soln.addFirst(1); if (ar[k] > after) { after++; } } } for (int l = 0; l < n-1; l++) { out.print(soln.poll()); } out.println(soln.poll()); } out.flush(); } public static class MyReader { private BufferedReader br; private StringTokenizer st; public MyReader() { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } public String next() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(this.next()); } public long nextLong() throws IOException { return Long.parseLong(this.next()); } public double nextDouble() throws IOException { return Double.parseDouble(this.next()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
47839cd477914df970b5562ffcbe9345
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class Problem_C { static FastReader scan; public static void main(String[] args) throws Exception{ scan = new FastReader(); int tests = scan.nextInt(); boolean db = false; if(tests == 0){ db = true; tests = 100; } BufferedWriter print = new BufferedWriter(new OutputStreamWriter(System.out)); for(int testNum = 0; testNum < tests; testNum++){ solve(testNum, scan, print, db); print.flush(); System.out.flush(); } print.close(); } public static void solve(int testNum, FastReader scan, BufferedWriter print, boolean db) throws Exception{ int n = scan.nextInt(); int q = scan.nextInt(); List<Integer> nums = readList(n, scan); Map<Integer, Integer> lastDifficulty = new HashMap(); for (int i = 0; i < n; i++) { lastDifficulty.put(nums.get(i), i); } int[] sweepIQ = new int[n]; int neededIQ = 1; for (int i = n-1; i >= 0; i--) { if(i == n-1){ sweepIQ[i] = neededIQ; } else{ if(nums.get(i) > neededIQ){ neededIQ += 1; } sweepIQ[i] = neededIQ; } } int curIQ = q; List<Boolean> take = new ArrayList<>(); for (int i = 0; i < n; i++) { if(curIQ <= 0){ take.add(false); continue; } if(curIQ >= sweepIQ[i]){ take.add(true); continue; } if(nums.get(i) <= curIQ){ take.add(true); continue; } boolean laterTest = false; if(lastDifficulty.containsKey(curIQ)){ if(lastDifficulty.get(curIQ) > i){ //after this test laterTest = true; } } if(laterTest){ //dont do it take.add(false); } else{ //take the bullet curIQ -= 1; take.add(true); } } for(boolean b : take){ if(b) print.write("1"); else print.write("0"); } //if(db) System.out.println("debug?"); print.write("\n"); } //PREWRITTEN FUNCTIONS public static void writeList(BufferedWriter print, int[] arr) throws Exception{ for (int i = 0; i < arr.length; i++) { if(i < arr.length-1) print.write(arr[i] + " "); else print.write(arr[i] + ""); } } public static void writeList(BufferedWriter print, List<Integer> arr) throws Exception{ for (int i = 0; i < arr.size(); i++) { if(i < arr.size()-1) print.write(arr.get(i) + " "); else print.write(arr.get(i) + ""); } } public static List<Integer> readList(int n, FastReader scan){ List<Integer> res = new ArrayList<Integer>(); for(int i = 0; i < n; i++){ int next = scan.nextInt(); res.add(next); } return res; } public List<List<Integer>> read2DListSpace(int r, int c, FastReader scan){ List<List<Integer>> list2d = new ArrayList<>(); for(int i = 0; i < r; i++){ List<Integer> curRow = new ArrayList<>(); for(int j = 0; j < c; j++){ int next = scan.nextInt(); curRow.add(next); } list2d.add(curRow); } return list2d; } //FastReader from https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/ //i really should switch to c++ but i keep finding things like this to convince myself Java is fast enough lol static class FastReader { BufferedReader br; StringTokenizer st; static boolean customInput = false; static List<String> queue; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); queue = new LinkedList<>(); customInput = false; } public static void setInputMode(boolean custom){ customInput = custom; } public static void addToQueue(String item){ queue.add(item); } String next() { if(customInput){ String str = queue.get(0); queue.remove(0); return str; } else{ while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
1ad64a5215a18b3c135e8e143821304e
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; public final class doremyiq { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int iq = sc.nextInt(); int[] a = new int[n]; int[] ans = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int nq = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] <= nq) { ans[i] = 1; } else if (nq < iq) { ans[i] = 1; nq++; } else ans[i] = 0; } for (int i = 0; i < n; i++) { System.out.print(ans[i]); } System.out.println(); } sc.close(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
cfe46d908dd66df0e0fdd6ef1676b957
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
//package com.example.practice.codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.StringTokenizer; public class Solution { public static void main (String [] args) throws IOException { // Use BufferedReader rather than RandomAccessFile; it's much faster final BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); // input file name goes above int Q = Integer.parseInt(input.readLine()); while (Q > 0) { StringTokenizer st = new StringTokenizer(input.readLine()); int n = Integer.parseInt(st.nextToken()), q = Integer.parseInt(st.nextToken()); int[] ns = readArrayInt(n, input); out.println(calc(n, q, ns)); Q--; } out.close(); // close the output file } private static String calc(final int n, final int q, final int[] ns) { char[] res = new char[n]; int[] mins = new int[n]; mins[n-1] = 1; for (int i=n-2;i>=0;--i){ if (ns[i] <= mins[i+1]){ mins[i] = mins[i+1]; }else { mins[i] = Math.min(mins[i+1] + 1, q); } } int q2 = q; for (int i=0;i<n && q2>0;++i){ if (ns[i] <= q2){ res[i] = '1'; }else if (i+1==n || q2-1 >= mins[i+1]){ res[i] = '1'; q2--; }else { res[i] = '0'; } } return new String(res); } private static void printArray(long[] ns, final PrintWriter out){ for (int i=0;i<ns.length;++i){ out.print(ns[i]); if (i+1<ns.length)out.print(" "); else out.println(); } } private static void printArrayInt(int[] ns, final PrintWriter out){ for (int i=0;i<ns.length;++i){ out.print(ns[i]); if (i+1<ns.length)out.print(" "); else out.println(); } } private static void printArrayVertical(long[] ns, final PrintWriter out){ for (long a : ns){ out.println(a); } } private static void printArrayVerticalInt(int[] ns, final PrintWriter out){ for (int a : ns){ out.println(a); } } private static void printArray2D(long[][] ns, final int len, final PrintWriter out){ int cnt = 0; for (long[] kk : ns){ cnt++; if (cnt > len)break; for (int i=0;i<kk.length;++i){ out.print(kk[i]); if (i+1<kk.length)out.print(" "); else out.println(); } } } private static void printArray2DInt(int[][] ns, final int len, final PrintWriter out){ int cnt = 0; for (int[] kk : ns){ cnt++; if (cnt > len)break; for (int i=0;i<kk.length;++i){ out.print(kk[i]); if (i+1<kk.length)out.print(" "); else out.println(); } } } private static long[] readArray(final int n, final BufferedReader input) throws IOException{ long[] ns = new long[n]; StringTokenizer st = new StringTokenizer(input.readLine()); for (int i=0;i<n;++i){ ns[i] = Long.parseLong(st.nextToken()); } return ns; } private static int[] readArrayInt(final int n, final BufferedReader input) throws IOException{ int[] ns = new int[n]; StringTokenizer st = new StringTokenizer(input.readLine()); for (int i=0;i<n;++i){ ns[i] = Integer.parseInt(st.nextToken()); } return ns; } private static long[] readArrayVertical(final int n, final BufferedReader input) throws IOException{ long[] ns = new long[n]; for (int i=0;i<n;++i){ ns[i] = Long.parseLong(input.readLine()); } return ns; } private static int[] readArrayVerticalInt(final int n, final BufferedReader input) throws IOException{ int[] ns = new int[n]; for (int i=0;i<n;++i){ ns[i] = Integer.parseInt(input.readLine()); } return ns; } private static long[][] readArray2D(final int n, final int len, final BufferedReader input) throws IOException{ long[][] ns = new long[len][]; for (int i=0;i<n;++i){ StringTokenizer st = new StringTokenizer(input.readLine()); ArrayList<Long> al = new ArrayList<>(); while (st.hasMoreTokens()){ al.add(Long.parseLong(st.nextToken())); } long[] kk = new long[al.size()]; for (int j=0;j<kk.length;++j){ kk[j] = al.get(j); } ns[i] = kk; } return ns; } private static int[][] readArray2DInt(final int n, final int len, final BufferedReader input) throws IOException{ int[][] ns = new int[len][]; for (int i=0;i<n;++i){ StringTokenizer st = new StringTokenizer(input.readLine()); ArrayList<Integer> al = new ArrayList<>(); while (st.hasMoreTokens()){ al.add(Integer.parseInt(st.nextToken())); } int[] kk = new int[al.size()]; for (int j=0;j<kk.length;++j){ kk[j] = al.get(j); } ns[i] = kk; } return ns; } static class SegTree{ int st; int en; int mid; int val1; int val2; SegTree left; SegTree right; public SegTree(int l, int r, int d){ st = l; en = r; mid = (st + en) >> 1; val1 = val2 = d; if (st<en){ left = new SegTree(st, mid, d); right = new SegTree(mid+1, en, d); }else { left = right = null; } } public SegTree(int l, int r, int[] ns){ st = l; en = r; mid = (st + en) >> 1; if (st==en){ val1 = val2 = ns[st]; }else { left = new SegTree(l, mid, ns); right = new SegTree(mid+1, r, ns); val1 = Math.min(left.val1, right.val1); val2 = Math.max(left.val2, right.val2); } } void update(int idx, int v){ if (st==en){ val1 = val2 = v; }else { if (idx <= mid){ left.update(idx, v); }else { right.update(idx, v); } val1 = Math.min(left.val1, right.val1); val2 = Math.max(left.val2, right.val2); } } int getMin(int l, int r){ if (st==en || (l==st && r==en))return val1; if (r<=mid){ return left.getMin(l, r); } if (l>mid){ return right.getMin(l, r); } return Math.min(left.getMin(l, mid), right.getMin(mid+1, r)); } int getMax(int l, int r){ if (st==en || (l==st && r==en))return val2; if (r<=mid){ return left.getMax(l, r); } if (l>mid){ return right.getMax(l, r); } return Math.max(left.getMax(l, mid), right.getMax(mid+1, r)); } } static class SparseTable{ int[][] minTable; int[][] maxTable; int[] log2; int n; public SparseTable(final int[] ns){ n = ns.length; int m = 0, pre = 0; while (1<<m < n){ m++; } m++; minTable = new int[n][m]; maxTable = new int[n][m]; log2 = new int[n+1]; for (int i=0;i<n;++i){ minTable[i][0] = ns[i]; maxTable[i][0] = ns[i]; if ((1<<(pre+1)) == i+1){ pre++; } log2[i+1] = pre; } for (int i=1;i<m;++i){ for (int j=0;j<n;++j){ int r = Math.min(n-1, j+(1<<i)-1); if (r-(1<<(i-1))+1 <= j){ minTable[j][i] = minTable[j][i-1]; maxTable[j][i] = maxTable[j][i-1]; }else { minTable[j][i] = Math.min(minTable[j][i-1], minTable[r-(1<<(i-1))+1][i-1]); maxTable[j][i] = Math.max(maxTable[j][i-1], maxTable[r-(1<<(i-1))+1][i-1]); } } } } int getMin(final int l, final int r){ int d = log2[r-l+1]; return Math.min(minTable[l][d], minTable[r-(1<<d)+1][d]); } int getMax(final int l, final int r){ int d = log2[r-l+1]; return Math.max(maxTable[l][d], maxTable[r-(1<<d)+1][d]); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
ea77f680a0c7a14d25bebdfd19437e3e
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class C_Doremy_s_IQ { public static void main(String[] args)throws Exception { new Solver().solve(); } } //* Success is not final, failure is not fatal: it is the courage to continue that counts. class Solver { void solve() throws Exception { int t = sc.nextInt(); while(t-->0){ int n =sc.nextInt(); long q = sc.nextLong(); // Binary Search on the ArrayList long[] arr = sc.getLongArray(n); ArrayList<Integer> Good = new ArrayList<>(); ArrayList<Integer> Bad = new ArrayList<>(); // we do a Binary Search and check if we can get the remaining elements all the remaiinin for(int i =0 ;i<n;i++){ //we are adding the index if(arr[i]>q){ // it is a goog Bad.add(i); }else{ Good.add(i); } } // do a binary Search on Bad array // System.out.println(Bad); int low = 0; int high = Bad.size()-1; int ans = n; while(low<=high){ int mid = (low+high)/2; long curq = q; boolean isPos = true; for(int i = Bad.get(mid);i<n;i++){ if(curq==0){ isPos = false; // break; } if(arr[i]>curq){ curq--; } } // if it is not possible move right if(isPos){ high = mid-1; ans = Bad.get(mid); }else{ low = mid+1; } } // System.out.println(ans); // just print the ans StringBuilder SB = new StringBuilder(); for(int i =0 ;i<ans;i++){ if(arr[i]<=q){ SB.append("1"); }else{ SB.append("0"); } } for(int i = ans;i<n;i++){ SB.append("1"); } System.out.println(SB.toString()); } sc.flush(); } final Helper sc; final int MAXN = 1000_006; final long MOD = (long) 1e9 + 7; Solver() { sc = new Helper(MOD, MAXN); sc.initIO(System.in, System.out); } } class Helper { final long MOD; final int MAXN; final Random rnd; public Helper(long mod, int maxn) { MOD = mod; MAXN = maxn; rnd = new Random(); } public static int[] sieve; public static ArrayList<Integer> primes; public void setSieve() { primes = new ArrayList<>(); sieve = new int[MAXN]; int i, j; for (i = 2; i*i < MAXN; ++i) if (sieve[i] == 0) { primes.add(i); for (j = i*i; j < MAXN; j += i) { sieve[j] = i; } } } public static long[] factorial; public void setFactorial() { factorial = new long[MAXN]; factorial[0] = 1; for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD; } public long getFactorial(int n) { if (factorial == null) setFactorial(); return factorial[n]; } public long ncr(int n, int r) { if (r > n) return 0; if (factorial == null) setFactorial(); long numerator = factorial[n]; long denominator = factorial[r] * factorial[n - r] % MOD; return numerator * pow(denominator, MOD - 2, MOD) % MOD; } public long[] getLongArray(int size) throws Exception { long[] ar = new long[size]; for (int i = 0; i < size; ++i) ar[i] = nextLong(); return ar; } public int[] getIntArray(int size) throws Exception { int[] ar = new int[size]; for (int i = 0; i < size; ++i) ar[i] = nextInt(); return ar; } public long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public long max(long[] ar) { long ret = ar[0]; for (long itr : ar) ret = Math.max(ret, itr); return ret; } public int max(int[] ar) { int ret = ar[0]; for (int itr : ar) ret = Math.max(ret, itr); return ret; } public long min(long[] ar) { long ret = ar[0]; for (long itr : ar) ret = Math.min(ret, itr); return ret; } public int min(int[] ar) { int ret = ar[0]; for (int itr : ar) ret = Math.min(ret, itr); return ret; } public long sum(long[] ar) { long sum = 0; for (long itr : ar) sum += itr; return sum; } public long sum(int[] ar) { long sum = 0; for (int itr : ar) sum += itr; return sum; } public void shuffle(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void shuffle(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public long pow(long base, long exp, long MOD) { base %= MOD; long ret = 1; while (exp > 0) { if ((exp & 1) == 1) ret = ret * base % MOD; base = base * base % MOD; exp >>= 1; } return ret; } static byte[] buf = new byte[1000_006]; static int index, total; static InputStream in; static BufferedWriter bw; public void initIO(InputStream is, OutputStream os) { try { in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); } catch (Exception e) { } } public void initIO(String inputFile, String outputFile) { try { in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputFile))); } catch (Exception e) { } } private int scan() throws Exception { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public String nextLine() throws Exception { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c >= 32; c = scan()) sb.append((char) c); return sb.toString(); } public String next() throws Exception { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) sb.append((char) c); return sb.toString(); } public int nextInt() throws Exception { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public long nextLong() throws Exception { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public void print(Object a) throws Exception { bw.write(a.toString()); } public void printsp(Object a) throws Exception { print(a); print(" "); } public void println() throws Exception { bw.write("\n"); } public void printArray(int[] arr) throws Exception{ for(int i = 0;i<arr.length;i++){ print(arr[i]+ " "); } println(); } public void println(Object a) throws Exception { print(a); println(); } public void flush() throws Exception { bw.flush(); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
40d8dbb9d63140d7f973d085ef98e0cd
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.*; import java.util.*; // whole solution public class new1{ static int mod = 998244353; public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader s = new FastReader(); int t = s.nextInt(); for(int z = 1; z <= t; z++) { int n = s.nextInt(); int q = s.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = s.nextInt(); int be = 0; int en = n; int ans = -1; while(be < en) { int mid = (be + en) / 2; int q1 = q; int i = 0; for(i = mid; i < n; i++) { if(arr[i] > q1) { q1--; } } if(q1 >= 0) { ans = mid; en = mid; } else { be = mid + 1; } } StringBuilder str = new StringBuilder(""); for(int i = 0; i < ans; i++) { if(arr[i] <= q) str = str.append("1"); else str = str.append("0"); } for(int i = ans; i < n; i++) str = str.append("1"); output.write(str + "\n"); } output.flush(); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }}
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
0497316a2e622689ce2493b9f9abf08f
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class Template { static int mod = 1000000007; public static void main(String[] args){ FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int yo = sc.nextInt(); while (yo-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] a = sc.readInts(n); int q1 = 0; StringBuilder sb = new StringBuilder(); for(int i = n-1; i >= 0; i--){ if(a[i] <= q1){ sb.append("1"); } else { if(q1 < q){ q1++; sb.append("1"); } else{ sb.append("0"); } } } sb = sb.reverse(); out.println(sb.toString()); } out.close(); } public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int N) { boolean[] sieve = new boolean[N + 1]; for (int i = 2; i <= N; i++) sieve[i] = true; for (int i = 2; i <= N; i++) { if (sieve[i]) { for (int j = 2 * i; j <= N; j += i) { sieve[j] = false; } } } return sieve; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } public static void print(int[] arr, PrintWriter out) { //for debugging only for (int x : arr) out.print(x + " "); out.println(); } public static int log2(int a){ return (int)(Math.log(a)/Math.log(2)); } public static long ceil(long x, long y){ return (x + 0l + y - 1) / y; } static class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream("input.txt"); // FileOutputStream out = new FileOutputStream("output.txt"); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
3772cf417fbdccfedacc00429da02252
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.util.*; import java.io.*; public class practise { static boolean multipleTC = true; final static int Mod = 1000000007; final static int Mod2 = 998244353; final double PI = 3.14159265358979323846; int MAX = 1000000007; void pre() throws Exception { } void DFSUtil(int v, boolean[] visited, ArrayList<Integer> al, List<Integer> adj[]) { visited[v] = true; al.add(v); // System.out.print(v + " "); Iterator<Integer> it = adj[v].iterator(); while (it.hasNext()) { int n = it.next(); if (!visited[n]) DFSUtil(n, visited, al, adj); } } void DFS(List<Integer> adj[], ArrayList<ArrayList<Integer>> components, int V) { boolean[] visited = new boolean[V]; for (int i = 0; i < V; i++) { ArrayList<Integer> al = new ArrayList<>(); if (!visited[i]) { DFSUtil(i, visited, al, adj); components.add(al); } } } long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a%b); } boolean check(List<Integer> list, long arr[], long q, int cnt, int req, int n) { if(cnt >= req) return true; int idx = req-cnt-1; int strtidx = list.get(idx); for(int i=strtidx;i<=n;i++) { if(arr[i] > q) q--; } if(q >= 0) return true; return false; } void solve(int t) throws Exception { int n = ni(); long q = nl(); long arr[] = new long[n+1]; List<Integer> list = new ArrayList<>(); int cnt = 0; for(int i=1;i<=n;i++) { arr[i] = nl(); if(arr[i] <= q) cnt++; } for(int i=n;i>=1;i--) { if(arr[i] > q) list.add(i); } int lo = 0, hi = n, succ = -1; while(lo <= hi) { int mid = lo + (hi - lo)/2; if(check(list, arr, q, cnt, mid, n)) { lo = mid+1; succ = mid; } else { hi = mid-1; } } StringBuilder ans = new StringBuilder(); int bn[] = new int[n+1]; succ -= cnt; for(int i=n;i>=1;i--) { if(arr[i] <= q) bn[i] = 1; else if(succ > 0) { bn[i] = 1; succ--; } else bn[i] = 0; } for(int i=1;i<=n;i++) ans.append(bn[i]); pn(ans); } double dist(int x1, int y1, int x2, int y2) { double a = x1 - x2, b = y1 - y2; return Math.sqrt((a * a) + (b * b)); } long xor_sum_upton(long n) { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } int[] readArr(int n) throws Exception { int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = ni(); } return arr; } void sort(int arr[], int left, int right) { ArrayList<Integer> list = new ArrayList<>(); for (int i = left; i <= right; i++) list.add(arr[i]); Collections.sort(list); for (int i = left; i <= right; i++) arr[i] = list.get(i - left); } void sort(int arr[]) { ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < arr.length; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < arr.length; i++) arr[i] = list.get(i); } public long max(long... arr) { long max = arr[0]; for (long itr : arr) max = Math.max(max, itr); return max; } public int max(int... arr) { int max = arr[0]; for (int itr : arr) max = Math.max(max, itr); return max; } public long min(long... arr) { long min = arr[0]; for (long itr : arr) min = Math.min(min, itr); return min; } public int min(int... arr) { int min = arr[0]; for (int itr : arr) min = Math.min(min, itr); return min; } public long sum(long... arr) { long sum = 0; for (long itr : arr) sum += itr; return sum; } public long sum(int... arr) { long sum = 0; for (int itr : arr) sum += itr; return sum; } String bin(long n) { return Long.toBinaryString(n); } String bin(int n) { return Integer.toBinaryString(n); } static int bitCount(int x) { return x == 0 ? 0 : (1 + bitCount(x & (x - 1))); } static void dbg(Object... o) { System.err.println(Arrays.deepToString(o)); } int bit(long n) { return (n == 0) ? 0 : (1 + bit(n & (n - 1))); } int abs(int a) { return (a < 0) ? -a : a; } long abs(long a) { return (a < 0) ? -a : a; } void p(Object o) { out.print(o); } void pn(Object o) { out.println(o); } void pni(Object o) { out.println(o); out.flush(); } void pn(int[] arr) { int n = arr.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(arr[i] + " "); } pn(sb); } void pn(long[] arr) { int n = arr.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(arr[i] + " "); } pn(sb); } String n() throws Exception { return in.next(); } String nln() throws Exception { return in.nextLine(); } char c() throws Exception { return in.next().charAt(0); } int ni() throws Exception { return Integer.parseInt(in.next()); } long nl() throws Exception { return Long.parseLong(in.next()); } double nd() throws Exception { return Double.parseDouble(in.next()); } public static void main(String[] args) throws Exception { new practise().run(); } FastReader in; PrintWriter out; void run() throws Exception { in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC) ? ni() : 1; pre(); for (int t = 1; t <= T; t++) solve(t); out.flush(); out.close(); } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception { br = new BufferedReader(new FileReader(s)); } String next() throws Exception { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
2b066f5b4252f8ecb46c8a65fc4d86ee
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; import java.util.Scanner; 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()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException { // write your code here FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int q = sc.nextInt(); int[] arr = new int[n]; for(int i=0; i<n; i++) { arr[i]=sc.nextInt(); } int x=0; int[] ans = new int[n]; for(int i=n-1; i>=0; i--) { if(arr[i]<=x) ans[i]=1; else { if(x<q) { x++; ans[i]=1; } else ans[i]=0; } } for(int i=0; i<n; i++) { System.out.print(ans[i]); } System.out.println(); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
043d3d7b1ce8ddfe61a55d4112ec1293
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
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 C { static FastScanner fs=new FastScanner(); public static void main(String[] args) { int tc= fs.nextInt(); for (int i=0;i<tc;i++){ int n= fs.nextInt();long q= fs.nextLong(); long[] arr=fs.readArray(n); StringBuilder stringBuilder=new StringBuilder(); long iq=0; for (int j=n-1;j>=0;j--){ if (iq>=arr[j]) { stringBuilder.append("1"); } if (iq<arr[j]) { if (iq<=q-1){ iq++; stringBuilder.append("1"); } else { stringBuilder.append("0"); } } // if (arr[j]>q) stringBuilder.append("0"); } System.out.println(stringBuilder.reverse()); } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { public BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long[] readArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
6ac18b9c9b2a231913bafa395dca354f
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Solution { public static int gcd(int a, int b) { if(a==b) { return a; } else if (a<b) { for(int i = a; i>=1; i++) { if(a%i == 0 && b%i==0) { return i; } } } else { for(int i = b; i>=1; i++) { if(a%i == 0 && b%i==0) { return i; } } } return 1; } public static void main(String[] args) throws IOException { Reader r = new Reader(); BufferedWriter o = new BufferedWriter(new OutputStreamWriter(System.out)); int t = r.readI(); outer: for(int z = 1; z<=t; z++){ int[] in = r.readArrI(); int n = in[0]; int q = in[1]; int[] a = r.readArrI(); int Q = 0; StringBuilder sb = new StringBuilder(); for(int i = n-1; i>=0; i--) { if(a[i]>Q && Q<q) { Q++; sb.append("1"); } else if(a[i] <= Q) { sb.append("1"); } else { sb.append("0"); } } sb.reverse(); String ans = sb.toString(); o.write(ans + "\n"); o.flush(); } } } class Reader { BufferedReader r; Reader(){ r = new BufferedReader(new InputStreamReader(System.in)); } public int[] readArrI() throws IOException { String[] s = r.readLine().split(" "); int n = s.length; int[] a = new int[n]; for(int j=0; j<n;j++) { a[j] = Integer.parseInt(s[j]); } return a; } public long[] readArrL() throws IOException { String[] s = r.readLine().split(" "); int n = s.length; long[] a = new long[n]; for(int j=0; j<n;j++) { a[j] = Long.parseLong(s[j]); } return a; } public int readI() throws IOException { String[] s = r.readLine().split(" "); int n = Integer.parseInt(s[0]); return n; } public long readL() throws IOException { String[] s = r.readLine().split(" "); long n = Long.parseLong(s[0]); return n; } public String readS() throws IOException { String s = r.readLine(); return s; } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output
PASSED
0cd54fa9e43543c4921a528486c33bb5
train_108.jsonl
1657982100
Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens: if $$$a_i&gt;q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$; otherwise, nothing changes. If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.
256 megabytes
import com.sun.security.jgss.GSSUtil; import javax.swing.plaf.IconUIResource; import java.io.*; import java.net.Inet4Address; import java.util.*; public class Main { private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private FastWriter wr; private Reader rd; public final int MOD = 1000000007; /************************************************** FAST INPUT IMPLEMENTATION *********************************************/ class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader( new InputStreamReader(System.in)); } public Reader(String path) throws FileNotFoundException { br = new BufferedReader( new InputStreamReader(new FileInputStream(path))); } 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 int ni() throws IOException { return rd.nextInt(); } public long nl() throws IOException { return rd.nextLong(); } public void yOrn(boolean flag) { if (flag) { wr.println("YES"); } else { wr.println("NO"); } } char nc() throws IOException { return rd.next().charAt(0); } public String ns() throws IOException { return rd.nextLine(); } public Double nd() throws IOException { return rd.nextDouble(); } public ArrayList<Integer> nli(int n, int start) throws IOException { ArrayList<Integer> list=new ArrayList<>(n+start); for (int i = 0; i < n+start; i++) { list.add(rd.nextInt()); } return list; } public ArrayList<Integer> nli(int n) throws IOException { int start=0; ArrayList<Integer> list=new ArrayList<>(n+start); for (int i = 0; i < n+start; i++) { list.add(rd.nextInt()); } return list; } public ArrayList<String> nls(int n, int start) throws IOException { ArrayList<String> list=new ArrayList<>(n+start); for (int i = 0; i < n+start; i++) { list.add(rd.nextLine()); } return list; } public ArrayList<String> nls(int n) throws IOException { int start=0; ArrayList<String> list=new ArrayList<>(n+start); for (int i = 0; i < n+start; i++) { list.add(rd.nextLine()); } return list; } public ArrayList<Long> nll(int n, int start) throws IOException { ArrayList<Long> list=new ArrayList<>(n+start); for (int i = 0; i < n+start; i++) { list.add(rd.nextLong()); } return list; } public ArrayList<Long> nll(int n) throws IOException { int start=0; ArrayList<Long> list=new ArrayList<>(n+start); for (int i = 0; i < n+start; i++) { list.add(rd.nextLong()); } return list; } /************************************************** FAST OUTPUT IMPLEMENTATION *********************************************/ public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } /********************************************************* USEFUL CODE **************************************************/ boolean[] SAPrimeGenerator(int n) { // TC-N*LOG(LOG N) //Create Prime Marking Array and fill it with true value boolean[] primeMarker = new boolean[n + 1]; Arrays.fill(primeMarker, true); primeMarker[0] = false; primeMarker[1] = false; for (int i = 2; i <= n; i++) { if (primeMarker[i]) { // we start from 2*i because i*1 must be prime for (int j = 2 * i; j <= n; j += i) { primeMarker[j] = false; } } } return primeMarker; } private void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } class Pair<F, S> { F first; S second; Pair(F first, S second) { this.first = first; this.second = second; } } class PairThree<F, S, X> { private F first; private S second; private X third; PairThree(F first, S second, X third) { this.first = first; this.second = second; this.third = third; } } public static void main(String[] args) throws IOException { new Main().run(); } public void run() throws IOException { if (oj) { rd = new Reader(); wr = new FastWriter(System.out); } else { File input = new File("input.txt"); File output = new File("output.txt"); if (input.exists() && output.exists()) { rd = new Reader(input.getPath()); wr = new FastWriter(output.getPath()); } else { rd = new Reader(); wr = new FastWriter(System.out); oj = true; } } long s = System.currentTimeMillis(); solve(); wr.flush(); tr(System.currentTimeMillis() - s + "ms"); } /*************************************************************************************************************************** *********************************************************** MAIN CODE ****************************************************** ****************************************************************************************************************************/ boolean[] sieve; public void solve() throws IOException { sieve=SAPrimeGenerator(100001); int t = 1; t = ni(); while (t-- > 0) { go(); } } /********************************************************* MAIN LOGIC HERE ****************************************************/ long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } boolean isPowerOfTwo(int n) { int counter = 0; while (n != 0) { if ((n & 1) == 1) { counter++; } n = n >> 1; } return counter <= 1; } void printList(ArrayList<Integer> al){ for(int i=0;i<al.size();i++){ wr.print(al.get(i)+" "); } wr.println(""); } int lower_than(ArrayList<Long> al,long key){ int start=0,end=al.size()-1; int ans=0; while (start<=end){ int mid=(start+end)/2; if(al.get(mid)<key){ ans=mid; start=mid+1; }else { end=mid-1; } } return ans; } boolean isComplete(long[] arr,int index,long q){ boolean flag=true; for(int i=index;i<arr.length;i++){ if(q==0){ flag=false; break; } if(arr[i]>q){ q--; } } return flag; } public void go() throws IOException { int n=ni(); long q=nl(); long[] arr=new long[n]; ArrayList<Integer> bad=new ArrayList<>(); for(int i=0;i<n;i++){ arr[i]=nl(); if(arr[i]>q){ bad.add(i); } } int start=0,end=bad.size()-1; int ans; ans=n-1; while (start<=end){ int mid=(start+end)/2; if(isComplete(arr,bad.get(mid),q)){ ans=bad.get(mid); end=mid-1; }else { start=mid+1; } } StringBuilder sb=new StringBuilder(); for(int j=0;j<n;j++){ if(j>=ans){ sb.append("1"); }else { if(arr[j]>q){ sb.append("0"); }else { sb.append("1"); } } } wr.println(sb.toString()); } }
Java
["5\n\n1 1\n\n1\n\n2 1\n\n1 2\n\n3 1\n\n1 2 1\n\n4 2\n\n1 4 3 1\n\n5 2\n\n5 1 2 4 3"]
1 second
["1\n11\n110\n1110\n01111"]
NoteIn the first test case, Doremy tests the only contest. Her IQ doesn't decrease.In the second test case, Doremy tests both contests. Her IQ decreases by $$$1$$$ after testing contest $$$2$$$.In the third test case, Doremy tests contest $$$1$$$ and $$$2$$$. Her IQ decreases to $$$0$$$ after testing contest $$$2$$$, so she can't test contest $$$3$$$.
Java 11
standard input
[ "binary search", "greedy" ]
62a90c34a7df8fb56419aa5a1cf2a75b
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 10^9$$$) — the number of contests and Doremy's IQ in the beginning. The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the difficulty of each contest. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, you need to output a binary string $$$s$$$, where $$$s_i=1$$$ if Doremy should choose to test contest $$$i$$$, and $$$s_i=0$$$ otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less. If there are multiple solutions, you may output any.
standard output