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 | a825a99923785ba8454812013ef42b4c | 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>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 ContestScanner sc = new ContestScanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder();
static long mod = (long) 1e9 + 7;
public static void main(String[] args) throws Exception {
int T = sc.nextInt();
for(int i = 0; i < T; i++)solve();
//solve();
pw.flush();
}
public static void solve() {
int N = sc.nextInt();
int q = sc.nextInt();
int[] a = sc.nextIntArray(N);
int ans = 0;
int nowQ = 0;
char[] prt = new char[N];
for(int i = N-1; i >= 0; i--){
if(a[i] > nowQ){
if(nowQ < q){
nowQ++;
prt[i] = '1';
}else{
prt[i] = '0';
}
}else{
prt[i] = '1';
}
}
pw.println(new String(prt));
}
static class GeekInteger {
public static void save_sort(int[] array) {
shuffle(array);
Arrays.sort(array);
}
public static int[] shuffle(int[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
int randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
public static void save_sort(long[] array) {
shuffle(array);
Arrays.sort(array);
}
public static long[] shuffle(long[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
long randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
}
}
/**
* refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java
*/
class ContestScanner {
private final java.io.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 ContestScanner(java.io.InputStream in){
this.in = in;
}
public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {
this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));
}
public ContestScanner(){
this(System.in);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = in.read(buffer);
} catch (java.io.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 java.util.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 java.util.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("%d%s... is not number", n, Character.toString(b))
);
}
}
} 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("%d%s... is not number", n, Character.toString(b))
);
}
}
}
}
throw new ArithmeticException(
String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)
);
}
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(int length){
long[] array = new long[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[] 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;
}
}
| 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 | 754113c471f8db5929d3f142d2ff1176 | 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>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 int mod = 998244353;
static int mod = (int)1e9+7;
static boolean[] prime = new boolean[1];
static int[][] dir1 = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
static int[][] dir2 = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
static int inf = 0x3f3f3f3f;
static {
for (int i = 2; i < prime.length; i++)
prime[i] = true;
for (int i = 2; i < prime.length; i++) {
if (prime[i]) {
for (int k = 2; i * k < prime.length; k++) {
prime[i * k] = false;
}
}
}
}
static class JoinSet {
int[] fa;
JoinSet(int n) {
fa = new int[n];
for (int i = 0; i < n; i++)
fa[i] = i;
}
int find(int t) {
if (t != fa[t])
fa[t] = find(fa[t]);
return fa[t];
}
void join(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
}
}
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
static int get() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Integer.parseInt(ss);
}
static long getx() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Long.parseLong(ss);
}
static int[] getint() throws Exception {
String[] s = bf.readLine().split(" ");
int[] a = new int[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(s[i]);
}
return a;
}
static long[] getlong() throws Exception {
String[] s = bf.readLine().split(" ");
long[] a = new long[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Long.parseLong(s[i]);
}
return a;
}
static char[] getstr() throws Exception {
return bf.readLine().toCharArray();
}
static void println() throws Exception {
bw.write("\n");
}
static void print(int a) throws Exception {
bw.write(a + "\n");
}
static void print(long a) throws Exception {
bw.write(a + "\n");
}
static void print(String a) throws Exception {
bw.write(a + "\n");
}
static void print(int[] a) throws Exception {
for (int i : a) {
bw.write(i + " ");
}
println();
}
static void print(long[] a) throws Exception {
for (long i : a) {
bw.write(i + " ");
}
println();
}
static void print(int[][] a) throws Exception {
for (int i[] : a)
print(i);
}
static void print(long[][] a) throws Exception {
for (long[] i : a)
print(i);
}
static void print(char[] a) throws Exception {
for (char i : a) {
bw.write(i + "");
}
println();
}
static long pow(long a, long b) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans *= a;
}
a *= a;
b >>= 1;
}
return ans;
}
static int powmod(long a, long b, int mod) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return (int) ans;
}
static void sort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void sort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void resort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static void resort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
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 max(int[] a) {
int max = a[0];
for (int i : a)
max = max(max, i);
return max;
}
static int min(int[] a) {
int min = a[0];
for (int i : a)
min = min(min, i);
return min;
}
static long max(long[] a) {
long max = a[0];
for (long i : a)
max = max(max, i);
return max;
}
static long min(long[] a) {
long min = a[0];
for (long i : a)
min = min(min, i);
return min;
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void yes() throws Exception {
print("Yes");
}
static void no() throws Exception {
print("No");
}
static int[] getarr(List<Integer> list) {
int n = list.size();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = list.get(i);
return a;
}
static List<Integer>[] lists;
static class LCA{
int[] dep;
int[][] fa;
int[] log;
boolean[] v;
public LCA(int n){
dep = new int[n+5];
log = new int[n+5];
fa = new int[n+5][31];
v = new boolean[n+5];
for (int i = 2; i <= n; ++i) {
log[i] = log[i/2] + 1;
}
dfs(1,0);
}
private void dfs(int cur, int pre){
if(v[cur]) return;
v[cur] = true;
dep[cur] = dep[pre]+1;
fa[cur][0] = pre;
for (int i = 1; i <= log[dep[cur]]; ++i) {
fa[cur][i] = fa[fa[cur][i - 1]][i - 1];
}
for(int i : lists[cur]){
dfs(i,cur);
}
}
private int lca(int a, int b){
if(dep[a] > dep[b]){
int t = a;
a = b;
b = t;
}
while (dep[a] != dep[b]){
b = fa[b][log[dep[b] - dep[a]]];
}
if(a == b) return a;
for (int k = log[dep[a]]; k >= 0; k--) {
if (fa[a][k] != fa[b][k]) {
a = fa[a][k]; b = fa[b][k];
}
}
return fa[a][0];
}
}
public static void main(String[] args) throws Exception {
int T = 1;
T = get();
while (T-- > 0) {
int[] p = getint();
int n = p[0], q = p[1];
int c = 0;
int[] a = getint();
char s[] = new char[n];
Arrays.fill(s,'0');
for(int i = n-1;i >= 0;i--){
if(c>=a[i]) s[i] = '1';
else if(c<q){
c++;
s[i] = '1';
}
}
print(String.valueOf(s));
}
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 | 220788839e76abc6fe8a45392442b298 | 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>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 random;
import java.util.*;
import java.io.*;
public class CF {
static int[] arr;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int q = Integer.parseInt(st.nextToken());
while(q-->0) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int iq = Integer.parseInt(st.nextToken());
arr = new int[n];
st = new StringTokenizer(br.readLine());
for (int i=0; i<n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int l = 0;
int r = n-1;
while(l<r) {
int mid = (l+r)/2;
if (pos(mid, iq)) {
r = mid;
}
else {
l = mid+1;
}
}
for (int i=0; i<l; i++) {
if (arr[i]<=iq) {
System.out.print(1);
}
else {
System.out.print(0);
}
}
for (int i=l; i<arr.length; i++) {
System.out.print(1);
}
System.out.println();
}
}
static boolean pos(int dex, int iq) {
for (int i=dex; i<arr.length; i++) {
if (arr[i]>iq) {
iq--;
}
}
return iq>=0;
}
}
| 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 | 7e719bc663cab3f72237b132008a1f64 | 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>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.lang.Math;
import java.util.*;
public final class Codechef {
static BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
static BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(System.out)
);
static StringTokenizer st;
static int mod = 1000000000;
/*write your constructor and global variables here*/
static class sortCond implements Comparator<Pair<Integer, Integer>> {
@Override
public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
if (p1.a <= p2.a) {
return -1;
} else {
return 1;
}
}
}
static class sortCond1 implements Comparator<Integer> {
@Override
public int compare(Integer p1, Integer p2) {
if (p1 <= p2) {
return 1;
} else {
return -1;
}
}
}
static class Rec {
int a;
int b;
long c;
Rec(int a, int b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
}
static class Pair<f, s> {
f a;
s b;
Pair(f a, s b) {
this.a = a;
this.b = b;
}
}
interface modOperations {
int mod(int a, int b, int mod);
}
static int findBinaryExponentian(int a, int pow, int mod) {
if (pow == 1) {
return a;
} else if (pow == 0) {
return 1;
} else {
int retVal = findBinaryExponentian(a, (int) pow / 2, mod);
int val = (pow % 2 == 0) ? 1 : a;
return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);
}
}
static int findPow(int a, int b, int mod) {
if (b == 1) {
return a % mod;
} else if (b == 0) {
return 1;
} else {
int res = findPow(a, (int) b / 2, mod);
return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);
}
}
static int bleft(int ele, int[] arr) {
int l = 0;
int h = arr.length - 1;
int ans = -1;
while (l <= h) {
int mid = l + (int) (h - l) / 2;
int val = arr[mid];
if (ele > val) {
l = mid + 1;
} else if (ele < val) {
h = mid - 1;
} else {
ans = mid;
h = mid - 1;
}
}
return ans;
}
static int gcd(int a, int b) {
int div = b;
int rem = a % b;
while (rem != 0) {
int temp = rem;
rem = div % rem;
div = temp;
}
return div;
}
static long[] log(long no, long n) {
long i = 1;
int cnt = 0;
long sum = 0l;
long arr[] = new long[2];
while (i < no) {
sum += i;
cnt++;
if (sum == n) {
arr[0] = 1l * cnt;
arr[1] = sum;
break;
}
i *= 2l;
}
if (arr[0] == 0) {
arr[0] = cnt;
arr[1] = sum;
}
return arr;
}
static modOperations modAdd = (int a, int b, int mod) -> {
return (a % mod + b % mod) % mod;
};
static modOperations modSub = (int a, int b, int mod) -> {
return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);
};
static modOperations modMul = (int a, int b, int mod) -> {
return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));
};
static modOperations modDiv = (int a, int b, int mod) -> {
return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);
};
static HashSet<Integer> primeList(int MAXI) {
int[] prime = new int[MAXI + 1];
HashSet<Integer> obj = new HashSet<>();
for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {
if (prime[i] == 0) {
obj.add(i);
for (int j = i * i; j <= MAXI; j += i) {
prime[j] = 1;
}
}
}
for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {
if (prime[i] == 0) {
obj.add(i);
}
}
return obj;
}
static int[] factorialList(int MAXI, int mod) {
int[] factorial = new int[MAXI + 1];
factorial[0] = factorial[1] = 1;
factorial[2] = 2;
for (int i = 3; i < MAXI + 1; i++) {
factorial[i] = modMul.mod(factorial[i - 1], i, mod);
}
return factorial;
}
static void put(HashMap<Integer, Integer> cnt, int key) {
if (cnt.containsKey(key)) {
cnt.replace(key, cnt.get(key) + 1);
} else {
cnt.put(key, 1);
}
}
static long arrSum(ArrayList<Long> arr) {
long tot = 0;
for (int i = 0; i < arr.size(); i++) {
tot += arr.get(i);
}
return tot;
}
static int ord(char b) {
return (int) b - (int) 'a';
}
static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {
int l = lower_bound + 1;
int h = n;
int ans = 0;
while (l <= h) {
int mid = l + (h - l) / 2;
if (cnt[mid] - cnt[lower_bound] == pow) {
return mid;
} else if (cnt[mid] - cnt[lower_bound] < pow) {
ans = mid;
l = mid + 1;
} else {
h = mid - 1;
}
}
return ans;
}
static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {
int size = ans.size();
int mini = 1000000000 + 1;
long tit = 0l;
for (int i = 0; i < size; i++) {
tit += 1l * ans.get(i);
mini = Math.min(mini, ans.get(i));
}
return new Pair<>(tit - mini, mini);
}
static int factorList(
HashMap<Integer, Integer> maps,
int no,
int maxK,
int req
) {
int i = 1;
while (i * i <= no) {
if (no % i == 0) {
if (i != no / i) {
put(maps, no / i);
}
put(maps, i);
if (maps.get(i) == req) {
maxK = Math.max(maxK, i);
}
if (maps.get(no / i) == req) {
maxK = Math.max(maxK, no / i);
}
}
i++;
}
return maxK;
}
static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {
ArrayList<Integer> vals = new ArrayList<>();
for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
vals.add(map.getKey());
}
return vals;
}
static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {
ArrayList<Integer> vals = new ArrayList<>();
for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
vals.add(map.getValue());
}
return vals;
}
static int getMax(ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 1; i < arr.size(); i++) {
if (arr.get(i) > max) {
max = arr.get(i);
}
}
return max;
}
static int getMin(ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 1; i < arr.size(); i++) {
if (arr.get(i) < max) {
max = arr.get(i);
}
}
return max;
}
static void bitRep(int n, int no) throws IOException {
int curr = (int) Math.pow(2, n - 1);
for (int i = n - 1; i >= 0; i--) {
if ((curr & no) != 0) {
bw.write("1");
} else {
bw.write("0");
}
curr /= 2;
}
bw.write("\n");
}
static ArrayList<Integer> retPow(int MAXI) {
long curr = 1l;
ArrayList<Integer> arr = new ArrayList<>();
for (int i = 1; i <= MAXI; i++) {
curr *= 2l;
curr = curr % mod;
arr.add((int) curr);
}
return arr;
}
static String is(int no) {
return Integer.toString(no);
}
static String ls(long no) {
return Long.toString(no);
}
static int pi(String s) {
return Integer.parseInt(s);
}
static long pl(String s) {
return Long.parseLong(s);
}
/*write your methods and classes here*/
public static void main(String[] args) throws IOException {
int cases = pi(br.readLine()), n, q, i;
while (cases-- != 0) {
st = new StringTokenizer(br.readLine());
n = pi(st.nextToken());
q = pi(st.nextToken());
int arr[] = new int[n];
st = new StringTokenizer(br.readLine());
for (i = 0; i < n; i++) {
arr[i] = pi(st.nextToken());
}
int p = 0;
String ans = "";
for (i = n - 1; i >= 0; i--) {
if (arr[i] <= p) {
ans += "1";
} else {
if (p == q) {
ans += "0";
continue;
} else {
ans += "1";
p++;
}
}
}
for (i = n - 1; i >= 0; i--) {
bw.write(ans.charAt(i));
}
bw.write("\n");
}
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 | f3e2653ad6cfecc9552eac1d96367323 | 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>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 PrintWriter out;
static Kioken sc;
// static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null;
public static void main(String[] args) throws FileNotFoundException {
out = new PrintWriter((System.out));
sc = new Kioken();
int tt = 1;
tt = sc.nextInt();
while (tt-- > 0) {
solve();
}
out.flush();
out.close();
}
public static void solve() {
int n = sc.nextInt();
int q = sc.nextInt();
int[] arr = sc.readArrayInt(n);
// checking from last
// at last q should be zero
int lastq = 0;
int[] ans = new int[n];
for(int i = n - 1; i >= 0; i--) {
if(arr[i] <= lastq) {
ans[i] = 1;
}else {
if(lastq < q) {
ans[i] = 1;
lastq++;
}else {
ans[i] = 0;
}
}
}
for(int i : ans) {
out.print(i);
}
out.println();
}
public static long gcd(long a, long b) {
while (b != 0) {
long rem = a % b;
a = b;
b = rem;
}
return a;
}
static long MOD = 1000000007;
static void reverseSort(int[] arr){List<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 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 class Kioken {
// FileInputStream br = new FileInputStream("input.txt");
BufferedReader br;
StringTokenizer st;
Kioken(String filename) {
try {
FileReader fr = new FileReader(filename);
br = new BufferedReader(fr);
st = new StringTokenizer("");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Kioken() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean hasNext() {
String next = null;
try {
next = br.readLine();
} catch (Exception e) {
}
if (next == null || next.length() == 0) {
return false;
}
st = new StringTokenizer(next);
return true;
}
public int[] readArrayInt(int n){
int[] arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = nextInt();
}
return arr;
}
public long[] readArrayLong(int n){
long[] arr = new long[n];
for(int i = 0; i < n; i++){
arr[i] = nextLong();
}
return arr;
}
}
} | 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 | 378d00e1dee09a192da4f2b04339ec0c | 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>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 | // we go as further as possible.
import java.util.Scanner;
public class C {
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 arr[] = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = sc.nextInt();
}
char c[] = new char[N];
int currIQ = 0;
for (int i = N - 1; i >= 0; i--) {
if (arr[i] <= currIQ) c[i] = '1';
else if (currIQ < IQ) { currIQ++; c[i] = '1'; }
else c[i] = '0';
}
for (int i = 0; i < N; i++) {
System.out.print(c[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 | 621d00d5a69305d8a928a9e85e1fb88c | 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>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 Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
int 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 | 136e1fe21ae1e16bfd12934650ee8ba9 | 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>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.math.BigInteger;
import java.io.*;
public class Main implements Runnable {
public static void main(String[] args) {
new Thread(null, new Main(), "whatever", 1 << 26).start();
}
private FastScanner sc;
private PrintWriter pw;
public void run() {
try {
boolean isSumitting = true;
// isSumitting = false;
if (isSumitting) {
pw = new PrintWriter(System.out);
sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
} else {
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
sc = new FastScanner(new BufferedReader(new FileReader("input.txt")));
}
} catch (Exception e) {
throw new RuntimeException();
}
int t = sc.nextInt();
// int t = 1;
while (t-- > 0) {
// sc.nextLine();
// System.out.println("for t=" + t);
solve();
}
pw.close();
}
public long mod = 1_000_000_007;
private int inf=1_000_000_000;
public void solve(){
int n=sc.nextInt();
int q=sc.nextInt();
int[] arr=sc.nextIntArray(n);
if(q>=n){
for(int i=0;i<n;i++){
pw.print(1);
}
pw.println();
return;
}
int top=0;
Stack<Integer> s=new Stack<>();
for(int i=n-1;i>=0;i--){
if(arr[i]<=top){
s.push(1);
}else{
if(top+1>q){
s.push(0);
}else{
s.push(1);
top++;
}
}
}
while(s.size()>0){
pw.print(s.pop());
}
pw.println();
}
class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(BufferedReader bf) {
reader = bf;
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public float nextFloat() {
return Float.parseFloat(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String[] nextStringArray(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++) {
a[i] = next();
}
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
}
private static class Sorter {
public static <T extends Comparable<? super T>> void sort(T[] arr) {
Arrays.sort(arr);
}
public static <T> void sort(T[] arr, Comparator<T> c) {
Arrays.sort(arr, c);
}
public static <T> void sort(T[][] arr, Comparator<T[]> c) {
Arrays.sort(arr, c);
}
public static <T extends Comparable<? super T>> void sort(ArrayList<T> arr) {
Collections.sort(arr);
}
public static <T> void sort(ArrayList<T> arr, Comparator<T> c) {
Collections.sort(arr, c);
}
public static void normalSort(int[] arr) {
Arrays.sort(arr);
}
public static void normalSort(long[] arr) {
Arrays.sort(arr);
}
public static void sort(int[] arr) {
timSort(arr);
}
public static void sort(int[] arr, Comparator<Integer> c) {
timSort(arr, c);
}
public static void sort(int[][] arr, Comparator<Integer[]> c) {
timSort(arr, c);
}
public static void sort(long[] arr) {
timSort(arr);
}
public static void sort(long[] arr, Comparator<Long> c) {
timSort(arr, c);
}
public static void sort(long[][] arr, Comparator<Long[]> c) {
timSort(arr, c);
}
private static void timSort(int[] arr) {
Integer[] temp = new Integer[arr.length];
for (int i = 0; i < arr.length; i++) temp[i] = arr[i];
Arrays.sort(temp);
for (int i = 0; i < arr.length; i++) arr[i] = temp[i];
}
private static void timSort(int[] arr, Comparator<Integer> c) {
Integer[] temp = new Integer[arr.length];
for (int i = 0; i < arr.length; i++) temp[i] = arr[i];
Arrays.sort(temp, c);
for (int i = 0; i < arr.length; i++) arr[i] = temp[i];
}
private static void timSort(int[][] arr, Comparator<Integer[]> c) {
Integer[][] temp = new Integer[arr.length][arr[0].length];
for (int i = 0; i < arr.length; i++)
for (int j = 0; j < arr[0].length; j++)
temp[i][j] = arr[i][j];
Arrays.sort(temp, c);
for (int i = 0; i < arr.length; i++)
for (int j = 0; j < arr[0].length; j++)
temp[i][j] = arr[i][j];
}
private static void timSort(long[] arr) {
Long[] temp = new Long[arr.length];
for (int i = 0; i < arr.length; i++) temp[i] = arr[i];
Arrays.sort(temp);
for (int i = 0; i < arr.length; i++) arr[i] = temp[i];
}
private static void timSort(long[] arr, Comparator<Long> c) {
Long[] temp = new Long[arr.length];
for (int i = 0; i < arr.length; i++) temp[i] = arr[i];
Arrays.sort(temp, c);
for (int i = 0; i < arr.length; i++) arr[i] = temp[i];
}
private static void timSort(long[][] arr, Comparator<Long[]> c) {
Long[][] temp = new Long[arr.length][arr[0].length];
for (int i = 0; i < arr.length; i++)
for (int j = 0; j < arr[0].length; j++)
temp[i][j] = arr[i][j];
Arrays.sort(temp, c);
for (int i = 0; i < arr.length; i++)
for (int j = 0; j < arr[0].length; j++)
temp[i][j] = arr[i][j];
}
}
public long fastPow(long x, long y, long mod) {
if (y == 0) return 1;
if (y == 1) return x % mod;
long temp = fastPow(x, y / 2, mod);
long ans = (temp * temp) % mod;
return (y % 2 == 1) ? (ans * (x % mod)) % mod : ans;
}
public long fastPow(long x, long y) {
if (y == 0) return 1;
if (y == 1) return x;
long temp = fastPow(x, y / 2);
long ans = (temp * temp);
return (y % 2 == 1) ? (ans * x) : 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 | 6248ef1396042e28fa80bb3cea413bc4 | 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>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 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t = Integer.parseInt(br.readLine());
while(t --> 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int[] ar = new int[n];
for(int i = 0; i < n; i++)
ar[i] = Integer.parseInt(st.nextToken());
boolean[] take = new boolean[n];
int need = 0;
for(int i = n-1; i >= 0; i--) {
if(need == q) {
if(need >= ar[i])
take[i] = true;
}else {
take[i] = true;
if(need < ar[i])
need++;
}
}
for(boolean d : take)
if(d)
pw.print(1);
else
pw.print(0);
pw.println();
}
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 | a2e63e561eb3a7a77ca401ccf46e7c80 | 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>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 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int g=Integer.parseInt(bf.readLine());
while(g-->0){
String[] s=bf.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
Stack<int[]> ka=new Stack<>();
int[] k=new int[a];
s=bf.readLine().split(" ");
for(int i=0; i<a; i++){
ka.add(new int[]{Integer.parseInt(s[i]),i});
}
int x=0;
while(!ka.isEmpty()){
int[] q=ka.pop();
if(q[0]>x){
if(x<b){
x++;
k[q[1]]=1;
}
else k[q[1]]=0;
}
else k[q[1]]=1;
}
StringBuilder sb=new StringBuilder();
for(int i=0; i<a; i++) sb.append(k[i]);
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 | e5ad062b9fcb666e11e193bdc16170e2 | 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>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.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class Solution {
static int max;
static String res;
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
FastScanner fs = new FastScanner();
// DecimalFormat formatter = new DecimalFormat("#0.000000");
int ti = fs.nextInt();
outer: while (ti-- > 0) {
int n = fs.nextInt();
int q = fs.nextInt();
int[] arr = fs.readArray(n);
StringBuilder sb = new StringBuilder();
int temp = 0;
for (int i = n - 1; i >= 0; i--) {
if (arr[i] > temp) {
if (q > temp) {
sb.append(1);
temp++;
} else
sb.append(0);
} else
sb.append(1);
}
out.println(sb.reverse());
}
out.close();
}
static void buildHeap(int arr[], int n) {
for (int i = n / 2 - 1; i >= 0; i--)
heapify(arr, n, i);
}
static void heapify(int arr[], int n, int i) {
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < n && arr[l] > arr[largest])
largest = l;
if (r < n && arr[r] > arr[largest])
largest = r;
if (largest != i) {
int temp = arr[i];
arr[i] = arr[largest];
arr[largest] = temp;
heapify(arr, n, largest);
}
}
public static void heapSort(int arr[], int n) {
buildHeap(arr, n);
for (int i = n - 1; i >= 0; i--) {
int max = arr[0];
arr[0] = arr[i];
arr[i] = max;
heapify(arr, i, 0);
}
// Arrays.copyOfRange(arr, n, n);
}
static long power(long x, int m) {
long y = x;
while (x % m == 0)
x /= m;
if (x != 1)
y = -1;
return y;
}
static final int mod = 1_000_000_007;
static void sort(long[] a) {
Random random = new Random();
int n = a.length;
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n);
long temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static void sort(int[] a) {
Random random = new Random();
int n = a.length;
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static 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 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());
}
float nextFloat() {
return Float.parseFloat(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());
}
}
static class Pair {
int one;
String two;
public Pair(int a, String b) {
this.one = a;
this.two = b;
}
}
}
| 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 | 1d70dec817a357fe982d43dfbb331524 | 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>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 | // LARGEST SQUARE
// package com.company
/*
* @author :: Yuvraj Singh
* CS UNDERGRAD AT IT GGV BILASPUR
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;
public class Main {
// Solution here
ArrayList<Pair> arr;
void solve(int t) {
int n= in.nextInt();
int q= in.nextInt();
int[] arr= intArr(n);
int[] ans= new int[n];
int curr = 0;
for(int i=n-1; i>=0; i--){
if(curr < arr[i]){
if(curr < q){
curr++;
ans[i] = 1;
}else{
ans[i] = 0;
}
}else{
ans[i] = 1;
}
}
for(int i=0; i<n; i++){
sb.append(ans[i]);
}
sb.append("\n");
}
void start(){
sb= new StringBuffer();
int t= in.nextInt();
for(int i=1;i<=t;i++) {
solve(i);
}
out.print(sb);
}
// Starter Code
FastReader in;
StringBuffer sb;
public static void main(String[] args) {
new Main().run();
}
void run(){
in= new FastReader();
start();
}
void bubbleSort(int[] arr){
int n= arr.length;
for(int i=n-1; i>0; i--){
for(int j=0; j<i; j++){
if(arr[i] < arr[j]){
swap(arr, i, j);
}
}
}
}
void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
long numberOfWays(long n, long k) {
// Base Cases
if (n == 0)
return 1;
if (k == 0)
return 1;
if (n >= (int)Math.pow(2, k)) {
int curr_val = (int)Math.pow(2, k);
return numberOfWays(n - curr_val, k)
+ numberOfWays(n, k - 1);
}
else
return numberOfWays(n, k - 1);
}
boolean palindrome(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;
}
int call(int[] A, int N, int K) {
int i = 0, j = 0, sum = 0;
int maxLen = Integer.MIN_VALUE;
while (j < N) {
sum += A[j];
if (sum < K) {
j++;
}
else if (sum == K) {
maxLen = Math.max(maxLen, j-i+1);
j++;
}
else if (sum > K) {
while (sum > K) {
sum -= A[i];
i++;
}
if(sum == K){
maxLen = Math.max(maxLen, j-i+1);
}
j++;
}
}
return maxLen;
}
int largestNum(int n)
{
int num = 0;
// Iterate through all possible values
for (int i = 0; i <= 32; i++)
{
// Multiply the number by 2 i times
int x = (1 << i);
if ((x - 1) >= n)
num = (1 << i) - 1;
else
break;
}
// Return the final result
return num;
}
static boolean isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
// Useful Functions
void swap( int i , int j) {
int tmp = i;
i = j;
j = tmp;
}
int call(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MIN_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = max(call(i+1, j, mat, dp), call(i, j+1, mat, dp)) + mat[i][j];
}
int util(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MAX_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = min(util(i+1, j, mat, dp), util(i, j+1, mat, dp)) + mat[i][j];
}
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;
x = (x * x) % p;
}
return res;
}
int lower_bound(long[] a, long 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;
}
int upper_bound(long[] arr, int key) {
int i=0, j=arr.length-1;
if (arr[j]<=key) return j+1;
if(arr[i]>key) return i;
while (i<j){
int mid= (i+j)/2;
if(arr[mid]<=key){
i= mid+1;
}else{
j=mid;
}
}
return i;
}
void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
int[] intArr(int n){
int[] res= new int[n];
for(int i=0;i<n;i++){
res[i]= in.nextInt();
}
return res;
}
long[] longArr(int n){
long[] res= new long[n];
for(int i=0;i<n;i++){
res[i]= in.nextLong();
}
return res;
}
// // sieve of eratosthenes code for precomputing whether numbers are prime or not up to MAX_VALUE
long MAX= 100000000;
int[] precomp;
void sieve(){
long n= MAX;
precomp = new int[(int) (n+1)];
boolean[] prime = new boolean[(int) (n+1)];
for(int i=0;i<=n;i++)
prime[i] = true;
for(long p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[(int) p])
{
// Update all multiples of p
for(long i = p*p; i <= n; i += p)
prime[(int) i] = false;
}
}
// Print all prime numbers
for(long i = 2; i <= n; i++)
{
if(prime[(int) i])
precomp[(int) i]= 1;
}
}
long REVERSE(long N) {
// code here
long rev=0;
long org= N;
while (N!=0){
long d= N%10;
rev = rev*10 +d;
N /= 10;
}
return rev;
}
long sumOfDigits(String n){
long sum= 0;
for (char c: n.toCharArray()){
sum += Integer.parseInt(String.valueOf(c));
}
return sum;
}
long[] revArray(long[] arr) {
int n= arr.length;
int i=0, j=n-1;
while (i<j){
long temp= arr[i];
arr[i]= arr[j];
arr[j]= temp;
i++;
j--;
}
return arr;
}
long gcd(long a, long b){
if (b==0)
return a;
return gcd(b, a%b);
}
long lcm(long a,long b){
return (a*b)/gcd(a,b);
}
static class Pair implements Comparable<Pair>{
long first;
long second;
Pair(long x, long y){
this.first=x;
this.second=y;
}
@Override
public int compareTo(Pair o) {
return 0;
}
}
// static class Compare {
// static void compare(ArrayList<Pair> arr, int n) {
// arr.sort(new Comparator<Pair>() {
// @Override
// public int compare(Pair p1, Pair p2) {
// return (int) (p2.first - p1.first);
// }
// });
// }
// }
public static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(br.readLine());
}catch (Exception 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 (Exception 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 | 2483c57008f9ef196c00a4569dfba85f | 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>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.*;// hamare sath shri Raghunath, to kis baat ki chinta..........
import java.lang.*;// discipline is doing what needs to be done even if you don't want to do it.
import java.io.*;
public class a {
static FastReader sc = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
public static void main (String[] args) throws java.lang.Exception {
int tc = sc.nextInt();
while(tc-->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 cnt = 0;
int index = 0;
char ans[] = new char[n];
boolean flag = true;
for(int i = n-1; i >= 0; i--){
if(flag && cnt < arr[i]){
cnt++;
}
if(cnt > q){
flag = false;
}
if(cnt <= q || arr[i] <= q){
ans[i] = '1';
}else{
ans[i] = '0';
}
}
// out.println(cnt+" "+index);
for(int i = 0; i < n; i++){
out.print(ans[i]);
}
out.println();
}
out.flush();
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["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 | 35d9af6eaecba675e0b5c61a3ef71f68 | 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>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 C {
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0)
{
StringBuilder sb = new StringBuilder();
int n = s.nextInt(), q = s.nextInt();
int qnow = 0;
int a[] = new int[n];
for(int i=1; i<=n; i++) a[i-1] = s.nextInt();
boolean ans[] = new boolean[n];
for(int i=n; i>=1; i--)
{
if(qnow>=a[i-1]) ans[i-1] = true;
else if(qnow<q&&qnow<a[i-1])
{
ans[i-1] = true;
qnow++;
}
}
for(int i=1; i<=n; i++)
{
if(ans[i-1]) sb.append(1);
else sb.append(0);
}
System.out.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 | |
PASSED | 8edbe79c52e2df71e66e046cb1c9aeb5 | 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>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.util.function.BinaryOperator;
import java.util.stream.Collectors;
public class Main {
private final static long mod = 1000000007;
private final static int MAXN = 1000001;
private static long power(long x, long y, long m) {
long temp;
if (y == 0)
return 1;
temp = power(x, y / 2, m);
temp = (temp * temp) % m;
if (y % 2 == 0)
return temp;
else
return ((x % m) * temp) % m;
}
private static long power(long x, long y) {
return power(x, y, mod);
}
private static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static int nextPowerOf2(int a) {
return 1 << nextLog2(a);
}
static int nextLog2(int a) {
return (a == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(a - 1));
}
private static long modInverse(long a, long m) {
long m0 = m;
long y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
long q = a / m;
long t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
private static int[] getLogArr(int n) {
int arr[] = new int[n + 1];
for (int i = 1; i < n + 1; i++) {
arr[i] = (int) (Math.log(i) / Math.log(2) + 1e-10);
}
return arr;
}
private static int log[] = getLogArr(MAXN);
private static int getLRSpt(int st[][], int L, int R, BinaryOperator<Integer> binaryOperator) {
int j = log[R - L + 1];
return binaryOperator.apply(st[L][j], st[R - (1 << j) + 1][j]);
}
private static int[][] getSparseTable(int array[], BinaryOperator<Integer> binaryOperator) {
int k = log[array.length + 1] + 1;
int st[][] = new int[array.length + 1][k + 1];
for (int i = 0; i < array.length; i++)
st[i][0] = array[i];
for (int j = 1; j <= k; j++) {
for (int i = 0; i + (1 << j) <= array.length; i++) {
st[i][j] = binaryOperator.apply(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
}
return st;
}
private static int[][] getSparseTable(List<Integer> list, BinaryOperator<Integer> binaryOperator) {
int n=list.size();
int k = log[n + 1] + 1;
int st[][] = new int[n + 1][k + 1];
for (int i = 0; i < n; i++)
st[i][0] = list.get(i);
for (int j = 1; j <= k; j++) {
for (int i = 0; i + (1 << j) <= n; i++) {
st[i][j] = binaryOperator.apply(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
}
return st;
}
static class Subset {
int parent;
int rank;
@Override
public String toString() {
return "" + parent;
}
}
static int find(Subset[] subsets, int i) {
if (subsets[i].parent != i)
subsets[i].parent = find(subsets, subsets[i].parent);
return subsets[i].parent;
}
static void union(Subset[] Subsets, int x, int y) {
int xroot = find(Subsets, x);
int yroot = find(Subsets, y);
if (Subsets[xroot].rank < Subsets[yroot].rank)
Subsets[xroot].parent = yroot;
else if (Subsets[yroot].rank < Subsets[xroot].rank)
Subsets[yroot].parent = xroot;
else {
Subsets[xroot].parent = yroot;
Subsets[yroot].rank++;
}
}
private static int maxx(Integer... a) {
return Collections.max(Arrays.asList(a));
}
private static int minn(Integer... a) {
return Collections.min(Arrays.asList(a));
}
private static long maxx(Long... a) {
return Collections.max(Arrays.asList(a));
}
private static long minn(Long... a) {
return Collections.min(Arrays.asList(a));
}
private static class Pair<T extends Comparable<T>, U extends Comparable<U>> implements Comparable<Pair<T, U>> {
T a;
U b;
public Pair(T a, U b) {
this.a = a;
this.b = b;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return a.equals(pair.a) &&
b.equals(pair.b);
}
@Override
public int hashCode() {
return Objects.hash(a, b);
}
@Override
public String toString() {
return "(" + a +
"," + b +
')';
}
@Override
public int compareTo(Pair<T, U> o) {
return (this.a.equals(o.a) ? this.b.equals(o.b) ? 0 : this.b.compareTo(o.b) : this.a.compareTo(o.a));
}
}
public static int upperBound(List<Integer> list, int value) {
int low = 0;
int high = list.size();
while (low < high) {
final int mid = (low + high) / 2;
if (value >= list.get(mid)) {
low = mid + 1;
} else {
high = mid;
}
}
return low;
}
private static int[] getLPSArray(String pattern) {
int i, j, n = pattern.length();
int[] lps = new int[pattern.length()];
lps[0] = 0;
for (i = 1, j = 0; i < n; ) {
if (pattern.charAt(i) == pattern.charAt(j)) {
lps[i++] = ++j;
} else if (j > 0) {
j = lps[j - 1];
} else {
lps[i++] = 0;
}
}
return lps;
}
private static List<Integer> findPattern(String text, String pattern) {
List<Integer> matchedIndexes = new ArrayList<>();
if (pattern.length() == 0) {
return matchedIndexes;
}
int[] lps = getLPSArray(pattern);
int i = 0, j = 0, n = text.length(), m = pattern.length();
while (i < n) {
if (text.charAt(i) == pattern.charAt(j)) {
i++;
j++;
}
if (j == m) {
matchedIndexes.add(i - j);
j = lps[j - 1];
}
if (i < n && text.charAt(i) != pattern.charAt(j)) {
if (j > 0) {
j = lps[j - 1];
} else {
i++;
}
}
}
return matchedIndexes;
}
private static Set<Long> getDivisors(long n) {
Set<Long> divisors = new HashSet<>();
divisors.add(1L);
divisors.add(n);
for (long i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
divisors.add(i);
divisors.add(n / i);
}
}
return divisors;
}
private static long getLCM(long a, long b) {
return (Math.max(a, b) / gcd(a, b)) * Math.min(a, b);
}
static long fac[];
static long ifac[];
private static void preCompute(int n) {
fac = new long[n + 1];
ifac = new long[n + 1];
fac[0] = ifac[0] = fac[1] = ifac[1] = 1;
int i;
for (i = 2; i < n + 1; i++) {
fac[i] = (i * fac[i - 1]) % mod;
ifac[i] = (power(i, mod - 2) * ifac[i - 1]) % mod;
}
}
private static long C(int n, int r) {
if (n < 0 || r < 0) return 1;
if (r > n) return 1;
return (fac[n] * ((ifac[r] * ifac[n - r]) % mod)) % mod;
}
static int getSum(int BITree[], int index) {
int sum = 0;
index = index + 1;
while (index > 0) {
sum+=BITree[index];
index -= index & (-index);
}
return sum;
}
public static void updateBIT(int BITree[], int index, int val) {
index = index + 1;
while (index <= BITree.length - 1) {
BITree[index] += val;
index += index & (-index);
}
}
static int[] constructBITree(int n) {
int BITree[] = new int[n + 1];
for (int i = 1; i <= n; i++)
BITree[i] = 0;
return BITree;
}
private static int upperBound(int a[], int l, int r, int x) {
if (l > r) return -1;
if (l == r) {
if (a[l] <= x) {
return -1;
} else {
return a[l];
}
}
int m = (l + r) / 2;
if (a[m] <= x) {
return upperBound(a, m + 1, r, x);
} else {
return upperBound(a, l, m, x);
}
}
private static void mul(long A[][], long B[][]) {
int i, j, k, n = A.length;
long C[][] = new long[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
for (k = 0; k < n; k++) {
C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
A[i][j] = C[i][j];
}
}
}
private static void power(long A[][], long base[][], long n) {
if (n < 2) {
return;
}
power(A, base, n / 2);
mul(A, A);
if (n % 2 == 1) {
mul(A, base);
}
}
static void reverse(int a[], int l, int r) {
while (l < r) {
int t = a[l];
a[l] = a[r];
a[r] = t;
l++;
r--;
}
}
public void rotate(int[] nums, int k) {
k = k % nums.length;
reverse(nums, 0, nums.length - k - 1);
reverse(nums, nums.length - k, nums.length - 1);
reverse(nums, 0, nums.length - 1);
}
private 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 int[] getNGE(int arr[]) {
Stack<Integer> s = new Stack<>();
int n = arr.length;
int nge[] = new int[n];
s.push(0);
for (int i = 1; i < n; i++) {
if (s.empty()) {
s.push(i);
continue;
}
while (!s.isEmpty() && arr[s.peek()] <= arr[i]) {
nge[s.peek()] = i;
s.pop();
}
s.push(i);
}
while (!s.isEmpty()) {
nge[s.peek()] = n;
s.pop();
}
return nge;
}
public static int[] getPSE(int arr[]) {
Stack<Integer> s = new Stack<>();
int n = arr.length;
int pse[] = new int[n];
s.push(n-1);
for (int i = n-2; i >= 0; i--) {
if (s.empty()) {
s.push(i);
continue;
}
while (!s.isEmpty() && arr[s.peek()] > arr[i]) {
pse[s.peek()] = i;
s.pop();
}
s.push(i);
}
while (!s.isEmpty()) {
pse[s.peek()] = -1;
s.pop();
}
return pse;
}
public static int[] getNSE(int arr[]) {
Stack<Integer> s = new Stack<>();
int n = arr.length;
int nse[] = new int[n];
s.push(0);
for (int i = 1; i < n-1; i++) {
if (s.empty()) {
s.push(i);
continue;
}
while (!s.isEmpty() && arr[s.peek()] > arr[i]) {
nse[s.peek()] = i;
s.pop();
}
s.push(i);
}
while (!s.isEmpty()) {
nse[s.peek()] = n;
s.pop();
}
return nse;
}
public int validSubarraySize(int[] nums, int threshold) {
int nse[]=getNSE(nums);
int pse[]=getPSE(nums);
for(int i=0;i<nums.length;i++){
int len=nse[i]-pse[i]-1;
if(nums[i]>threshold/len) {
return len;
}
}
return -1;
}
private static boolean isPal(String s){
for(int i=0,j=s.length()-1;i<j;i++,j--){
if(s.charAt(i)!=s.charAt(j))return false;
}
return true;
}
private static int[] getSuffixArray(String s) {
int n=s.length();
int su[][]=new int[n][3];
for(int i=0;i<n;i++){
su[i]=new int[]{i, s.charAt(i)-'$', 0};
}
for(int i=0;i<n;i++){
su[i][2]=(i+1<n?su[i+1][1]:-1);
}
Arrays.sort(su, (a,b)->a[1]==b[1]?a[2]-b[2]:a[1]-b[1]);
int ind[]=new int[n];
for(int l=4;l<2*n;l*=2){
int rank=0,prev=su[0][1];
su[0][1]=0;
ind[su[0][0]]=0;
for(int i=1;i<n;i++){
if(su[i][1]==prev&&su[i][2]==su[i-1][2]){
su[i][1]=rank;
} else {
prev=su[i][1];
su[i][1]=++rank;
}
ind[su[i][1]]=1;
}
for(int i=0;i<n;i++){
int np=su[i][1]+l/2;
su[i][2]=(np<n?su[ind[np]][1]:-1);
}
Arrays.sort(su, (a,b)->a[1]==b[1]?a[2]-b[2]:a[1]-b[1]);
}
int suf[]=new int[n];
for(int i=0;i<n;i++){
suf[i]=su[i][0];
}
return suf;
}
private static boolean isPossible(int a[], int skip, int q) {
for(int i=0;i<a.length;i++){
if(a[i]>q){
if(skip>0){
skip--;
} else if(q==0){
return false;
} else {
q--;
}
}
}
return true;
}
public static void main(String[] args) throws Exception {
long START_TIME = System.currentTimeMillis();
try (FastReader in = new FastReader();
FastWriter out = new FastWriter()) {
int n, t, i, j, f, k, m, ti, tidx, gm, g, l,r,q;
for (t = in.nextInt(), tidx = 1; tidx <= t; tidx++)
{
long x = 0, y = 0, z = 0, sum = 0, bhc = 0, ans = 0;
//out.print(String.format("Case #%d: ", tidx));
n=in.nextInt();
q=in.nextInt();
int a[]=in.nextIntArr(n);
int lo=0,hi=n,mid,skip=0;
while(lo<=hi){
mid=(lo+hi)/2;
if(isPossible(a, mid, q)) {
skip=mid;
hi=mid-1;
} else {
lo=mid+1;
}
}
StringBuilder sb=new StringBuilder();
for(i=0;i<a.length;i++){
if(a[i]>q){
if(skip>0){
skip--;
sb.append(0);
} else {
q--;
sb.append(1);
}
} else {
sb.append(1);
}
}
out.println(sb.toString());
}
/*if (args.length > 0 && "ex_time".equals(args[0])) {
out.print("\nTime taken: ");
out.println(System.currentTimeMillis() - START_TIME);
}*/
out.commit();
}
}
public static class FastReader implements Closeable {
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private StringTokenizer st;
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception 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[] nextIntArr(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Integer[] nextIntegerArr(int n) {
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
double[] nextDoubleArr(int n) {
double[] arr = new double[n];
for (int i = 0; i < n; i++) {
arr[i] = nextDouble();
}
return arr;
}
long[] nextLongArr(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
List<Long> nextLongList(int n) {
List<Long> retList = new ArrayList<>();
for (int i = 0; i < n; i++) {
retList.add(nextLong());
}
return retList;
}
String[] nextStrArr(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = next();
}
return arr;
}
int[][] nextIntArr2(int n, int m) {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++) {
arr[i] = nextIntArr(m);
}
return arr;
}
long[][] nextLongArr2(int n, int m) {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++) {
arr[i] = nextLongArr(m);
}
return arr;
}
@Override
public void close() throws IOException {
br.close();
}
}
public static class FastWriter implements Closeable {
BufferedWriter bw;
StringBuilder sb = new StringBuilder();
List<String> list = new ArrayList<>();
Set<String> set = new HashSet<>();
public FastWriter() {
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
<T> void commit() throws IOException {
bw.write(sb.toString());
bw.flush();
sb = new StringBuilder();
}
public <T> void print(T obj) throws IOException {
sb.append(obj.toString());
commit();
}
public void println() throws IOException {
print("\n");
}
public <T> void println(T obj) throws IOException {
print(obj.toString() + "\n");
}
<T> void printArrLn(T[] arr) throws IOException {
for (int i = 0; i < arr.length - 1; i++) {
print(arr[i] + " ");
}
println(arr[arr.length - 1]);
}
<T> void printArr2(T[][] arr) throws IOException {
for (int j = 0; j < arr.length; j++) {
for (int i = 0; i < arr[j].length - 1; i++) {
print(arr[j][i] + " ");
}
println(arr[j][arr[j].length - 1]);
}
}
<T> void printColl(Collection<T> coll) throws IOException {
List<String> stringList = coll.stream().map(e -> ""+e).collect(Collectors.toList());
println(String.join(" ", stringList));
}
void printCharN(char c, int n) throws IOException {
for (int i = 0; i < n; i++) {
print(c);
}
}
void printIntArr(int []arr) throws IOException {
for (int i = 0; i < arr.length - 1; i++) {
print(arr[i] + " ");
}
println(arr[arr.length - 1]);
}
void printIntArr2(int[][] arr) throws IOException {
for (int j = 0; j < arr.length; j++) {
for (int i = 0; i < arr[j].length - 1; i++) {
print(arr[j][i] + " ");
}
println(arr[j][arr[j].length - 1]);
}
}
@Override
public void close() throws IOException {
bw.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 | f630bc3e77ef96a61acf4357f225ce2b | 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>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.*;
import static java.lang.Math.*;
public class Main {
static double pi = 3.141592653589;
static int mod = (int) 1e9 + 7;
public static void main(String[] args) throws IOException {
int qwe = in.nextInt();
while (qwe-- > 0)
{
solve();
}
out.close();
}
/*
*/
public static void solve() {
int n = in.nextInt();
int q = in.nextInt();
int[] num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = in.nextInt();
}
boolean[] ok = new boolean[n];
StringBuffer str = new StringBuffer("");
for (int i = 0; i < n; i++) {
if (num[i]<=q){
ok[i] = true;
}
}
// for (int i = n-1; i >=0 ; i--) {
// if (!ok[i] && q>0){
// q--;
// ok[i] = true;
// }
// }
// for (int i = 0; i < n; i++) {
// if (ok[i]){
// str.append("1");
// }else {
// str.append("0");
// }
// }
int cur = 0;
for (int i = n-1; i >= 0; i--) {
if (cur >= num[i]){
ok[i] = true;
}else {
if (q>0){
ok[i] = true;
cur++;
q--;
}
}
}
for (int i = 0; i < n; i++) {
if (ok[i]){
str.append("1");
}else {
str.append("0");
}
}
out.println(str);
out.flush();
}
static class pair {
int min;
int max;
public pair(int a, int b) {
this.min = a;
this.max = b;
}
}
/*
*/
// static int N = 1010;
// static int n,m;
// static int INF = 0x3f3f3f3f;
// static int[][] g = new int[N][N]; // 存储每条边 邻接矩阵
// static int[] dist = new int[N]; // 存储1号点到每个点的最短距离
// static boolean[] st = new boolean[N]; // 存储每个点的最短路是否已经确定
// static void init(){
// Arrays.fill(dist, INF);
// for (int i = 0; i <= n; i++) Arrays.fill(g[i],0x3f3f3f3f);
// }
// // 求x号点到y号点的最短路,如果不存在则返回-1
// static int dijkstra(int x, int y) {
// dist[x] = 0;
// for (int i = 1; i < n; i++) {
// int t = -1; // 在还未确定最短路的点中,寻找距离最小的点
// for (int j = 1; j <= n; j++)
// if (!st[j] && (t == -1 || dist[t] > dist[j]))
// t = j;
//
// st[t] = true;
// // 用t更新其他点的距离
// for (int j = 1; j <= n; j++) dist[j] = Math.min(dist[j], dist[t] + g[t][j]);
// }
// if (dist[y] == INF) return -1;
// return dist[y];
// }
// static int N = 1000 * 26;
// static int[][] trie = new int[N][26];;
// static int[] cnt = new int[N];
// static int idx;
// static void insert_trie(String s) {
// int p = 0;
// for (int i = 0; i < s.length(); i++) {
// int u = s.charAt(i) - 'a'; //如果是大写字母,则需要改成大写A
// if (trie[p][u] == 0) trie[p][u] = ++idx;
// p = trie[p][u];
// }
// cnt[p]++;
// }
// static int search_trie(String s){
// int p = 0;
// for (int i = 0; i < s.length(); i ++ ){
// int u = s.charAt(i) - 'a';
// if (trie[p][u] == 0) return 0;
// p = trie[p][u];
// }
// return cnt[p];
// }
static void kmp(String s1, String s2) { //短字符串、长字符串
int n = s1.length(); //短字符串
int m = s2.length();
char[] p = (" " + s1).toCharArray();//短字符串
char[] s = (" " + s2).toCharArray();
// 构造ne数组
int[] ne = new int[n + 1];
for (int i = 2, j = 0; i <= n; i++) {
while (j != 0 && p[i] != p[j + 1]) j = ne[j];
if (p[i] == p[j + 1]) j++;
ne[i] = j;
}
// kmp匹配
for (int i = 1, j = 0; i <= m; i++) {
while (j != 0 && s[i] != p[j + 1]) j = ne[j];
if (s[i] == p[j + 1]) j++;
if (j == n) { // 匹配了n字符了即代表完全匹配了
out.print(i - n + " "); // 输出在s串中p出现的位置
j = ne[j]; // 完全匹配后继续搜索
}
out.flush();
}
}
// static int N = 100010;
// static int idx = 0; //节点位置
// static char[] str = new char[N];
// static int[] cnt = new int[N];
// static int[][] son = new int[N][26];
// public static void insert(char[] str) {
// int p = 0; //从根节点出发
// for (char i : str) {
// int u = i - 'a';
// if (son[p][u] == 0) son[p][u] = ++idx;
// p = son[p][u];
// }
// cnt[p]++;
// }
// public static int query(char[] str) {
// int p = 0;
// for (char i : str) {
// int u = i - 'a';
// if (son[p][u] == 0) return 0;
// p = son[p][u];
// }
// return cnt[p];
// }
// static int bsearch_l(int l, int r, long target) {
// while (l < r) {
// int mid = l + r >> 1;
// if (num[mid] >= target) r = mid;
// else l = mid + 1;
// }
// return l;
// }
//
// static int bsearch_r(int l, int r, long target) {
// while (l < r) {
// int mid = l + r + 1 >> 1;
// if (num[mid] <= target) l = mid;
// else r = mid - 1;
// }
// return l;
// }
// static double bsearch_d(double l, double r) {
// double eps = 1e-8;
// while (Math.abs(r - l) > eps) {
// double mid = (l + r) / 2;
// if (check(mid)) r = mid;
// else l = mid;
// }
// return l;
// }
// static boolean check(int mid) {
// return true;
// }
public static long ksm(long n, long m) {//本质为n^m
long res = 1, base = n;
while (m != 0) {
if ((m & 1) == 1) { //等价于m%2==1,也就是m为奇数时
res = mul(res, base) % mod;
}
base = mul(base, base) % mod;//m为偶数时,base自乘
m = m >> 1;//等价于m/2
}
return res % mod;
}
static long mul(long a, long b) {//本质为a*b
long ans = 0;
while (b != 0) {
if ((b & 1) == 1) {
ans = (ans + a) % mod;
}
a = (a + a) % mod;
b = b >> 1;
}
return ans % mod;
}
public static long cnm(int a, int b) {
long sum = 1;
int i = a, j = 1;
while (j <= b) {
sum = sum * i / j;
i--;
j++;
}
return sum;
}
public static 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 void gbSort(int[] a, int l, int r) {
if (l < r) {
int m = (l + r) >> 1;
gbSort(a, l, m);
gbSort(a, m + 1, r);
int[] t = new int[r - l + 1];
int idx = 0, i = l, j = m + 1;
while (i <= m && j <= r)
if (a[i] <= a[j]) t[idx++] = a[i++];
else t[idx++] = a[j++];
while (i <= m) t[idx++] = a[i++];
while (j <= r) t[idx++] = a[j++];
for (int z = 0; z < t.length; z++) a[l + z] = t[z];
}
}
static InputReader in = new InputReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
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();
}
boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
return false;
// TODO: handle exception
}
}
return true;
}
public String nextLine() {
String str = null;
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
public BigDecimal nextBigDecimal() {
return new BigDecimal(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 | da2cbcc2425c59bd94904a2f2bee94e6 | 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>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 {
public static void main(String[] args) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
int[] test = new int[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
test[i] = Integer.parseInt(st.nextToken());
}
int temp = 0;
StringBuilder tempSb = new StringBuilder();
for (int i = n-1; i >= 0; i--) {
if (temp < q) {
tempSb.append("1");
if (temp < test[i]) {
temp++;
}
}
else {
if (q >= test[i]) {
tempSb.append("1");
} else {
tempSb.append("0");
}
}
}
tempSb.reverse();
sb.append(tempSb.toString()+"\n");
}
System.out.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 | |
PASSED | 2d5d6977d6f8206b6acf799a3f05a595 | 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>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 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
{
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args) throws java.lang.Exception
{
Reader sc = new Reader();
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
int q = sc.nextInt();
int st = 0;
int arr[] = new int[n];
for(int i = 0 ; i < n ; i++)
{
arr[i] = sc.nextInt();
}
int ans[] = new int[n];
for(int i = n-1 ; i >= 0 ; i--)
{
if(arr[i] > st)
{
if(st < q)
{
st++;
ans[i] = 1;
}
}
else
{
ans[i] = 1;
}
}
StringBuffer str = new StringBuffer("");
for(int i = 0 ; i < n ; i++)
{
str.append(ans[i]);
}
System.out.println(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 | 88afca127dabd66f6ad2d49f3843c56b | 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>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.company;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Rough_Work {
public static void main(String[] args) throws IOException {
new Rough_Work().TestCases();
}
void TestCases() throws IOException{
int t = nextInt();
while (t-->0) {
solve();
}
out.flush();
} // Put t = 1, for NO testcases // out.flush() is written in this method
void solve () throws IOException {
int n = nextInt();
int q = nextInt();
int[] arr = nextIntArray(n);
StringBuilder sb = new StringBuilder();
int temp = 0;
for (int i = n-1; i >= 0; i--) {
if (arr[i] > temp) {
if (q > temp) {
sb.append(1);
temp++;
}
else sb.append(0);
}
else sb.append(1);
}
out.println(sb.reverse());
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st;
void printIntArray (int[] arr) {
for (int z : arr) out.print(z+" ");
out.println();
}
void printIntList (ArrayList<Integer> arr) {
for (int z : arr) out.print(z+" ");
out.println();
}
void printLongArray (long[] arr) {
for (long z : arr) out.print(z+" ");
out.println();
}
void printLongList (ArrayList<Long> arr) {
for (long z : arr) out.print(z+" ");
out.println();
}
String next () throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine().trim());
return st.nextToken();
}
int nextInt () throws IOException {
return Integer.parseInt(next());
}
int[] nextIntArray (int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = nextInt();
return arr;
}
long nextLong () throws IOException {
return Long.parseLong(next());
}
long[] nextLongArray (int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = nextLong();
return arr;
}
ArrayList<Long> nextLongList (int n) throws IOException {
ArrayList<Long> lis = new ArrayList<>(n);
for (int i = 0; i < n; i++) lis.add(nextLong());
return lis;
}
double nextDouble () throws IOException {
return Double.parseDouble(next());
}
char nextChar () throws IOException {
return next().charAt(0);
}
String nextLine () throws IOException {
return br.readLine().trim();
}
boolean is_Sorted_int (int[] arr) {
for (int i = 0; i < arr.length-1; i++) if (arr[i] > arr[i+1]) return false;
return true;
}
boolean is_Sorted_long (long[] arr) {
for (int i = 0; i < arr.length-1; i++) if (arr[i] > arr[i+1]) return false;
return true;
}
long gcd(long a, long b) { return (b==0?a:gcd(b,a%b)); }
long lcm(long a, long b) { return (a / gcd(a, b)) * b; }
ArrayList<Integer> Factors(int n) {
ArrayList<Integer> ret = new ArrayList<>();
for (int i=1; i<=Math.sqrt(n); i++) {
if (n%i==0) {
// If divisors are equal, print only one
if (n/i != i) ret.add(n/i);
ret.add(i);
}
}
return ret;
}
boolean check_Integer (double a) {return Math.ceil(a) == Math.floor(a);}
static class Pair implements Comparable<Pair> {
long f;
long s;
public Pair (long f, long s) {
this.f = f;
this.s = s;
}
@Override
public int compareTo(Pair o) {
if (this.s == o.s) return Long.compare(this.f,o.f);
else return Long.compare(this.s,o.s);
}
} // Comparable on basis of first then second.
static class Triplet {
long f;
long s;
long t;
public Triplet (long f, long s, long t) {
this.f = f;
this.s = s;
this.t = t;
}
} // Implement comparable accordingly.
long mod = 1_000_000_007;
long mod_Multiply(long a,long b) {
return (a*b)%mod;
}
long mod_factorial (long n) {
long fact =1;
for(int i=1; i<=n; i++) {
fact = mod_Multiply(fact,i);
}
return fact%mod;
}
long mod_power(long x, long y) {
long temp;
if (y == 0) return 1;
temp = mod_power(x, y / 2);
if ((y&1) == 0) return mod_Multiply(temp,temp);
else {
if (y > 0) return mod_Multiply(x,mod_Multiply(temp,temp));
else return (mod_Multiply(temp,temp)) / x;
}
}
void Print_all_subsequence (int i, int[] x) {
if (i >= x.length) {
printIntArray(x);
return;
}
for (int j = i; j < x.length; j++) {
XOR_Swap(i,j,x);
Print_all_subsequence(i+1,x);
XOR_Swap(i,j,x);
}
}
void XOR_Swap (int i, int j, int[] x) {
if (i == j) return;
x[i] = x[i]^x[j];
x[j] = x[i]^x[j];
x[i] = x[i]^x[j];
} // works only for numbers..
boolean[] prime;
void sieveOfEratosthenes(int n) {
prime = new boolean[n + 1];
Arrays.fill(prime,true);
prime[0] = prime[1] = false;
//for (int i = 2; i <= n; i++) prime[i] = true;
for (int p = 2; p * p <= n; p++) {
if (prime[p])
{
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
} // Gives prime numbers less than equal to n in boolean[] array prime.
int[] LPS_array (String s) {
int[] arr = new int[s.length()];
int j = 0;
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == s.charAt(j)) {
arr[i] = j + 1;
j++;
}
else {
boolean f = true;
while (j > 0) {
j = arr[j-1];
if (s.charAt(i) == s.charAt(j)) {
arr[i] = j + 1;
j++;
f = false;
break;
}
}
if (f) arr[i] = 0;
}
}
return arr;
} // Longest Prefix Suffix array for pattern searching
}
| 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 | f3d6f5771e5e85f4909e06da24a7c89d | 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>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 {
public static void main(String[] args) throws IOException {
//BufferedReader f = new BufferedReader(new FileReader("uva.in"));
//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("milkvisits.out")));
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(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());
st = new StringTokenizer(f.readLine());
int[] a = new int[n];
for(int i = n-1; i >= 0; i--) {
a[i] = Integer.parseInt(st.nextToken());
}
int c = 0;
StringBuilder res = new StringBuilder();
for(int i: a) {
if(i > c && c < q) {
c++;
res.append(1);
} else if(i <= c) {
res.append(1);
} else {
res.append(0);
}
}
out.println(res.reverse());
}
f.close();
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 | 03b128948ed9a83277eeddd14acd16ad | 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>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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
CDoremysIQ solver = new CDoremysIQ();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class CDoremysIQ {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt(), q = in.nextInt();
int[] arr = in.nextIntArray(n);
int[] ans = new int[n];
int now = 0;
for (int i = n - 1; i >= 0; i--) {
if (arr[i] <= now) {
ans[i] = 1;
} else {
if (now == q) {
continue;
}
ans[i] = 1;
now++;
}
}
for (int a : ans) {
out.print(a);
}
out.println();
}
}
static class InputReader {
BufferedReader reader;
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[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println() {
writer.println();
}
public void close() {
writer.close();
}
public void print(int i) {
writer.print(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 | a22f73f154f0ba1b612c0da22f408940 | 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>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 c;
import java.util.*;
import java.io.*;
public class C {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
int cases=Integer.parseInt(br.readLine());
for(int d=0;d<cases;d++){
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
int iq=Integer.parseInt(st.nextToken());
int[] arr=new int[n];
st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(st.nextToken());
}
boolean[] bool=new boolean[n];
if(iq>=n){
Arrays.fill(bool,true);
}else{
int counter=0;
int index=-1;
for(int i=n-1;i>=0;i--){
if(arr[i]>counter){
counter++;
}
if(counter>iq){
index=i;
break;
}
bool[i]=true;
}
for(int i=0;i<=index;i++){
if(iq>=arr[i]){
bool[i]=true;
}
}
}
StringBuilder sb=new StringBuilder();
for(int i=0;i<n;i++){
if(bool[i]){
sb.append(1);
}else{
sb.append(0);
}
}
pw.println(sb);
}
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 | 812294c9fde9816e03cf6e17b5203398 | 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>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.util.Map.Entry;
import javax.swing.ToolTipManager;
import org.xml.sax.HandlerBase;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.*;
import java.sql.Array;
public class Simple{
public static class Node{
int v;
int val;
public Node(int v,int val){
this.val = val;
this.v = v;
}
}
static final Random random=new Random();
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();
}
}
static void ruffleSort(int[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
long oi=random.nextInt(n), temp=a[(int)oi];
a[(int)oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
public static class Pair implements Comparable<Pair>{
int x;
int y;
public Pair(int x,int y){
this.x = x;
this.y = y;
}
public int compareTo(Pair other){
return this.y - other.y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair other = (Pair) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
// public boolean equals(Pair other){
// if(this.x == other.x && this.y == other.y)return true;
// return false;
// }
// public int hashCode(){
// return 31*x + y;
// }
// @Override
// public int compareTo(Simple.Pair o) {
// // TODO Auto-generated method stub
// return 0;
// }
}
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more than or
// equal to p
x = x % p;
while (y > 0) {
// If y is odd, multiply x
// with result
if (y % 2 == 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Returns n^(-1) mod p
static long modInverse(long n, long p)
{
return power(n, p - 2, p);
}
static long[] fac = new long[100000 + 1];
// Returns nCr % p using Fermat's
// little theorem.
static long nCrModPFermat(long n, long r,
long p)
{
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
return (fac[(int)n] * modInverse(fac[(int)r], p)
% p * modInverse(fac[(int)n - (int)r], p)
% p)
% p;
}
static int nCrModp(int n, int r, int p)
{
if (r > n - r)
r = n - r;
// The array C is going to store last
// row of pascal triangle at the end.
// And last entry of last row is nCr
int C[] = new int[r + 1];
C[0] = 1; // Top row of Pascal Triangle
// One by constructs remaining rows of Pascal
// Triangle from top to bottom
for (int i = 1; i <= n; i++) {
// Fill entries of current row using previous
// row values
for (int j = Math.min(i, r); j > 0; j--)
// nCj = (n-1)Cj + (n-1)C(j-1);
C[j] = (C[j] + C[j - 1]) % p;
}
return C[r];
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcd_long(long a, long b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd_long(a-b, b);
return gcd_long(a, b-a);
}
// public static int helper(int arr[],int n ,int i,int j,int dp[][]){
// if(i==0 || j==0)return 0;
// if(dp[i][j]!=-1){
// return dp[i][j];
// }
// if(helper(arr, n, i-1, j-1, dp)>=0){
// return dp[i][j]=Math.max(helper(arr, n, i-1, j-1,dp)+arr[i-1], helper(arr, n, i-1, j,dp));
// }
// return dp[i][j] = helper(arr, n, i-1, j,dp);
// }
// public static void dfs(ArrayList<ArrayList<Integer>> al,int levelcount[],int node,int count){
// levelcount[count]++;
// for(Integer x : al.get(node)){
// dfs(al, levelcount, x, count+1);
// }
// }
public static long __gcd(long a, long b)
{
if (b == 0)
return a;
return __gcd(b, a % b);
}
public static class DSU{
int n;
int par[];
int rank[];
public DSU(int n){
this.n = n;
par = new int[n+1];
rank = new int[n+1];
for(int i=1;i<=n;i++){
par[i] = i ;
rank[i] = 0;
}
}
public int findPar(int node){
if(node==par[node]){
return node;
}
return par[node] = findPar(par[node]);//path compression
}
public void union(int u,int v){
u = findPar(u);
v = findPar(v);
if(rank[u]<rank[v]){
par[u] = v;
}
else if(rank[u]>rank[v]){
par[v] = u;
}
else{
par[v] = u;
rank[u]++;
}
}
}
public static boolean isPallindrome(char[] arr,int n,boolean vis[]){
int i=0;
int j= n-1;
while(i<j){
if(vis[i])i++;
else if(vis[j])j--;
else{
if(arr[i]!=arr[j])return false;
i++;
j--;
}
}
return true;
}
public static List<List<Integer>> permute(int[] nums) {
List<Integer> list = new ArrayList<>();
List<List<Integer>> ans = new ArrayList<>();
helper(ans,list,nums,nums.length);
return ans;
}
public static void helper(List<List<Integer>> ans,List<Integer> list,int nums[],int n){
if(list.size()==n){
ans.add(new ArrayList<>(list));
return;
}
for(int i=0;i<n;i++){
if(!list.contains(nums[i])){
list.add(nums[i]);
helper(ans,list,nums,n);
list.remove(list.size()-1);
}
}
}
static int level = 0;
static ArrayList<Integer> nodes;
public static int printShortestPath(Map<Integer,Integer> par, int s, int d)
{
level = 0;
// If we reached root of shortest path tree
if (par.get(s) == -1)
{
System.out.printf("Shortest Path between"+
"%d and %d is %s ", s, d, s);
return level;
}
printShortestPath(par, par.get(s), d);
level++;
// if (s < this.V)
// System.out.printf("%d ", s);
return level;
}
// finds shortest path from source vertex 's' to
// destination vertex 'd'.
// This function mainly does BFS and prints the
// shortest path from src to dest. It is assumed
// that weight of every edge is 1
public static void swap(char arr[],int i){
char c = arr[i];
arr[i] = arr[i+1];
arr[i+1] = c;
}
public static String mul(String str,int n){
int carry = 0;
StringBuilder muli = new StringBuilder();
for(int i=n-1;i>=0;i--){
int val = str.charAt(i) - '0';
int ans = val*2 + carry;
carry = ans/10;
ans = ans%10;
char c = (char)(ans + '0');
muli.append(c);
}
if(carry!=0){
muli.append((char)(carry + '0'));
}
muli.reverse();
return muli.toString();
}
static boolean isSmaller(String str1, String str2)
{
// Calculate lengths of both string
int n1 = str1.length(), n2 = str2.length();
if (n1 < n2)
return true;
if (n2 < n1)
return false;
for (int i = 0; i < n1; i++)
if (str1.charAt(i) < str2.charAt(i))
return true;
else if (str1.charAt(i) > str2.charAt(i))
return false;
return false;
}
// Function for find difference of larger numbers
static String findDiff(String str1, String str2)
{
// Before proceeding further, make sure str1
// is not smaller
if (isSmaller(str1, str2)) {
String t = str1;
str1 = str2;
str2 = t;
}
// Take an empty string for storing result
String str = "";
// Calculate length of both string
int n1 = str1.length(), n2 = str2.length();
// Reverse both of strings
str1 = new StringBuilder(str1).reverse().toString();
str2 = new StringBuilder(str2).reverse().toString();
int carry = 0;
// Run loop till small string length
// and subtract digit of str1 to str2
for (int i = 0; i < n2; i++) {
// Do school mathematics, compute difference of
// current digits
int sub
= ((int)(str1.charAt(i) - '0')
- (int)(str2.charAt(i) - '0') - carry);
// If subtraction is less then zero
// we add then we add 10 into sub and
// take carry as 1 for calculating next step
if (sub < 0) {
sub = sub + 10;
carry = 1;
}
else
carry = 0;
str += (char)(sub + '0');
}
// subtract remaining digits of larger number
for (int i = n2; i < n1; i++) {
int sub = ((int)(str1.charAt(i) - '0') - carry);
// if the sub value is -ve, then make it
// positive
if (sub < 0) {
sub = sub + 10;
carry = 1;
}
else
carry = 0;
str += (char)(sub + '0');
}
// reverse resultant string
return new StringBuilder(str).reverse().toString();
}
public static double cal1(double x1,double x2,double y1,double y2){
double x = Math.abs(x1 - x2);
double y = Math.abs(y1 - y2);
double ans = x*x + y*y;
return Math.sqrt(ans);
}
static final int MAXN = 100001;
// stores smallest prime factor for every number
static int spf[] = new int[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
static void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
// checking if i is prime
if (spf[i] == i)
{
// marking SPF for all numbers divisible by i
for (int j=i*i; j<MAXN; j+=i)
// marking spf[j] if it is not
// previously marked
if (spf[j]==j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
static Vector<Integer> getFactorization(int x)
{
Vector<Integer> ret = new Vector<>();
while (x != 1)
{
ret.add(spf[x]);
x = x / spf[x];
}
return ret;
}
public static long dfs(long index,int currIndex,long arr[][],int n){
if(currIndex==-1)return 1;
if(index <=n){
return index;
}
if(index< arr[currIndex][3]){
return dfs(index, currIndex -1 , arr, n);
}
else{
long nindex = arr[currIndex][0] + index - arr[currIndex][3];
return dfs(nindex, currIndex-1, arr, n);
}
}
public static void main(String args[]){
// try {
// FastReader s=new FastReader();
// FastWriter out = new FastWriter();
Scanner s = new Scanner(System.in);
int testCases=s.nextInt();
// int testCases = 1;
// sieve();
// int something = 0;
while(testCases-- > 0){
// counter++;
int n = s.nextInt();
int k = s.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i] = s.nextInt();
}
int points = 0;
int ans[] = new int[n];
for(int i=n-1;i>=0;i--){
if(points >= arr[i]){
ans[i] = 1;
}
else{
if(points + 1<=k){
ans[i] = 1;
points++;
}
else{
}
}
}
for(int i=0;i<n;i++){
System.out.print(ans[i]);
}
System.out.println();
}
// }
// catch (Exception e) {
// System.out.println(e.toString());
// // System.out.println("Eh");
// return;
// }
}
}
/*
1 3 4 5 2
2 4 3 5 1
*/ | 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 | 8f35ed80efc81c56a184470424fc3e8a | train_109.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>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 | /*
Goal: Become better in CP!
Key: Consistency and Discipline
Desire: SDE @ Google USA
Motto: Do what i Love <=> Love what i do
If you don't use your brain 100%, it deteriorates gradually
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static StringBuffer str=new StringBuffer();
static BufferedReader bf;
static PrintWriter pw;
static int n;
static long q;
static long a[];
static int pat[];
static boolean poss(int cnt){
long power=q;
// greedy idea: It's better to do contest that
// are not able to at the end
for(int i=0;i<n;i++){
int left=n-i;
// from here we need do every contest
if(cnt==left){
cnt--;
if(a[i]>power) power--;
}else if(a[i]<=power) cnt--;
}
return power>=0;
}
static void solve(int te) throws Exception{
int l=-1, r=n+1;
while(r-l>1){
int mid=l+(r-l)/2;
if(poss(mid)) l=mid;
else r=mid;
}
int cnt=l;
long power=q;
for(int i=0;i<n;i++){
int left=n-i;
// from here we need do every contest
if(cnt==left){
cnt--;
str.append(1);
if(a[i]>power){
power--;
}
}else if(a[i]<=power){
str.append(1);
cnt--;
}else str.append(0);
}
str.append("\n");
}
public static void main(String[] args) throws java.lang.Exception {
boolean lenv=false;
int te=1;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q1 = Integer.parseInt(bf.readLine().trim());
for(te=1;te<=q1;te++) {
String s[]=bf.readLine().trim().split("\\s+");
n=Integer.parseInt(s[0]);
q=Long.parseLong(s[1]);
a=new long[n];
s=bf.readLine().trim().split("\\s+");
for(int i=0;i<n;i++) a[i]=Long.parseLong(s[i]);
solve(te);
}
pw.print(str);
pw.flush();
// System.out.println(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 8 | 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 | 99fd230728949817aac784df7d11ea60 | train_109.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>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 | /*
Goal: Become better in CP!
Key: Consistency and Discipline
Desire: SDE @ Google USA
Motto: Do what i Love <=> Love what i do
If you don't use your brain 100%, it deteriorates gradually
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class A {
static StringBuffer str=new StringBuffer();
static int n;
static long q;
static long a[];
static void solve(){
long Q=0;
int ans[]=new int[n];
for(int i=n-1;i>=0;i--){
if(a[i]<=Q) ans[i]=1;
if(a[i]>Q && Q<q){
Q++;
ans[i]=1;
}
}
for(int i=0;i<n;i++) str.append(ans[i]);
str.append("\n");
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader bf;
PrintWriter pw;
boolean lenv=false;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q1 = Integer.parseInt(bf.readLine().trim());
while (q1-- > 0) {
String s[]=bf.readLine().trim().split("\\s+");
n=Integer.parseInt(s[0]);
q=Long.parseLong(s[1]);
s=bf.readLine().trim().split("\\s+");
a=new long[n];
for(int i=0;i<n;i++) a[i]=Long.parseLong(s[i]);
solve();
}
pw.println(str);
pw.flush();
// System.outin.print(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 8 | 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 | 587c835dd55af280dce01f53d5fdcf08 | train_109.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>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 | /*
Goal: Become better in CP!
Key: Consistency and Discipline
Desire: SDE @ Google USA
Motto: Do what i Love <=> Love what i do
If you don't use your brain 100%, it deteriorates gradually
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class A {
static StringBuffer str=new StringBuffer();
static int n;
static long q;
static long a[];
static boolean isPoss(int idx){
long tq=q;
for(int i=idx;i<n;i++){
if(a[i]<=tq) continue;
tq--;
}
return tq>=0;
}
static void solve(){
List<Integer> v=new ArrayList<>();
for(int i=0;i<n;i++) if(a[i]>q) v.add(i);
int l=0, r=v.size()-1;
int ans=-1;
while(l<=r){
int mid=l+(r-l)/2;
if(isPoss(v.get(mid))){
ans=v.get(mid);
r=mid-1;
}else l=mid+1;
}
if(ans==-1){
for(int i=0;i<n;i++){
if(a[i]<=q) str.append(1);
else str.append(0);
}
}else{
for(int i=0;i<ans;i++){
if(a[i]<=q) str.append(1);
else str.append(0);
}
for(int i=ans;i<n;i++) str.append(1);
}
str.append("\n");
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader bf;
PrintWriter pw;
boolean lenv=false;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q1 = Integer.parseInt(bf.readLine().trim());
while (q1-- > 0) {
String s[]=bf.readLine().trim().split("\\s+");
n=Integer.parseInt(s[0]);
q=Long.parseLong(s[1]);
s=bf.readLine().trim().split("\\s+");
a=new long[n];
for(int i=0;i<n;i++) a[i]=Long.parseLong(s[i]);
solve();
}
pw.println(str);
pw.flush();
// System.outin.print(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 8 | 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 | 4c5c1c7348f2d10ef12afbbc8cf8fa80 | train_109.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>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 |
// Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main(String[] args)throws IOException
{
Reader s = new Reader();
int t = s.nextInt();
while(t-->0){
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 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();
}
}
}
| 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 8 | 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 | 475a49bc28f2b49ff193ad9136bead89 | train_109.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>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 | // Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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)
{
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0){
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 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();
}
}
}
| 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 8 | 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 | dae0888ef43f5bddce807882ac6b5bbd | train_109.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>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 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();
}
}
} | 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 8 | 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 | 9ea764fba4557df647451a39dd2d6c61 | train_109.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>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.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(), Q = readInt();
int[] A = readIntArray(N);
int revQ = 0;
int[] ans = new int[N];
for (int i=N-1; i>=0; i--) {
if (A[i]<=revQ) ans[i]=1;
else if (revQ < Q) {
revQ++;
ans[i]=1;
}
}
for (int i=0; i<N; i++) out.print(ans[i]);
out.println();
}
}
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 | ["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 8 | 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 | 6cef0ea800e22f8a6ce831990092df25 | train_109.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>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 Main {
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
static final double pi=3.1415926536;
static long mod=1000000007;
// static long mod=998244353;
static int MAX=Integer.MAX_VALUE;
static int MIN=Integer.MIN_VALUE;
static long MAXL=Long.MAX_VALUE;
static long MINL=Long.MIN_VALUE;
static ArrayList<Integer> graph[];
static long fact[];
static long seg[];
// static int dp[][];
static long dp[][],dp2[][];
public static void main (String[] args) throws java.lang.Exception
{
// code goes here
int t=I();
outer:while(t-->0)
{
int n=I();
long q=L();
long a[]=IL(n);
if(q>=n){
for(int i=0;i<n;i++){
out.print("1");
}out.println();
}else{
long curr=0;
int ans[]=new int[n];
for(int i=n-1;i>=0;i--){
if(a[i]>curr && curr<q){
ans[i]=1;
curr++;
}else if(a[i]<=curr){
ans[i]=1;
}
}
for(int i=0;i<n;i++){
out.print(ans[i]);
}out.println();
}
}
out.close();
}
public static class pair
{
long a;
long b;
public pair(long aa,long bb)
{
a=aa;
b=bb;
}
}
public static class myComp implements Comparator<pair>
{
//sort in ascending order.
// public int compare(pair p1,pair p2)
// {
// if(p1.a==p2.a)
// return 0;
// else if(p1.a<p2.a)
// return -1;
// else
// return 1;
// }
// sort in descending order.
public int compare(pair p1,pair p2)
{
if(p1.b==p2.b)
return 0;
else if(p1.b<p2.b)
return 1;
else
return -1;
}
}
public static void setGraph(int n,int m)throws IOException
{
graph=new ArrayList[n+1];
for(int i=0;i<=n;i++){
graph[i]=new ArrayList<>();
}
for(int i=0;i<m;i++){
int u=I(),v=I();
graph[u].add(v);
graph[v].add(u);
}
}
//LOWER_BOUND and UPPER_BOUND functions
//It returns answer according to zero based indexing.
public static int lower_bound(long arr[],long X,int start, int end) //start=0,end=n-1
{
if(start>end)return -1;
// if(arr.get(arr.size()-1)<X)return end;
if(arr[arr.length-1]<X)return end;
// if(arr.get(0)>X)return -1;
if(arr[0]>X)return -1;
int left=start,right=end;
while(left<right){
int mid=(left+right)/2;
if(arr[mid]==X){ //Returns last index of lower bound value.
if(mid<end && arr[mid+1]==X){
left=mid+1;
}else{
return mid;
}
}
// if(arr.get(mid)==X){ //Returns first index of lower bound value.
// if(mid>start && arr.get(mid-1)==X){
// right=mid-1;
// }else{
// return mid;
// }
// }
else if(arr[mid]>X){
if(mid>start && arr[mid-1]<X){
return mid-1;
}else{
right=mid-1;
}
}else{
if(mid<end && arr[mid+1]>X){
return mid;
}else{
left=mid+1;
}
}
}
return left;
}
//It returns answer according to zero based indexing.
public static int upper_bound(ArrayList<Integer> arr,int X,int start,int end) //start=0,end=n-1
{
if(arr.get(0)>=X)return start;
if(arr.get(arr.size()-1)<X)return -1;
int left=start,right=end;
while(left<right){
int mid=(left+right)/2;
if(arr.get(mid)==X){ //returns first index of upper bound value.
if(mid>start && arr.get(mid-1)==X){
right=mid-1;
}else{
return mid;
}
}
// if(arr[mid]==X){ //returns last index of upper bound value.
// if(mid<end && arr[mid+1]==X){
// left=mid+1;
// }else{
// return mid;
// }
// }
else if(arr.get(mid)>X){
if(mid>start && arr.get(mid-1)<X){
return mid;
}else{
right=mid-1;
}
}else{
if(mid<end && arr.get(mid+1)>X){
return mid+1;
}else{
left=mid+1;
}
}
}
return left;
}
//END
//Segment Tree Code
public static void buildTree(long a[],int si,int ss,int se,long temp)
{
if(ss==se){
// seg[si]=new pair(a[ss],ss);
// seg[si].a=ss;
// seg[si].b=ss;
if(a[ss]>temp){
seg[si]=0;
}else{
seg[si]=a[ss];
}
return;
}
int mid=(ss+se)/2;
buildTree(a,2*si+1,ss,mid,temp);
buildTree(a,2*si+2,mid+1,se,temp);
seg[si]=max(seg[2*si+1],seg[2*si+2]);
}
// public static void update(int si,int ss,int se,int pos,int val)
// {
// if(ss==se){
// // seg[si]=val;
// return;
// }
// int mid=(ss+se)/2;
// if(pos<=mid){
// update(2*si+1,ss,mid,pos,val);
// }else{
// update(2*si+2,mid+1,se,pos,val);
// }
// // seg[si]=min(seg[2*si+1],seg[2*si+2]);
// if(seg[2*si+1].a < seg[2*si+2].a){
// seg[si].a=seg[2*si+1].a;
// seg[si].b=seg[2*si+1].b;
// }else{
// seg[si].a=seg[2*si+2].a;
// seg[si].b=seg[2*si+2].b;
// }
// }
public static long query1(long a[],int si,int ss,int se,int qs,int qe)
{
if(qs>qe)return 0;
if(qs>se || qe<ss)return 0;
if(ss>=qs && se<=qe)return seg[si];
int mid=(ss+se)/2;
long p1=query1(a,2*si+1,ss,mid,qs,qe);
long p2=query1(a,2*si+2,mid+1,se,qs,qe);
return max(p1,p2);
}
public static void merge(ArrayList<Integer> f,ArrayList<Integer> a,ArrayList<Integer> b)
{
int i=0,j=0;
while(i<a.size() && j<b.size()){
if(a.get(i)<=b.get(j)){
f.add(a.get(i));
i++;
}else{
f.add(b.get(j));
j++;
}
}
while(i<a.size()){
f.add(a.get(i));
i++;
}
while(j<b.size()){
f.add(b.get(j));
j++;
}
}
//Segment Tree Code end
//Prefix Function of KMP Algorithm
public static int[] KMP(char c[],int n)
{
int pi[]=new int[n];
for(int i=1;i<n;i++){
int j=pi[i-1];
while(j>0 && c[i]!=c[j]){
j=pi[j-1];
}
if(c[i]==c[j])j++;
pi[i]=j;
}
return pi;
}
public static long kadane(long a[],int n) //largest sum subarray
{
long max_sum=Long.MIN_VALUE,max_end=0;
for(int i=0;i<n;i++){
max_end+=a[i];
if(max_sum<max_end){max_sum=max_end;}
if(max_end<0){max_end=0;}
}
return max_sum;
}
public static long nPr(int n,int r)
{
long ans=divide(fact(n),fact(n-r),mod);
return ans;
}
public static long nCr(int n,int r)
{
long ans=divide(fact[n],mul(fact[n-r],fact[r]),mod);
return ans;
}
public static boolean isSorted(int a[])
{
int n=a.length;
for(int i=0;i<n-1;i++){
if(a[i]>a[i+1])return false;
}
return true;
}
public static boolean isSorted(long a[])
{
int n=a.length;
for(int i=0;i<n-1;i++){
if(a[i]>a[i+1])return false;
}
return true;
}
public static int computeXOR(int n) //compute XOR of all numbers between 1 to n.
{
if (n % 4 == 0)
return n;
if (n % 4 == 1)
return 1;
if (n % 4 == 2)
return n + 1;
return 0;
}
public static int np2(int x)
{
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
return x;
}
public static int hp2(int x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
public static long hp2(long x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
public static ArrayList<Integer> primeSieve(int n)
{
ArrayList<Integer> arr=new ArrayList<>();
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int i = 2; i <= n; i++)
{
if (prime[i] == true)
arr.add(i);
}
return arr;
}
// Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n);
public static class FenwickTree
{
int farr[];
int n;
public FenwickTree(int c)
{
n=c+1;
farr=new int[n];
}
// public void update_range(int l,int r,long p)
// {
// update(l,p);
// update(r+1,(-1)*p);
// }
public void update(int x,int p)
{
for(;x<n;x+=x&(-x))
{
farr[x]+=p;
}
}
public int get(int x)
{
int ans=0;
for(;x>0;x-=x&(-x))
{
ans=ans+farr[x];
}
return ans;
}
}
//Disjoint Set Union
public static class DSU
{
int par[],rank[];
public DSU(int c)
{
par=new int[c+1];
rank=new int[c+1];
for(int i=0;i<=c;i++)
{
par[i]=i;
rank[i]=0;
}
}
public int find(int a)
{
if(a==par[a])
return a;
return par[a]=find(par[a]);
}
public void union(int a,int b)
{
int a_rep=find(a),b_rep=find(b);
if(a_rep==b_rep)
return;
if(rank[a_rep]<rank[b_rep])
par[a_rep]=b_rep;
else if(rank[a_rep]>rank[b_rep])
par[b_rep]=a_rep;
else
{
par[b_rep]=a_rep;
rank[a_rep]++;
}
}
}
public static HashMap<Integer,Integer> primeFact(int a)
{
// HashSet<Long> arr=new HashSet<>();
HashMap<Integer,Integer> hm=new HashMap<>();
int p=0;
while(a%2==0){
// arr.add(2L);
p++;
a=a/2;
}
hm.put(2,hm.getOrDefault(2,0)+p);
for(int i=3;i*i<=a;i+=2){
p=0;
while(a%i==0){
// arr.add(i);
p++;
a=a/i;
}
hm.put(i,hm.getOrDefault(i,0)+p);
}
if(a>2){
// arr.add(a);
hm.put(a,hm.getOrDefault(a,0)+1);
}
// return arr;
return hm;
}
public static boolean isVowel(char c)
{
if(c=='a' || c=='e' || c=='i' || c=='u' || c=='o')return true;
return false;
}
public static boolean isInteger(double N)
{
int X = (int)N;
double temp2 = N - X;
if (temp2 > 0)
{
return false;
}
return true;
}
public static boolean isPalindrome(String s)
{
int n=s.length();
for(int i=0;i<=n/2;i++){
if(s.charAt(i)!=s.charAt(n-i-1)){
return false;
}
}
return true;
}
public static int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static long gcd(long a,long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static long fact(long n)
{
long fact=1;
for(long i=2;i<=n;i++){
fact=((fact%mod)*(i%mod))%mod;
}
return fact;
}
public static long fact(int n)
{
long fact=1;
for(int i=2;i<=n;i++){
fact=((fact%mod)*(i%mod))%mod;
}
return fact;
}
public static boolean isPrime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static boolean isPrime(long n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static void printArray(long a[])
{
for(int i=0;i<a.length;i++){
out.print(a[i]+" ");
}
out.println();
}
public static void printArray(int a[])
{
for(int i=0;i<a.length;i++){
out.print(a[i]+" ");
}
out.println();
}
public static void printArray(char a[])
{
for(int i=0;i<a.length;i++){
out.print(a[i]);
}
out.println();
}
public static void printArray(String a[])
{
for(int i=0;i<a.length;i++){
out.print(a[i]+" ");
}
out.println();
}
public static void printArray(boolean a[])
{
for(int i=0;i<a.length;i++){
out.print(a[i]+" ");
}
out.println();
}
public static void printArray(pair a[])
{
for(pair p:a){
out.println(p.a+"->"+p.b);
}
}
public static void printArray(int a[][])
{
for(int i=0;i<a.length;i++){
for(int j=0;j<a[i].length;j++){
out.print(a[i][j]+" ");
}out.println();
}
}
public static void printArray(long a[][])
{
for(int i=0;i<a.length;i++){
for(int j=0;j<a[i].length;j++){
out.print(a[i][j]+" ");
}out.println();
}
}
public static void printArray(char a[][])
{
for(int i=0;i<a.length;i++){
for(int j=0;j<a[i].length;j++){
out.print(a[i][j]+" ");
}out.println();
}
}
public static void printArray(ArrayList<?> arr)
{
for(int i=0;i<arr.size();i++){
out.print(arr.get(i)+" ");
}
out.println();
}
public static void printMapI(HashMap<?,?> hm){
for(Map.Entry<?,?> e:hm.entrySet()){
out.println(e.getKey()+"->"+e.getValue());
}out.println();
}
public static void printMap(HashMap<Long,ArrayList<Integer>> hm){
for(Map.Entry<Long,ArrayList<Integer>> e:hm.entrySet()){
out.print(e.getKey()+"->");
ArrayList<Integer> arr=e.getValue();
for(int i=0;i<arr.size();i++){
out.print(arr.get(i)+" ");
}out.println();
}
}
public static void printGraph(ArrayList<Integer> graph[])
{
int n=graph.length;
for(int i=0;i<n;i++){
out.print(i+"->");
for(int j:graph[i]){
out.print(j+" ");
}out.println();
}
}
//Modular Arithmetic
public static long add(long a,long b)
{
a+=b;
if(a>=mod)a-=mod;
return a;
}
public static long sub(long a,long b)
{
a-=b;
if(a<0)a+=mod;
return a;
}
public static long mul(long a,long b)
{
return ((a%mod)*(b%mod))%mod;
}
public static long divide(long a,long b,long m)
{
a=mul(a,modInverse(b,m));
return a;
}
public static long modInverse(long a,long m)
{
int x=0,y=0;
own p=new own(x,y);
long g=gcdExt(a,m,p);
if(g!=1){
out.println("inverse does not exists");
return -1;
}else{
long res=((p.a%m)+m)%m;
return res;
}
}
public static long gcdExt(long a,long b,own p)
{
if(b==0){
p.a=1;
p.b=0;
return a;
}
int x1=0,y1=0;
own p1=new own(x1,y1);
long gcd=gcdExt(b,a%b,p1);
p.b=p1.a - (a/b) * p1.b;
p.a=p1.b;
return gcd;
}
public static long pwr(long m,long n)
{
long res=1;
if(m==0)
return 0;
while(n>0)
{
if((n&1)!=0)
{
res=(res*m);
}
n=n>>1;
m=(m*m);
}
return res;
}
public static long modpwr(long m,long n)
{
long res=1;
m=m%mod;
if(m==0)
return 0;
while(n>0)
{
if((n&1)!=0)
{
res=(res*m)%mod;
}
n=n>>1;
m=(m*m)%mod;
}
return res;
}
public static class own
{
long a;
long b;
public own(long val,long index)
{
a=val;
b=index;
}
}
//Modular Airthmetic
public static void sort(int[] A)
{
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i)
{
int tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
public static void sort(char[] A)
{
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i)
{
char tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
public static void sort(long[] A)
{
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i)
{
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
//max & min
public static int max(int a,int b){return Math.max(a,b);}
public static int min(int a,int b){return Math.min(a,b);}
public static int max(int a,int b,int c){return Math.max(a,Math.max(b,c));}
public static int min(int a,int b,int c){return Math.min(a,Math.min(b,c));}
public static long max(long a,long b){return Math.max(a,b);}
public static long min(long a,long b){return Math.min(a,b);}
public static long max(long a,long b,long c){return Math.max(a,Math.max(b,c));}
public static long min(long a,long b,long c){return Math.min(a,Math.min(b,c));}
public static int maxinA(int a[]){int n=a.length;int mx=a[0];for(int i=1;i<n;i++){mx=max(mx,a[i]);}return mx;}
public static long maxinA(long a[]){int n=a.length;long mx=a[0];for(int i=1;i<n;i++){mx=max(mx,a[i]);}return mx;}
public static int mininA(int a[]){int n=a.length;int mn=a[0];for(int i=1;i<n;i++){mn=min(mn,a[i]);}return mn;}
public static long mininA(long a[]){int n=a.length;long mn=a[0];for(int i=1;i<n;i++){mn=min(mn,a[i]);}return mn;}
public static long suminA(int a[]){int n=a.length;long sum=0;for(int i=0;i<n;i++){sum+=a[i];}return sum;}
public static long suminA(long a[]){int n=a.length;long sum=0;for(int i=0;i<n;i++){sum+=a[i];}return sum;}
//end
public static int[] I(int n)throws IOException{int a[]=new int[n];for(int i=0;i<n;i++){a[i]=I();}return a;}
public static long[] IL(int n)throws IOException{long a[]=new long[n];for(int i=0;i<n;i++){a[i]=L();}return a;}
public static long[] prefix(int a[]){int n=a.length;long pre[]=new long[n];pre[0]=a[0];for(int i=1;i<n;i++){pre[i]=pre[i-1]+a[i];}return pre;}
public static long[] prefix(long a[]){int n=a.length;long pre[]=new long[n];pre[0]=a[0];for(int i=1;i<n;i++){pre[i]=pre[i-1]+a[i];}return pre;}
public static int I()throws IOException{return sc.I();}
public static long L()throws IOException{return sc.L();}
public static String S()throws IOException{return sc.S();}
public static double D()throws IOException{return sc.D();}
}
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 I(){ return Integer.parseInt(next());}
long L(){ return Long.parseLong(next());}
double D(){return Double.parseDouble(next());}
String S(){
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 8 | 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 | 08d5d67142be4bb3af42c56f93fd2563 | train_109.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>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.InputStreamReader;
import java.io.PrintStream;
import java.util.List;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) {
MyScanner myScanner = new MyScanner();
PrintStream out = System.out;
int t = myScanner.readInt();
while(t > 0) {
int n = myScanner.readInt();
int q = myScanner.readInt();
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = myScanner.readInt();
int start = 0,end = n-1;
String finalAns = null;
while(start <= end) {
int mid = (start+end)>>1;
Pair<Boolean,String>ans = check(a,mid,q);
if(ans.first){
end = mid-1;
finalAns = ans.second;
}
else
start = mid+1;
}
out.println(finalAns);
t--;
}
}
public static Pair<Boolean,String> check(int[] a,int x, int q) {
int n = a.length;
Pair<Boolean,String> ans = new Pair(Boolean.TRUE, "");
StringBuilder stringBuilder = new StringBuilder();
for(int i=0;i<x;i++) {
if(a[i] <= q) {
stringBuilder.append('1');
}
else {
stringBuilder.append('0');
}
}
for(int i=x;i<n;i++){
if(q == 0) {
ans.first = false;
stringBuilder.append('0');
}
else {
stringBuilder.append('1');
if(a[i] > q)
q--;
}
}
ans.second = stringBuilder.toString();
return ans;
}
public static class Pair<T,K> implements Comparable{
public T first;
public K second;
public Pair(T first, K second) {
this.first = first;
this.second = second;
}
// override the comparator if using one
@Override
public int compareTo(Object o) {
return 0;
}
}
public static class MyScanner {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer stringTokenizer = new StringTokenizer("");
public String next() {
while(!stringTokenizer.hasMoreTokens()) {
try {
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
}
catch (Exception exception) {
exception.printStackTrace();
}
}
return stringTokenizer.nextToken();
}
public int readInt() {
return Integer.parseInt(next());
}
public long readLong() {
return Long.parseLong(next());
}
public double readDouble() {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 8 | 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 | 801c0f6317cf76f5a8c5fdd1a88ac860 | train_109.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>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.InputStreamReader;
import java.io.PrintStream;
import java.util.List;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) {
MyScanner myScanner = new MyScanner();
PrintStream out = System.out;
int t = myScanner.readInt();
while(t > 0) {
int n = myScanner.readInt();
int q = myScanner.readInt();
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = myScanner.readInt();
int start = 0,end = n-1;
while(start <= end) {
int mid = (start+end)>>1;
Pair<Boolean,String>ans = check(a,mid,q);
if(ans.first){
end = mid-1;
}
else
start = mid+1;
}
Pair<Boolean,String>ans = check(a,end+1,q);
out.println(ans.second);
t--;
}
}
public static Pair<Boolean,String> check(int[] a,int x, int q) {
int n = a.length;
Pair<Boolean,String> ans = new Pair(Boolean.TRUE, "");
StringBuilder stringBuilder = new StringBuilder();
for(int i=0;i<x;i++) {
if(a[i] <= q) {
stringBuilder.append('1');
}
else {
stringBuilder.append('0');
}
}
for(int i=x;i<n;i++){
if(q == 0) {
ans.first = false;
stringBuilder.append('0');
}
else {
stringBuilder.append('1');
if(a[i] > q)
q--;
}
}
ans.second = stringBuilder.toString();
return ans;
}
public static class Pair<T,K> implements Comparable{
public T first;
public K second;
public Pair(T first, K second) {
this.first = first;
this.second = second;
}
// override the comparator if using one
@Override
public int compareTo(Object o) {
return 0;
}
}
public static class MyScanner {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer stringTokenizer = new StringTokenizer("");
public String next() {
while(!stringTokenizer.hasMoreTokens()) {
try {
stringTokenizer = new StringTokenizer(bufferedReader.readLine());
}
catch (Exception exception) {
exception.printStackTrace();
}
}
return stringTokenizer.nextToken();
}
public int readInt() {
return Integer.parseInt(next());
}
public long readLong() {
return Long.parseLong(next());
}
public double readDouble() {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 8 | 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 | 27f5d039adc41f69f181309b942f112b | train_109.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>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 CF808C {
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[] ans = new int[n];
int[] r = new int[n];
for(int i =0; i<n; i++){
r[i] = sc.nextInt();
}
int now = 0;
for(int i=n-1; i>=0; i--){
if(r[i]>now && now<q){
now++;
ans[i]=1;
}else if(r[i]<=now){
ans[i] =1;
}
}
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;i++){
sb.append(ans[i]);
}
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 8 | 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 | bf462d915063ae9540a3d0eb3ab76774 | train_109.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>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 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt(), q = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i]=sc.nextInt();
}
List<Integer> bad = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (a[i] > q) bad.add(i);
}
int low = 0, high = bad.size()-1;
int ans = n;
while (low <= high){
int mid = low + (high-low)/2;
boolean ok = true;
int curIq = q;
for (int i = bad.get(mid); i < n ; i++) {
if(curIq==0) {ok = false; break;}
if (a[i] > curIq) curIq--;
}
if (ok){
high = mid-1;
ans = bad.get(mid);
}
else low = mid+1;
}
for (int i = 0; i < ans; i++) {
if (a[i]<=q) pw.print(1);
else pw.print(0);
}
for (int i = ans; i <n ; i++) {
pw.print(1);
}
pw.println();
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
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 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 8 | 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 | ab20a6637c97d637ab91da81403b2d0f | train_109.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>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 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt(), q = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i]=sc.nextInt();
}
List<Integer> good = new ArrayList<>(), bad = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (a[i] > q) bad.add(i);
else good.add(i);
}
int low = 0, high = bad.size()-1;
int ans = n;
while (low <= high){
int mid = low + (high-low)/2;
boolean ok = true;
int curIq = q;
for (int i = bad.get(mid); i < n ; i++) {
if(curIq==0) {ok = false; break;}
if (a[i] > curIq) curIq--;
}
if (ok){
high = mid-1;
ans = bad.get(mid);
}
else low = mid+1;
}
for (int i = 0; i < ans; i++) {
if (a[i]<=q) pw.print(1);
else pw.print(0);
}
for (int i = ans; i <n ; i++) {
pw.print(1);
}
pw.println();
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
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 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 8 | 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 | b8b30ce04d8dfe8b2c64d288eaf43249 | train_109.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>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 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt(), q = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i]=sc.nextInt();
}
List<Integer> good = new ArrayList<>(), bad = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (a[i] > q) bad.add(i);
else good.add(i);
}
int low = 0, high = bad.size()-1;
int ans = n;
while (low <= high){
int mid = low + (high-low)/2;
boolean ok = true;
int curIq = q;
for (int i = bad.get(mid); i < n ; i++) {
if(curIq==0) ok = false;
if (a[i] > curIq) curIq--;
}
if (ok){
high = mid-1;
ans = bad.get(mid);
}
else low = mid+1;
}
for (int i = 0; i < ans; i++) {
if (a[i]<=q) pw.print(1);
else pw.print(0);
}
for (int i = ans; i <n ; i++) {
pw.print(1);
}
pw.println();
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
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 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 8 | 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 | effe0d84096cc2b7848d212e2ff283d3 | train_109.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>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.*;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, sc, out);
out.close();
}
static class Task {
public int get(int[] buf,int x){
int l=0;
int r=buf.length-1;
int idx=-1;
while(l<=r){
int mid=(l+r)/2;
if(buf[mid]<=x){
idx=mid;
l=mid+1;
}else{
r=mid-1;
}
}
return idx+1;
}
public void solve(int testNumber, InputReader sc, PrintWriter out) throws IOException {
int T=sc.nextInt();
while(T-->0){
int n=sc.nextInt();
int q=sc.nextInt();
int[] a=new int[n+1];
for(int i=1;i<=n;i++){
a[i]=sc.nextInt();
}
int l=0;
int r=n+1;
int idx=n;
while(l<=r){
int curq=q;
int mid=(l+r)/2;
boolean ok=true;
for(int i=mid+1;i<=n;i++){
if(a[i]>curq) {
curq--;
if (curq < 0) {
ok = false;
break;
}
}
}
if(ok){
idx=mid;
r=mid-1;
}else{
l=mid+1;
}
}
for(int i=1;i<=idx;i++){
if(a[i]<=q)
out.print("1");
else
out.print("0");
}
for(int i=idx+1;i<=n;i++){
out.print("1");
}
out.println();
}
}
}
static class BIT{
public int[] C; //注意本题在求和的过程中会爆int
public BIT(int n) {
C=new int[n+1];
}
public int lowBit(int x) {
return x&(-x);
}
public void add(int x,int y) {
for(int i=x;i<C.length;i+=lowBit(i)) {
C[i]+=y;
}
}
public int ask(int x) {
int res=0;
for(int i=x;i>0;i-=lowBit(i))
res+=C[i];
return res;
}
}
static class InputReader{
StreamTokenizer tokenizer;
public InputReader(InputStream stream){
tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));
tokenizer.ordinaryChars(33,126);
tokenizer.wordChars(33,126);
}
public String next() throws IOException {
tokenizer.nextToken();
return tokenizer.sval;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean hasNext() throws IOException {
int res=tokenizer.nextToken();
tokenizer.pushBack();
return res!=tokenizer.TT_EOF;
}
public double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(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 8 | 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 | c2b5940b24d5a04c178e70cc013740f1 | train_109.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>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 CF1
{
static FastReader sc=new FastReader();
// static long dp[][];
// static boolean v[][][];
// static int mod=998244353;;
// static int mod=1000000007;
static long oset[];
static int oset_p;
static long mod=1000000007;
// static int max;
// static int bit[];
//static long fact[];
//static HashMap<Long,Long> mp;
//static StringBuffer sb=new StringBuffer("");
//static HashMap<Integer,Integer> map;
//static List<Integer>list;
//static int m;
//static StringBuffer sb=new StringBuffer();
// static PriorityQueue<Integer>heap;
//static int dp[];
// static boolean cycle;
static PrintWriter out=new PrintWriter(System.out);
// static int msg[];
public static void main(String[] args)
{
// StringBuffer sb=new StringBuffer("");
int ttt=1;
ttt =i();
outer :while (ttt-- > 0)
{
int n=i();
long q=l();
long arr[]=inputL(n);
List<Integer>list=new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]>q)
list.add(i);
}
int l=0,r=list.size()-1;
int ans=n;
while(r>=l)
{
int mid=(l+r)/2;
int index=list.get(mid);
long tq=q;
boolean flag=true;
for(int i=index;i<n;i++)
{
if(tq<=0) {flag=false;
break;}
if(arr[i]>tq)
tq--;
}
if(flag)
{
ans=index;
r=mid-1;
}
else
l=mid+1;
}
StringBuffer sb=gsb();
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);
out.println(sb);
}
out.close();
}
static int findPar(int x,int parent[])
{
if(parent[x]==x)
return x;
return parent[x]=findPar(parent[x],parent);
}
static void union(int u,int v,int parent[],int rank[])
{
int x=findPar(u,parent);
int y=findPar(v,parent);
if(x==y)
return;
if(rank[x]>rank[y])
{
parent[y]=x;
}
else
if(rank[y]>rank[x])
parent[x]=y;
else
{
parent[y]=x;
rank[x]++;
}
}
static class Pair implements Comparable<Pair>
{
int x;
int y;
// int z;
Pair(int x,int y){
this.x=x;
this.y=y;
// this.z=z;
}
@Override
public int compareTo(Pair o) {
if(this.x>o.x)
return 1;
else if(this.x<o.x)
return -1;
else {
if(this.y>o.y)
return 1;
else if(this.y<o.y)
return -1;
else
return 0;
}
}
public int hashCode()
{
final int temp = 14;
int ans = 1;
ans =x*31+y*13;
return ans;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (this.getClass() != o.getClass()) {
return false;
}
Pair other = (Pair)o;
if (this.x != other.x || this.y!=other.y) {
return false;
}
return true;
}
//
/* FOR TREE MAP PAIR USE */
// public int compareTo(Pair o) {
// if (x > o.x) {
// return 1;
// }
// if (x < o.x) {
// return -1;
// }
// if (y > o.y) {
// return 1;
// }
// if (y < o.y) {
// return -1;
// }
// return 0;
// }
}
static ArrayList<Long> gLL()
{
return new ArrayList<>();
}
static ArrayList<Integer> gL()
{
return new ArrayList<>();
}
static StringBuffer gsb()
{
return new StringBuffer();
}
static int find(int A[],int a) {
if(A[a]==a)
return a;
return A[a]=find(A, A[a]);
}
//static int find(int A[],int a) {
// if(A[a]==a)
// return a;
// return find(A, A[a]);
//}
//FENWICK TREE
static class BIT{
int bit[];
BIT(int n){
bit=new int[n+1];
}
int lowbit(int i){
return i&(-i);
}
int query(int i){
int res=0;
while(i>0){
res+=bit[i];
i-=lowbit(i);
}
return res;
}
void update(int i,int val){
while(i<bit.length){
bit[i]+=val;
i+=lowbit(i);
}
}
}
//END
static long summation(long A[],int si,int ei)
{
long ans=0;
for(int i=si;i<=ei;i++)
ans+=A[i];
return ans;
}
static void add(long v,Map<Long,Long>mp) {
if(!mp.containsKey(v)) {
mp.put(v, (long)1);
}
else {
mp.put(v, mp.get(v)+(long)1);
}
}
static void remove(long v,Map<Long,Long>mp) {
if(mp.containsKey(v)) {
mp.put(v, mp.get(v)-(long)1);
if(mp.get(v)==0)
mp.remove(v);
}
}
public static int upper(List<Long>A,long k,int si,int ei)
{
int l=si;
int u=ei;
int ans=-1;
while(l<=u) {
int mid=(l+u)/2;
if(A.get(mid)<=k) {
ans=mid;
l=mid+1;
}
else {
u=mid-1;
}
}
return ans;
}
public static int upper(long A[],long k,int si,int ei)
{
int l=si;
int u=ei;
int ans=-1;
while(l<=u) {
int mid=(l+u)/2;
if(A[mid]<=k) {
ans=mid;
l=mid+1;
}
else {
u=mid-1;
}
}
return ans;
}
public static int lower(List<Long>A,long k,int si,int ei)
{
int l=si;
int u=ei;
int ans=-1;
while(l<=u) {
int mid=(l+u)/2;
if(A.get(mid)<=k) {
l=mid+1;
}
else {
ans=mid;
u=mid-1;
}
}
return ans;
}
public static int lower(long A[],long k,int si,int ei)
{
int l=si;
int u=ei;
int ans=-1;
while(l<=u) {
int mid=(l+u)/2;
if(A[mid]<=k) {
l=mid+1;
}
else {
ans=mid;
u=mid-1;
}
}
return ans;
}
static void pln(String s)
{
out.println(s);
}
static void p(String s)
{
out.print(s);
}
static int[] copy(int A[]) {
int B[]=new int[A.length];
for(int i=0;i<A.length;i++) {
B[i]=A[i];
}
return B;
}
static long[] copy(long A[]) {
long B[]=new long[A.length];
for(int i=0;i<A.length;i++) {
B[i]=A[i];
}
return B;
}
static int[] input(int n) {
int A[]=new int[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextInt();
}
return A;
}
static long[] inputL(int n) {
long A[]=new long[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextLong();
}
return A;
}
static String[] inputS(int n) {
String A[]=new String[n];
for(int i=0;i<n;i++) {
A[i]=sc.next();
}
return A;
}
static long sum(int A[]) {
long sum=0;
for(int i : A) {
sum+=i;
}
return sum;
}
static long sum(long A[]) {
long sum=0;
for(long i : A) {
sum+=i;
}
return sum;
}
static void reverse(long A[]) {
int n=A.length;
long B[]=new long[n];
for(int i=0;i<n;i++) {
B[i]=A[n-i-1];
}
for(int i=0;i<n;i++)
A[i]=B[i];
}
static void reverse(int A[]) {
int n=A.length;
int B[]=new int[n];
for(int i=0;i<n;i++) {
B[i]=A[n-i-1];
}
for(int i=0;i<n;i++)
A[i]=B[i];
}
static long[] inputL1(int n)
{
long arr[]=new long[n+1];
for(int i=1;i<=n;i++)
arr[i]=l();
return arr;
}
static int[] input1(int n)
{
int arr[]=new int[n+1];
for(int i=1;i<=n;i++)
arr[i]=i();
return arr;
}
static void input(int A[],int B[]) {
for(int i=0;i<A.length;i++) {
A[i]=sc.nextInt();
B[i]=sc.nextInt();
}
}
static long[][] inputL(int n,int m){
long A[][]=new long[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
A[i][j]=l();
}
}
return A;
}
static int[][] input(int n,int m){
int A[][]=new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
A[i][j]=i();
}
}
return A;
}
static char[][] charinput(int n,int m){
char A[][]=new char[n][m];
for(int i=0;i<n;i++) {
String s=s();
for(int j=0;j<m;j++) {
A[i][j]=s.charAt(j);
}
}
return A;
}
static int nextPowerOf2(int n)
{
if(n==0)
return 1;
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}
static int highestPowerof2(int x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
static long highestPowerof2(long x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
static int max(int A[]) {
int max=Integer.MIN_VALUE;
for(int i=0;i<A.length;i++) {
max=Math.max(max, A[i]);
}
return max;
}
static int min(int A[]) {
int min=Integer.MAX_VALUE;
for(int i=0;i<A.length;i++) {
min=Math.min(min, A[i]);
}
return min;
}
static long max(long A[]) {
long max=Long.MIN_VALUE;
for(int i=0;i<A.length;i++) {
max=Math.max(max, A[i]);
}
return max;
}
static long min(long A[]) {
long min=Long.MAX_VALUE;
for(int i=0;i<A.length;i++) {
min=Math.min(min, A[i]);
}
return min;
}
static long [] prefix(long A[]) {
long p[]=new long[A.length];
p[0]=A[0];
for(int i=1;i<A.length;i++)
p[i]=p[i-1]+A[i];
return p;
}
static long [] prefix(int A[]) {
long p[]=new long[A.length];
p[0]=A[0];
for(int i=1;i<A.length;i++)
p[i]=p[i-1]+A[i];
return p;
}
static long [] suffix(long A[]) {
long p[]=new long[A.length];
p[A.length-1]=A[A.length-1];
for(int i=A.length-2;i>=0;i--)
p[i]=p[i+1]+A[i];
return p;
}
static long [] suffix(int A[]) {
long p[]=new long[A.length];
p[A.length-1]=A[A.length-1];
for(int i=A.length-2;i>=0;i--)
p[i]=p[i+1]+A[i];
return p;
}
static void fill(int dp[]) {
Arrays.fill(dp, -1);
}
static void fill(int dp[][]) {
for(int i=0;i<dp.length;i++)
Arrays.fill(dp[i], -1);
}
static void fill(int dp[][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
Arrays.fill(dp[i][j],-1);
}
}
}
static void fill(int dp[][][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
for(int k=0;k<dp[0][0].length;k++) {
Arrays.fill(dp[i][j][k],-1);
}
}
}
}
static void fill(long dp[]) {
Arrays.fill(dp, -1);
}
static void fill(long dp[][]) {
for(int i=0;i<dp.length;i++)
Arrays.fill(dp[i], -1);
}
static void fill(long dp[][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
Arrays.fill(dp[i][j],-1);
}
}
}
static void fill(long dp[][][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
for(int k=0;k<dp[0][0].length;k++) {
Arrays.fill(dp[i][j][k],-1);
}
}
}
}
static int min(int a,int b) {
return Math.min(a, b);
}
static int min(int a,int b,int c) {
return Math.min(a, Math.min(b, c));
}
static int min(int a,int b,int c,int d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static int max(int a,int b) {
return Math.max(a, b);
}
static int max(int a,int b,int c) {
return Math.max(a, Math.max(b, c));
}
static int max(int a,int b,int c,int d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long min(long a,long b) {
return Math.min(a, b);
}
static long min(long a,long b,long c) {
return Math.min(a, Math.min(b, c));
}
static long min(long a,long b,long c,long d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static long max(long a,long b) {
return Math.max(a, b);
}
static long max(long a,long b,long c) {
return Math.max(a, Math.max(b, c));
}
static long max(long a,long b,long c,long d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long power(long x, long y, long p)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long power(long x, long y)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
static void dln(String s)
{
out.println(s);
}
static void d(String s)
{
out.print(s);
}
static void print(int A[]) {
for(int i : A) {
out.print(i+" ");
}
out.println();
}
static void print(long A[]) {
for(long i : A) {
System.out.print(i+" ");
}
System.out.println();
}
static long mod(long x) {
return ((x%mod + mod)%mod);
}
static String reverse(String s) {
StringBuffer p=new StringBuffer(s);
p.reverse();
return p.toString();
}
static int i() {
return sc.nextInt();
}
static String s() {
return sc.next();
}
static long l() {
return sc.nextLong();
}
static void sort(int[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
int tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static String sort(String s) {
Character ch[]=new Character[s.length()];
for(int i=0;i<s.length();i++) {
ch[i]=s.charAt(i);
}
Arrays.sort(ch);
StringBuffer st=new StringBuffer("");
for(int i=0;i<s.length();i++) {
st.append(ch[i]);
}
return st.toString();
}
static HashMap<Integer,Long> hash(int A[]){
HashMap<Integer,Long> map=new HashMap<Integer, Long>();
for(int i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+(long)1);
}
else {
map.put(i, (long)1);
}
}
return map;
}
static HashMap<Long,Long> hash(long A[]){
HashMap<Long,Long> map=new HashMap<Long, Long>();
for(long i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+(long)1);
}
else {
map.put(i, (long)1);
}
}
return map;
}
static TreeMap<Integer,Integer> tree(int A[]){
TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();
for(int i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static TreeMap<Long,Integer> tree(long A[]){
TreeMap<Long,Integer> map=new TreeMap<Long, Integer>();
for(long i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static boolean prime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static boolean prime(long n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static 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 8 | 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 | 6e1af7c19e1472d85c8469b25b7b3b44 | train_109.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>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.*;
public class Main {
static long cr[][]=new long[1001][1001];
//static double EPS = 1e-7;
static long mod=998244353;
static long val=0;static int cnt=0;
static boolean flag=true;
static int res=Integer.MAX_VALUE;
static int v=0;
public static void main(String[] args)
{
FScanner sc = new FScanner();
//Arrays.fill(prime, true);
//sieve();
//ncr();
StringBuilder sb = new StringBuilder();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int q=sc.nextInt();
int arr[]=new int[n];
ArrayList<Integer> A=new ArrayList<>();
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
if(arr[i]>q)
A.add(i);
}
int l=0,r=A.size()-1;
int ind=n;
while(l<=r)
{
int mid=(l+r)/2;
if(check(arr,A.get(mid),q))
{
ind=A.get(mid);
r=mid-1;
}
else
l=mid+1;
}
// System.out.println(ind+" ind");
for(int i=0;i<ind;i++)
{ if(arr[i]<=q)
sb.append("1");
else
sb.append("0");
}
for(int i=ind;i<n;i++)
{
sb.append("1");
}
sb.append("\n");
}
System.out.println(sb.toString());
}
public static String dfs(ArrayList<pair> arr,long ind,String s)
{ ind--;
// System.out.println(ind+" #");
if(ind<s.length())
return ""+s.charAt((int) ind);
int n=arr.size();
for(int i=n-1;i>=0;i--)
{
if(arr.get(i).c<=ind && arr.get(i).d>=ind)
{
return dfs(arr,arr.get(i).a+ (ind-arr.get(i).c) ,s);
}
}
return "";
}
public static boolean check(int arr[],int mid,int q)
{
int val=0;
for(int i=mid;i<arr.length;i++)
{
if(arr[i]>q)
q--;
val++;
if(q==0)
break;
}
// System.out.println(val+" "+mid);
if(val<arr.length-mid)
return false;
else
return true;
}
static int digits (long x, long y) {
BigInteger bi = BigInteger.valueOf(x).multiply(BigInteger.valueOf(y));
return bi.toString().length();
}
public static long powerLL(long x, long n)
{
long result = 1;
while (n > 0)
{
if (n % 2 == 1)
{
result = result * x % mod;
}
n = n / 2;
x = x * x % mod;
}
return result;
}
public static long gcd(long a,long b)
{
return b==0 ? a:gcd(b,a%b);
}
/* public static void sieve()
{ prime[0]=prime[1]=false;
int n=1000000;
for(int p = 2; p*p <=n; p++)
{
if(prime[p] == true)
{
for(int i = p*p; i <= n; i += p)
prime[i] = false;
}
}
*/
public static void ncr()
{
cr[0][0]=1;
for(int i=1;i<=1000;i++)
{
cr[i][0]=1;
for(int j=1;j<i;j++)
{
cr[i][j]=(cr[i-1][j-1]+cr[i-1][j])%mod;
}
cr[i][i]=1;
}
}
}
class pair
{
long a;long b;long c;long d;
public pair(long a,long b,long c,long d)
{
this.a=a;
this.b=b;
this.c=c;
this.d=d;
}
}
class FScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer sb = new StringTokenizer("");
String next(){
while(!sb.hasMoreTokens()){
try{
sb = new StringTokenizer(br.readLine());
} catch(IOException e){ }
}
return sb.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
float nextFloat(){
return Float.parseFloat(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
}
| Java | ["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 8 | 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 | 0b2dd47fafad23aa9193523f05ecd9c1 | train_109.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>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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
public class C {
static final long mod = (long) 1e9 + 7l;
static char chr[];
static Map<Integer, Integer> map = new HashMap<>();
private static void solve(int t){
int n =fs.nextInt();
int q = fs.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = fs.nextInt();
}
int check = q;
List<Integer> ls = new ArrayList<>();
for (int i = 0; i < n; i++) {
if(arr[i]<=q)ls.add(i);
if(arr[i]>check)check--;
}
if(check>=0){
for (int i = 0; i < n; i++) out.print(1);
out.println();
return;
}
int i, rq =0;
for (i = n-1; i >=0; i--) {
if(arr[i]>rq && rq<q){
rq++;
}
if(rq==q)break;
}
for (int j = 0, k=0; j < i; j++) {
if(k<ls.size() && ls.get(k)==j){
out.print(1);
k++;
}else out.print(0);
}
for (int j = i; j < n; j++) {
out.print(1);
}
out.println();
}
private static int[] sortByCollections(int[] arr) {
ArrayList<Integer> ls = new ArrayList<>(arr.length);
for (int i = 0; i < arr.length; i++) {
ls.add(arr[i]);
}
Collections.sort(ls);
for (int i = 0; i < arr.length; i++) {
arr[i] = ls.get(i);
}
return arr;
}
public static void main(String[] args) {
fs = new FastScanner();
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int t = fs.nextInt();
for (int i = 1; i <= t; i++) solve(t);
out.close();
// System.err.println( System.currentTimeMillis() - s + "ms" );
}
static boolean DEBUG = true;
static PrintWriter out;
static FastScanner fs;
static void trace(Object... o) {
if (!DEBUG) return;
System.err.println(Arrays.deepToString(o));
}
static void pl(Object o) {
out.println(o);
}
static void p(Object o) {
out.print(o);
}
static long gcd(long a, long b) {
return (b == 0) ? a : gcd(b, a % b);
}
static int gcd(int a, int b) {
return (b == 0) ? a : gcd(b, a % b);
}
static void sieveOfEratosthenes(int n, int factors[]) {
factors[1] = 1;
for (int p = 2; p * p <= n; p++) {
if (factors[p] == 0) {
factors[p] = p;
for (int i = p * p; i <= n; i += p)
factors[i] = p;
}
}
}
static long mul(long a, long b) {
return a * b % mod;
}
static long fact(int x) {
long ans = 1;
for (int i = 2; i <= x; i++) ans = mul(ans, i);
return ans;
}
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 modInv(long x) {
return fastPow(x, mod - 2);
}
static long nCk(int n, int k) {
return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n - k))));
}
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();
}
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());
}
}
static class _Scanner {
InputStream is;
_Scanner(InputStream is) {
this.is = is;
}
byte[] bb = new byte[1 << 15];
int k, l;
byte getc() throws IOException {
if (k >= l) {
k = 0;
l = is.read(bb);
if (l < 0) return -1;
}
return bb[k++];
}
byte skip() throws IOException {
byte b;
while ((b = getc()) <= 32)
;
return b;
}
int nextInt() throws IOException {
int n = 0;
for (byte b = skip(); b > 32; b = getc())
n = n * 10 + b - '0';
return 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 8 | 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 | f06e42f1968a2f66733c9bf894928d8e | train_109.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>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 8 | 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 | 9163d35f2cbdfbb5f8a829a305d491b5 | train_109.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>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) {
LinkedList<Integer> s = new LinkedList<>();
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++) {
int fir = -1;
if(!s.isEmpty()){
fir = s.getFirst();
}
if (i==fir) {
ans[i] = '1';
s.pollFirst();
} 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 8 | 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 | cae6937c8c87f50b7d73d4a6dd48e9b3 | train_109.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>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.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class C {
static ArrayList<Integer>adj[];
static int[]vis;
static ArrayList<String>[]arr;
static HashMap<String, Integer>dp;
static HashSet<String>dat;
static int c,n;
public static void main(String[]args) throws IOException {
// Scanner sc=new Scanner("files.in");
Scanner sc=new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt(),q=sc.nextInt();
int[]a=new int[n],ans=new int[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
}
// if(n==1) {out.println("1");continue;}
Arrays.fill(ans, 1);
int[]nums=new int[n];
nums[n-1]=1;
int j=-1;
for(int i=n-2;i>=0;i--) {
nums[i]=nums[i+1];
if(a[i]>nums[i+1]) {
nums[i]++;
if(nums[i]>q) {
j=i;break;
}
// ded++;
}
}
for(int i=j;i>=0;i--) {
if(a[i]>q)ans[i]=0;
}
for(int x:ans)out.print(x);
out.println();
}
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(String s) throws IOException{
br=new BufferedReader(new FileReader(new File(s)));
}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public boolean hasNext() {return st.hasMoreTokens();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public double nextDouble() throws IOException {return Double.parseDouble(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
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 8 | 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 | 64022a06847398f27ac826a94bc49e3b | train_109.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>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.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();
int q=fs.nextInt();
int arr[]=new int[n];
for( int i=0;i<n;i++ ) {
arr[i]=fs.nextInt();
}
int q1=0;
char crr[]=new char[n];
for( int i=n-1 ; i>=0; i-- ) {
if( arr[i]<=q1 ) {
crr[i]='1';
}else {
if( q1<q ) {
crr[i]='1';
q1++;
}else {
crr[i]='0';
}
}
}
for( int i=0;i<n;i++ ) {
System.out.print(crr[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 | ["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 8 | 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 | 816f235ff6d643495d0dd8c3c2233a52 | train_109.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>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.lang.reflect.Parameter;
import java.math.BigInteger;
import java.util.*;
public class codeMaster {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int tc = sc.nextInt();
while(tc-->0){
int n = sc.nextInt(), q = sc.nextInt();
int[] arr = sc.nextIntArray(n);
int[] taken = new int[n];
int cnt = 0;
for(int i = n - 1; i>=0; i--){
if(arr[i] > cnt){
if(cnt == q)continue;
else{
cnt++;
taken[i] = 1;
}
}else taken[i] = 1;
}
for(int x: taken)pw.print(x);
pw.println();
}
pw.flush();
}
static class SegmentTree{
long[] tree;
int N;
public SegmentTree(long[] arr){
N = arr.length;
tree = new long[2*N - 1];
build(tree, arr);
}
public void build(long[] tree, long[] arr){
for(int i = N-1, j = 0; i<tree.length; i++, j++)tree[i] = arr[j];
for(int i = tree.length - 1, j = i - 1, k = N-2; k>=0; i -= 2, j-= 2, k--){
tree[k] = tree[i] + tree[j];
}
}
public void update(int idx, int val){
tree[idx + N - 2] = val;
boolean f = true;
int i = idx + N - 2;
int j = i - 1;
if(i % 2 != 0){
i++;
j++;
}
for(int k = (tree.length - N - 1) - ((tree.length - 1 - i)/2); k>=0; ){
tree[k] = tree[i] + tree[j];
f = !f;
i = k;
j = k - 1;
if(k % 2 != 0){
i++;
j++;
}
k = (tree.length - N - 1) - ((tree.length - 1 - i)/2);
}
}
}
public static boolean isSorted(int[] arr){
boolean f = true;
for(int i = 1; i<arr.length; i++){
if(arr[i] < arr[i - 1]){
f = false;
break;
}
}
return f;
}
public static int binary_Search(long key, long[] arr){
int low = 0;
int high = arr.length;
int mid = (low + high) / 2;
while(low <= high){
mid = low + (high - low) / 2;
if(arr[mid] == key)break;
else if(arr[mid] > key) high = mid - 1;
else low = mid + 1;
}
return mid;
}
public static int differences(int n, int test){
int changes = 0;
while(test > 0){
if(test % 10 != n % 10)changes++;
test/=10;
n/=10;
}
return changes;
}
static int maxSubArraySum(int a[], int size)
{
int max_so_far = Integer.MIN_VALUE,
max_ending_here = 0,start = 0,
end = 0, s = 0;
for (int i = 0; i < size; i++)
{
max_ending_here += a[i];
if (max_so_far < max_ending_here)
{
max_so_far = max_ending_here;
start = s;
end = i;
}
if (max_ending_here < 0)
{
max_ending_here = 0;
s = i + 1;
}
}
return start;
}
static int maxSubArraySum2(int a[], int size)
{
int max_so_far = Integer.MIN_VALUE,
max_ending_here = 0,start = 0,
end = 0, s = 0;
for (int i = 0; i < size; i++)
{
max_ending_here += a[i];
if (max_so_far < max_ending_here)
{
max_so_far = max_ending_here;
start = s;
end = i;
}
if (max_ending_here < 0)
{
max_ending_here = 0;
s = i + 1;
}
}
return end;
}
public static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static class Pair implements Comparable<Pair>{
int x;
int y;
public Pair(int x, int y){
this.x = x;
this.y = y;
}
public int compareTo(Pair x){
if(this.x == x.x) return this.y - x.y;
else return this.x - x.x;
}
public String toString(){
return "("+this.x + ", " + this.y + ")";
}
}
public static class Tuple implements Comparable<Tuple>{
int x;
int y;
int z;
public Tuple(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
public int compareTo(Tuple x){
if(this.x == x.x) return x.y - this.y;
else return this.x - x.x;
}
public String toString(){
return "("+this.x + ", " + this.y + "," + this.z + ")";
}
}
public static boolean isSubsequence(char[] arr, String s){
boolean ans = false;
for(int i = 0, j = 0; i<arr.length; i++){
if(arr[i] == s.charAt(j)){
j++;
}
if(j == s.length()){
ans = true;
break;
}
}
return ans;
}
public static void sortIdx(long[]a,long[]idx) {
mergesortidx(a, idx, 0, a.length-1);
}
static void mergesortidx(long[] arr,long[]idx,int b,int e) {
if(b<e) {
int m=b+(e-b)/2;
mergesortidx(arr,idx,b,m);
mergesortidx(arr,idx,m+1,e);
mergeidx(arr,idx,b,m,e);
}
return;
}
static void mergeidx(long[] arr,long[]idx,int b,int m,int e) {
int len1=m-b+1,len2=e-m;
long[] l=new long[len1];
long[] lidx=new long[len1];
long[] r=new long[len2];
long[] ridx=new long[len2];
for(int i=0;i<len1;i++) {
l[i]=arr[b+i];
lidx[i]=idx[b+i];
}
for(int i=0;i<len2;i++) {
r[i]=arr[m+1+i];
ridx[i]=idx[m+1+i];
}
int i=0,j=0,k=b;
while(i<len1 && j<len2) {
if(l[i]<=r[j]) {
arr[k++]=l[i++];
idx[k-1]=lidx[i-1];
}
else {
arr[k++]=r[j++];
idx[k-1]=ridx[j-1];
}
}
while(i<len1) {
idx[k]=lidx[i];
arr[k++]=l[i++];
}
while(j<len2) {
idx[k]=ridx[j];
arr[k++]=r[j++];
}
return;
}
static 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();
}
}
} | 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 8 | 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 | 4418d8312dfe9d98f323d98b13d95f0d | train_109.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>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.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.security.KeyStore.Entry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.*;
public class test2 {
// static boolean[] f = new boolean[(int) 10e6];
static int ans = 0;
static ArrayList<Integer> y=new ArrayList<Integer>();
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter sp = new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int iq=sc.nextInt();
Integer[] x=sc.nextIntegerArray(n);
int l=0;int r=n-1;
int st=0;
while(l<=r) {
int m=(l+r)/2;
int c=0;
boolean f=false;
int a=iq;
for(int i=m;i<n;i++) {
if(a==0) {
f=true;
break;
}
if(x[i]>a)a--;
}
if(f) {
l=m+1;
}
else {
st=m;
r=m-1;
}
}
for(int i=0;i<st;i++)sp.print((x[i]<=iq)?1:0);
for(int i=st;i<n;i++)sp.print(1);
sp.println();
}
sp.flush();
}
/*
* 11100
* 01110
* 00011
* 11011
* 7
* 101
* 111
* 100
* 011
*/
public static void fill(ArrayList<Integer>[] x,int st,boolean[] f) {
if(f[st])return;
else {
f[st]=true;
y.add(st);
for(int i=0;i<x[st].size();i++) {
fill(x, x[st].get(i), f);
}
}
}
public static void count(ArrayList<Integer>[] x, int i, int m, int cat, boolean[] f, boolean[] r, int st) {
// System.out.println(r[i]+" "+ans);
if (r[i])
return;
else
r[i] = true;
if (cat > m)
return;
if (x[i].size() == 1 && i != st) {
if (f[i - 1]) {
if (cat + 1 <= m) {
// System.out.println("ll");
ans++;
return;
} else
return;
} else {
if (cat <= m) {
ans++;
return;
}
return;
}
} else {
if (f[i - 1]) {
for (int j = 0; j < x[i].size(); j++) {
int n = x[i].get(j);
count(x, n, m, cat + 1, f, r, st);
}
} else {
for (int j = 0; j < x[i].size(); j++) {
int n = x[i].get(j);
count(x, n, m, 0, f, r, st);
}
}
}
}
public static int[] blwh(ArrayList<Integer>[] x, int i, char[] q) {
int[] y = new int[2];
if (x[i].size() == 0) {
//System.out.println(x[i]+" kl");
if (q[i] == 'B')
y[0]++;
else
y[1]++;
return y;
} else {
if (q[i] == 'B')
y[0]++;
else
y[1]++;
for (int j = 0; j < x[i].size(); j++) {
//System.out.println("LL " + x[i].get(j));
int[] t = blwh(x, x[i].get(j), q);
y[0] += t[0];
y[1] += t[1];
}
if (y[0] == y[1])
ans++;
return y;
}
}
//
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
// 1 1 1 1 1 2 2
class Pair implements Comparable {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Object o) {
Pair z = (Pair) o;
if (this.x >= z.x && this.y >= z.y)
return 1;
return -1;
}
public boolean contains(Pair q) {
if (q.x == x || q.x == y || q.y == x || q.y == y)
return true;
return false;
}
public int getx() {
return x;
}
public int gety() {
return y;
}
public String toString() {
return x + " " + y;
}
}
| Java | ["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 8 | 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 | 01fcc20e2c8d3a9fda2069c023b343d3 | train_109.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>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.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.security.KeyStore.Entry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.*;
public class test2 {
// static boolean[] f = new boolean[(int) 10e6];
static int ans = 0;
static ArrayList<Integer> y=new ArrayList<Integer>();
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter sp = new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int iq=sc.nextInt();
Integer[] x=sc.nextIntegerArray(n);
int l=0;int r=n-1;
while(l<=r) {
int m=(l+r)/2;
int a=iq;
boolean f=true;
for(int i=m;i<n;i++) {
if(a==0) {
f=false;
break;
}
else {
if(x[i]>a)a--;
}
}
if(!f) {
l=m+1;
}
else r=m-1;
}
for(int i=0;i<l;i++)sp.print((x[i]<=iq)?1:0+"");
for(int i=l;i<n;i++)sp.print(1+"");
sp.println();
}
sp.flush();
}
/*
* 11100
* 01110
* 00011
* 11011
* 7
* 101
* 111
* 100
* 011
*/
public static void fill(ArrayList<Integer>[] x,int st,boolean[] f) {
if(f[st])return;
else {
f[st]=true;
y.add(st);
for(int i=0;i<x[st].size();i++) {
fill(x, x[st].get(i), f);
}
}
}
public static void count(ArrayList<Integer>[] x, int i, int m, int cat, boolean[] f, boolean[] r, int st) {
// System.out.println(r[i]+" "+ans);
if (r[i])
return;
else
r[i] = true;
if (cat > m)
return;
if (x[i].size() == 1 && i != st) {
if (f[i - 1]) {
if (cat + 1 <= m) {
// System.out.println("ll");
ans++;
return;
} else
return;
} else {
if (cat <= m) {
ans++;
return;
}
return;
}
} else {
if (f[i - 1]) {
for (int j = 0; j < x[i].size(); j++) {
int n = x[i].get(j);
count(x, n, m, cat + 1, f, r, st);
}
} else {
for (int j = 0; j < x[i].size(); j++) {
int n = x[i].get(j);
count(x, n, m, 0, f, r, st);
}
}
}
}
public static int[] blwh(ArrayList<Integer>[] x, int i, char[] q) {
int[] y = new int[2];
if (x[i].size() == 0) {
//System.out.println(x[i]+" kl");
if (q[i] == 'B')
y[0]++;
else
y[1]++;
return y;
} else {
if (q[i] == 'B')
y[0]++;
else
y[1]++;
for (int j = 0; j < x[i].size(); j++) {
//System.out.println("LL " + x[i].get(j));
int[] t = blwh(x, x[i].get(j), q);
y[0] += t[0];
y[1] += t[1];
}
if (y[0] == y[1])
ans++;
return y;
}
}
//
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
// 1 1 1 1 1 2 2
class Pair implements Comparable {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Object o) {
Pair z = (Pair) o;
if (this.x >= z.x && this.y >= z.y)
return 1;
return -1;
}
public boolean contains(Pair q) {
if (q.x == x || q.x == y || q.y == x || q.y == y)
return true;
return false;
}
public int getx() {
return x;
}
public int gety() {
return y;
}
public String toString() {
return x + " " + y;
}
}
| Java | ["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 8 | 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 | a7091a54b8c48482f8e4607c124c57ed | train_109.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>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.ArrayList;
import java.util.Scanner;
public class cfContest1708 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
k:
while (t-- > 0) {
int n = scan.nextInt();
int q = scan.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scan.nextInt();
}
int curr = 0;
int[] res = new int[n];
for (int i = n - 1; i >= 0; i--) {
if (a[i] <= curr) {
res[i] = 1;
} else if (curr < q) {
++curr;
res[i] = 1;
}
}
for (int i = 0; i < n; i++) {
System.out.print(res[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 8 | 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 | 4d0c1b0c0b79640a63adb4da8dacb9e3 | train_109.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>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 static java.lang.Math.*;
public class MainC {
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 boolean hasNext() {
try {
String string = reader.readLine();
if (string == null) {
return false;
}
tokenizer = new StringTokenizer(string);
return tokenizer.hasMoreTokens();
} catch (IOException e) {
return false;
}
}
}
static InputReader in = new InputReader(System.in);
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static void ini() {
}
static String yes = "YES";
static String no = "NO";
static int ipInf = Integer.MAX_VALUE-5;
static int inInf = Integer.MIN_VALUE+5;
static long lpInf = Long.MAX_VALUE - 5;
static long lnInf = Long.MIN_VALUE + 5;
public static void main(String[] args) {
int t = in.nextInt();
ini();
while (t -- > 0) {
solve();
}
out.close();
}
static void solve() {
int n = in.nextInt();
int q = in.nextInt();
int[] arr = new int[n+1];
for (int i = 1; i <= n; i++) {
arr[i] = in.nextInt();
}
arr[0] = -1;
boolean[] test = new boolean[n+1];
int l = 1, r = n, mid, now_q;
boolean flag;
while (l <= r) {
mid = (l + r) >> 1;
flag = true;
for (int i = 1; i < n; i++) {
test[i] = false;
}
now_q = q;
for (int i = 1; i < mid; i++) {
if (arr[i] < now_q) test[i] = true;
}
for (int i = mid; i <= n; i++) {
test[i] = true;
if (now_q == 0) flag = false;
if (arr[i] > now_q) now_q --;
}
if (now_q < 0) flag = false;
if (flag) r = mid - 1;
else l = mid + 1;
}
now_q = q;
for (int i = 1; i < n; i++) {
test[i] = false;
}
for (int i = 1; i < r+1; i++) {
if (arr[i] <= now_q) test[i] = true;
}
for (int i = r+1; i <= n; i++) {
test[i] = true;
}
for (int i = 1; i <= n; i++) {
out.print(test[i] ? 1 : 0);
}
out.println();
}
static void printArr (int[] arr) {
int n = arr.length;
if (n == 0) return;
for (int i = 0; i < n-1; i++) {
out.print(arr[i] + " ");
}
out.println(arr[n-1]);
}
static void printArr (long[] arr) {
int n = arr.length;
if (n == 0) return;
for (int i = 0; i < n-1; i++) {
out.print(arr[i] + " ");
}
out.println(arr[n-1]);
}
static long _gcd (long a, long b) {
long temp;
while (true) {
temp = a % b;
if (temp == 0) return b;
a = b;
b = temp;
}
}
}
| 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 8 | 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 | 87883e922872b353df2f9bec849e1169 | train_109.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>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.*;
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 q= in.nextInt();
int[]arr=input(n);
int[]ans=new int[n];
int now=0;
for(int i=n-1;i>=0;i--) {
if(arr[i]<=now) {
ans[i]=1;
}
else {
if(now==q) {
continue;
}
ans[i]=1;
now++;
}
}
for(int x:ans)print(x);
println("");
}
}
static int dfs(int q,int i,int[]arr,int []ans,int total,int[]dp) {
// println(q+" "+i+" "+total);
if(q==0||i==arr.length) {
if(i<arr.length&&q<0) {
ans[i]=0;
dp[i]=total;
}
return total;
}
// if(dp[i]!=-1) {
// return dp[i];
// }
if(arr[i]<=q) {
ans[i]=1;
return dp[i]=dfs(q,i+1,arr,ans,total+1,dp);
}
else {
int x1=dfs(q,i+1,arr,ans,total,dp);
int x2=dfs(q-1,i+1,arr,ans,total+1,dp);
if(x1<x2) {
ans[i]=1;
}
return dp[i]=Math.max(x1, x2);
}
}
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 | ["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 8 | 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 | 2b1bab80b1d9343395b7eb54356f9ede | train_109.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>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 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 q =sc.nextInt();
int []a = sc.nextArrint(n);
int x = 0;
int[]res = new int[n];
for (int i = n-1; i >= 0; i--) {
if(a[i]>x) {
if(x==q) {
continue;
}else {
x++;
res[i] = 1;
}
}else {
res[i] = 1;
}
}
for(int e:res) {
pw.print(e);
}
pw.println();
}
pw.close();
}
static boolean isSquare(int x) {
int y = (int)Math.round(Math.sqrt(x));
return y*y==x;
}
public static void sortIdx(long[] a, long[] idx) {
mergesortidx(a, idx, 0, a.length - 1);
}
static void mergesortidx(long[] arr, long[] idx, int b, int e) {
if (b < e) {
int m = b + (e - b) / 2;
mergesortidx(arr, idx, b, m);
mergesortidx(arr, idx, m + 1, e);
mergeidx(arr, idx, b, m, e);
}
return;
}
static void mergeidx(long[] arr, long[] idx, int b, int m, int e) {
int len1 = m - b + 1, len2 = e - m;
long[] l = new long[len1];
long[] lidx = new long[len1];
long[] r = new long[len2];
long[] ridx = new long[len2];
for (int i = 0; i < len1; i++) {
l[i] = arr[b + i];
lidx[i] = idx[b + i];
}
for (int i = 0; i < len2; i++) {
r[i] = arr[m + 1 + i];
ridx[i] = idx[m + 1 + i];
}
int i = 0, j = 0, k = b;
while (i < len1 && j < len2) {
if (l[i] <= r[j]) {
arr[k++] = l[i++];
idx[k - 1] = lidx[i - 1];
} else {
arr[k++] = r[j++];
idx[k - 1] = ridx[j - 1];
}
}
while (i < len1) {
idx[k] = lidx[i];
arr[k++] = l[i++];
}
while (j < len2) {
idx[k] = ridx[j];
arr[k++] = r[j++];
}
return;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public int[] nextArrint(int size) throws IOException {
int[] a = new int[size];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
return a;
}
public long[] nextArrlong(int size) throws IOException {
long[] a = new long[size];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextLong();
}
return a;
}
public int[][] next2dArrint(int rows, int columns) throws IOException {
int[][] a = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
a[i][j] = sc.nextInt();
}
}
return a;
}
public long[][] next2dArrlong(int rows, int columns) throws IOException {
long[][] a = new long[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
a[i][j] = sc.nextLong();
}
}
return a;
}
}
}
| 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 8 | 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 | 3d848e3e2ff30167a7935f489093ac19 | train_109.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>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.StringTokenizer;
public class Main {
static Main2 admin = new Main2();
public static void main(String[] args) {
admin.start();
}
}
class Main2 {
//---------------------------------INPUT READER-----------------------------------------//
public BufferedReader br;
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try { st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace(); }
}
return st.nextToken();
}
int ni() { return Integer.parseInt(next()); }
long nl() { return Long.parseLong(next()); }
double nd() { return Double.parseDouble(next()); }
String ns() { return next(); }
int[] na(long n) {int[]ret=new int[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
long[] nal(long n) {long[]ret=new long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
Integer[] nA(long n) {Integer[]ret=new Integer[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
Long[] nAl(long n) {Long[]ret=new Long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
//--------------------------------------PRINTER------------------------------------------//
PrintWriter w;
void p(int i) {w.println(i);} void p(long l) {w.println(l);}
void p(double d) {w.println(d);} void p(String s) { w.println(s);}
void pr(int i) {w.print(i);} void pr(long l) {w.print(l);}
void pr(double d) {w.print(d);} void pr(String s) { w.print(s);}
void pl() {w.println();}
//--------------------------------------VARIABLES-----------------------------------------//
long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE;
int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE;
long mod = 1000000007;
{
w = new PrintWriter(System.out);
br = new BufferedReader(new InputStreamReader(System.in));
try {if(new File(System.getProperty("user.dir")).getName().equals("LOCAL")) {
w = new PrintWriter(new OutputStreamWriter(new FileOutputStream("output.txt")));
br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));}
} catch (Exception ignore) { }
}
//----------------------START---------------------//
void start() {
int t = ni(); while(t-- > 0)
solve();
w.close();
}
int[] check(long[] arr, long need, long q) {
if(need == 3) {
int e = 101;
}
int n = arr.length;
long rem = n-need;
int[] ans = new int[n];
int ct = 0;
for(int i = 0; i < n; i++) {
if(arr[i] > q && rem > 0) {
rem--;
ans[i] = 0;
continue;
}
ans[i] = 1;
ct++;
if(arr[i] > q) q--;
if(q <= 0) break;
}
if(ct < need) return new int[]{-1};
return ans;
}
void solve() {
int n = ni();
long q = nl();
long[] arr = nal(n);
int l = 0; // true;
int r = n+1; // false;
int[] ans = {-1};
while(l < r-1) {
int mid = (l+r)/2;
int[] ret = check(arr, mid, q);
if(ret[0] == -1) r = mid;
else {
ans = ret;
l = mid;
}
}
for(int i: ans) pr(i);
pl();
}
} | 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 8 | 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 | 48277ae312565764ff2de04bcc16afa7 | train_109.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>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.*;
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 q = sc.nextInt();
int[] arr = new int[n];
for (int j = 0; j < n; j++) {
arr[j] = sc.nextInt();
}
int[] ans = binSearch(arr, q);
for (int k : ans) System.out.print(k);
System.out.println();
}
}
public static int[] binSearch(int[] arr, int q) {
int n = arr.length;
int low = 0, high = n - 1;
int ans = Integer.MAX_VALUE;
while (low <= high) {
int mid = (low + high) / 2;
int numCanDo = numCanDo(arr, q, mid);
if (numCanDo > 0) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
// System.out.println("here " + ans);
int[] vals = new int[n];
if (ans >= 0 && ans <= n) {
for (int i = 0; i < ans; i++) {
if (arr[i] <= q) vals[i] = 1;
else vals[i] = 0;
}
for (int i = ans; i < n; i++) {
vals[i] = 1;
}
}
return vals;
}
public static int numCanDo(int[] arr, int q, int x) {
int total = 0;
int ans = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] <= q) ans++;
}
for (int i = x; i < arr.length; i++) {
if (arr[i] > q) {
q--;
}
ans++;
}
return q >= 0 ? ans : -1;
}
}
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 | ["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 8 | 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 | 61ef73c8009aa7e8017bf6162a0e7ed8 | train_109.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>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 _1708C {
private static final int START_TEST_CASE = 1;
public static void solveCase(FastIO io, int testCase) {
int n = io.nextInt();
int q = io.nextInt();
int[] a = io.nextIntArray(n);
int iq = 0;
StringBuilder ans = new StringBuilder();
for (int i = n-1; i >= 0; i--) {
if (a[i] > iq) {
if (iq < q) {
iq++;
ans.append("1");
} else {
ans.append("0");
}
} else {
ans.append("1");
}
}
io.println(ans.reverse().toString());
}
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 | ["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 8 | 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 | e541e3dc55cb4d2243f72fc0df6b0fb1 | train_109.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>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 faltu;
import java.util.*;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
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;
}
private static int CntOfFactor(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.size();
}
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) {
computeFact(n, 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 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 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(long a, long b){return (gcd(a, b) == 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(u==v)return;
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[]) {
long[]path=new long[n];
dist=new int[n];
Arrays.fill(dist,Integer.MAX_VALUE);
dist[u]=0;
path[0]=1;
PriorityQueue<node>pq=new PriorityQueue<node>(new node());
pq.add(new node(u,0));
while(!pq.isEmpty()) {
node v=pq.poll();
if(dist[v.getV()]<v.getW())continue;
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()]));
path[it.getV()]=path[v.getV()];
}
else if(dist[it.getV()]==it.getW()+dist[v.getV()]) {
path[it.getV()]+=path[v.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();
}
out.close();
// catch(Exception e) {return;}
}
private static void solver() {
int n=s.nextInt();
long q=s.nextLong();
long[]a=new long[n];
ArrayList<Integer>bad=new ArrayList<Integer>();
for(int i=0;i<n;i++) {
a[i]=s.nextLong();
if(a[i]>q)bad.add(i);
}
int low=0,high=bad.size()-1,ansidx=n;
while(low<=high) {
int mid=(low+high)/2;
if(check(mid,q,a,bad)){
ansidx=bad.get(mid);
high=mid-1;
}
else low=mid+1;
}
// out.println(ansidx);
for(int i=0;i<ansidx;i++) {
if(a[i]>q)out.print("0");
else out.print("1");
}
for(int i=ansidx;i<n;i++) {
out.print("1");
}
out.println();
}
private static boolean check(int mid, long q, long[] a, ArrayList<Integer> bad) {
int n=a.length;
for(int i=bad.get(mid);i<n;i++) {
if(q<=0)return false;
if(a[i]>q) {
q--;
}
}
return true;
}
private static long sqroot(long x) {long left = 0, right = 2000000123;while (right > left) {long mid = (left + right) / 2;if (mid * mid > x) right = mid;else left = mid + 1;}return left - 1;}
/* *********************BITS && TOOLS &&DEBUG STARTS***********************************************/
static boolean issafe(int i, int j, int r,int c,boolean[][]vis){
if (i < 0 || j < 0 || i >= r || j >= c||vis[i][j]==true)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 pl1d(long[] x) {for(int i=0;i<x.length;i++)out.print(x[i]+" ");out.println();}
static void pb1d(boolean[] x) {for(int i=0;i<x.length;i++)out.print(x[i]+" ");out.println();}
static void pi1d(int[] x) {for(int i=0;i<x.length;i++)out.print(x[i]+" ");out.println();}
static void pc1d(char[] x) {for(int i=0;i<x.length;i++)out.print(x[i]+" ");out.println();}
static void pb2d(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 pc2d(char[][] 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(int[][] 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 pl2d(long[][] 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();}}
// *****************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;}
public int[] rdia(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = nextInt();return a;}
public long[] rdla(int n) {long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}
public Integer[] rdIa(int n) {Integer[] a = new Integer[n];for (int i = 0; i < n; i++) a[i] =nextInt();return a;}
public Long[] rdLa(int n) {Long[] a = new Long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}
}
class dsu{
int n;
static int parent[];
static int rank[];
static int[]Size;
public dsu(int n) {this.n=n;this.parent=new int[n];this.rank=new int[n];this.Size=new int[n];
for(int i=0;i<n;i++){parent[i]=i;rank[i]=0;Size[i]=1;}
}
static int findpar(int node) {if(node==parent[node])return node;return parent[node]=findpar(parent[node]);}
static void union(int u,int v){
u=findpar(u);v=findpar(v);
if(u!=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];}
}
}
}
class pair{
int x;int y;
long u,v;
public pair(int x,int y){this.x=x;this.y=y;}
public pair(long u,long v) {this.u=u;this.v=v;}
}
class Tuple{
String str;int x;int y;
public Tuple(String str,int x,int y) {
this.str=str;
this.x=x;
this.y=y;
}
}
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 | ["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 8 | 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 | 14cc0deb405ea6cb2fe49b7f86be040a | train_109.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>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 QH {
public static final 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();
}
StringBuilder str=new StringBuilder(" ");
int currQ=0;
for(int i=n-1;i>=0;i--) {
if(arr[i]>currQ && currQ+1<=q) {
currQ++;
str.insert(0, '1');
}else if(arr[i]<=currQ){
str.insert(0, '1');
}else{
str.insert(0, '0');
}
}
System.out.println(str.toString().trim());
}
}
} | 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 8 | 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 | e9cd9e867150de76b0b8db51329b2fd1 | train_109.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>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 | /*
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]);
int q=Integer.parseInt(str[1]);
// long r=Long.parseLong(str[2]);
int[] arr=new int[n];
ArrayList<Integer> bad=new ArrayList<>();
String[] str1=br.readLine().split(" ");
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str1[i]);
if(arr[i]>q)bad.add(i);
}
int low=0;
int high=bad.size()-1;
int ans=n;
while(low<=high){
int mid=low+(high-low)/2;
int x=q;
boolean flag=true;
for(int i=bad.get(mid);i<n;i++){
if(x==0)flag=false;
if(arr[i]>x)x--;
}
if(flag==true){
high=mid-1;
ans=bad.get(mid);
}else{
low=mid+1;
}
}
StringBuilder sb=new StringBuilder();
for(int i=0;i<n;i++){
if(arr[i]>q){
if(i<ans){
sb.append(0);
}else{
sb.append(1);
}
}else{
sb.append(1);
}
}
pw.println(sb);
}
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 | ["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 8 | 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 | 3860e32f99246c43153953b7c09ff532 | train_109.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>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 | //---#ON_MY_WAY---
//---#THE_SILENT_ONE---
import static java.lang.Math.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class apples {
static FastReader x = new FastReader();
static OutputStream outputStream = System.out;
static PrintWriter out = new PrintWriter(outputStream);
/*---------------------------------------CODE STARTS HERE-------------------------*/
public static void main(String[] args) throws NumberFormatException, IOException {
long startTime = System.nanoTime();
int mod = 1000000007;
int t = x.nextInt();
StringBuilder str = new StringBuilder();
while (t > 0) {
int n = x.nextInt(), k = x.nextInt();
int a[] = readarr(n);
HashSet<Integer> ans = new HashSet<>();
int ind = n-1, iq = a[ind]==1?1:0;
while(ind>=0&&iq<k) {
if(a[ind]>iq) {
iq++;
}
ans.add(ind);
ind--;
}
while(ind>=0) {
if(a[ind]<=iq) ans.add(ind);
ind--;
}
for(int i = 0; i < n; i++) {
if(ans.contains(i)) str.append(1);
else str.append(0);
}
str.append("\n");
t--;
}
out.println(str);
out.flush();
long endTime = System.nanoTime();
//System.out.println((endTime-startTime)/1000000000.0);
}
/*--------------------------------------------FAST I/O-------------------------------*/
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;
}
char nextchar() {
char ch = ' ';
try {
ch = (char) br.read();
} catch (IOException e) {
e.printStackTrace();
}
return ch;
}
}
/*--------------------------------------------HELPER---------------------------------*/
static class pair implements Comparable<pair> {
int x, y;
public pair(int a, int b) {
x = a;
y = b;
}
@Override
public int hashCode() {
int hash = 3;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final pair other = (pair) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public int compareTo(apples.pair o) {
if(this.x==o.x) return this.y-o.y;
return this.x-o.x;
}
}
/*--------------------------------------------BOILER PLATE---------------------------*/
static int[] readarr(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = x.nextInt();
}
return arr;
}
static int[] sortint(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static long[] sortlong(long a[]) {
ArrayList<Long> al = new ArrayList<>();
for (long i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < al.size(); i++) {
a[i] = al.get(i);
}
return a;
}
static long pow(long x, long y) {
long result = 1;
while (y > 0) {
if (y % 2 == 0) {
x = x * x;
y = y / 2;
} else {
result = result * x;
y = y - 1;
}
}
return result;
}
static long pow(long x, long y, long mod) {
long result = 1;
x %= mod;
while (y > 0) {
if (y % 2 == 0) {
x = (x % mod * x % mod) % mod;
y /= 2;
} else {
result = (result % mod * x % mod) % mod;
y--;
}
}
return result;
}
static int[] revsort(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al, Comparator.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static int[] gcd(int a, int b, int ar[]) {
if (b == 0) {
ar[0] = a;
ar[1] = 1;
ar[2] = 0;
return ar;
}
ar = gcd(b, a % b, ar);
int t = ar[1];
ar[1] = ar[2];
ar[2] = t - (a / b) * ar[2];
return ar;
}
static boolean[] esieve(int n) {
boolean p[] = new boolean[n + 1];
Arrays.fill(p, true);
for (int i = 2; i * i <= n; i++) {
if (p[i] == true) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
static ArrayList<Integer> primes(int n) {
boolean p[] = new boolean[n + 1];
ArrayList<Integer> al = new ArrayList<>();
Arrays.fill(p, true);
int i = 0;
for (i = 2; i * i <= n; i++) {
if (p[i] == true) {
al.add(i);
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
for (i = i; i <= n; i++) {
if (p[i] == true) {
al.add(i);
}
}
return al;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
static long gcd(long a, long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
} | 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 8 | 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 | c405a7ed08accf36dcfeddbf46aac7df | train_109.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>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 {
/*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/
public static void solve(int tCase) throws IOException {
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 l = 0;
int r = n-1;
int ans = -1;
while (l<=r){
int mid =(r+l)/2;
if(isPos(mid,arr,n,q)){
ans = mid;
r = mid-1;
}else l = mid+1;
}
for(int i=0;i<n;i++){
if(i>=ans || arr[i] <= q)out.print(1);
else out.print(0);
}
out.println();
}
private static boolean isPos(int x, int[] arr, int n,int q){
for(int i=x;i<n;i++){
if(arr[i] > q)q--;
}
return q>=0;
}
public static void main(String[] args) throws IOException {
openIO();
int testCase = 1;
testCase = sc.nextInt();
for (int i = 1; i <= testCase; i++) solve(i);
closeIO();
}
/*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/
/*--------------------------------------HELPER FUNCTIONS STARTS HERE-----------------------------------------*/
public static int mod = (int) 1e9 + 7;
// public static int mod = 998244353;
public static int inf_int = (int) 2e9 + 1000;
public static long inf_long = (long)2e15;
public static void _sort(int[] arr, boolean isAscending) {
int n = arr.length;
List<Integer> list = new ArrayList<>();
for (int ele : arr) list.add(ele);
Collections.sort(list);
if (!isAscending) Collections.reverse(list);
for (int i = 0; i < n; i++) arr[i] = list.get(i);
}
public static void _sort(long[] arr, boolean isAscending) {
int n = arr.length;
List<Long> list = new ArrayList<>();
for (long ele : arr) list.add(ele);
Collections.sort(list);
if (!isAscending) Collections.reverse(list);
for (int i = 0; i < n; i++) arr[i] = list.get(i);
}
// time : O(1), space : O(1)
public static int _digitCount(long num,int base){
// this will give the # of digits needed for a number num in format : base
return (int)(1 + Math.log(num)/Math.log(base));
}
// time : O(n), space: O(n)
public static long _fact(int n){
// simple factorial calculator
long ans = 1;
for(int i=2;i<=n;i++) ans = ans * i % mod;
return ans;
}
// time for pre-computation of factorial and inverse-factorial table : O(nlog(mod))
public static long[] factorial , inverseFact;
public static void _ncr_precompute(int n){
factorial = new long[n+1];
inverseFact = new long[n+1];
factorial[0] = inverseFact[0] = 1;
for (int i = 1; i <=n; i++) {
factorial[i] = (factorial[i - 1] * i) % mod;
inverseFact[i] = _modExpo(factorial[i], mod - 2);
}
}
// time of factorial calculation after pre-computation is O(1)
public static int _ncr(int n,int r){
if(r > n)return 0;
return (int)(factorial[n] * inverseFact[r] % mod * inverseFact[n - r] % mod);
}
public static int _npr(int n,int r){
if(r > n)return 0;
return (int)(factorial[n] * inverseFact[n - r] % mod);
}
// euclidean algorithm time O(max (loga ,logb))
public static long _gcd(long a, long b) {
while (a>0){
long x = a;
a = b % a;
b = x;
}
return b;
}
// lcm(a,b) * gcd(a,b) = a * b
public static long _lcm(long a, long b) {
return (a / _gcd(a, b)) * b;
}
// binary exponentiation time O(logn)
public static long _modExpo(long x, long n) {
long ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans *= x;
ans %= mod;
n--;
} else {
x *= x;
x %= mod;
n >>= 1;
}
}
return ans;
}
// function to find a/b under modulo mod. time : O(logn)
public static long _modInv(long a,long b){
return (a * _modExpo(b,mod-2)) % mod;
}
//sieve or first divisor time : O(mx * log ( log (mx) ) )
public static int[] _seive(int mx){
int[] firstDivisor = new int[mx+1];
for(int i=0;i<=mx;i++)firstDivisor[i] = i;
for(int i=2;i*i<=mx;i++)
if(firstDivisor[i] == i)
for(int j = i*i;j<=mx;j+=i)
if(firstDivisor[j]==j)firstDivisor[j] = i;
return firstDivisor;
}
static class Pair<K, V>{
K ff;
V ss;
public Pair(K ff, V ss) {
this.ff = ff;
this.ss = ss;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return ff.equals(pair.ff) && ss.equals(pair.ss);
}
@Override
public int hashCode() {
return Objects.hash(ff, ss);
}
@Override
public String toString(){
return ff.toString()+" "+ss.toString();
}
}
/*--------------------------------------HELPER FUNCTIONS ENDS HERE-----------------------------------------*/
/*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/
static FastestReader sc;
static PrintWriter out;
private static void openIO() throws IOException {
sc = new FastestReader();
out = new PrintWriter(System.out);
}
public static void closeIO() throws IOException {
out.flush();
out.close();
sc.close();
}
private static final class FastestReader {
private static final int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
public FastestReader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public FastestReader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
private static boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() throws IOException {
int b;
//noinspection StatementWithEmptyBody
while ((b = read()) != -1 && isSpaceChar(b)) {}
return b;
}
public String next() throws IOException {
int b = skip();
final StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = read();
}
return sb.toString();
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
final boolean neg = c == '-';
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
return neg?-ret:ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
final boolean neg = c == '-';
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
return neg?-ret:ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
final boolean neg = c == '-';
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.')
while ((c = read()) >= '0' && c <= '9')
ret += (c - '0') / (div *= 10);
return neg?-ret:ret;
}
public String nextLine() throws IOException {
final byte[] buf = new byte[(1<<10)]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
break;
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
din.close();
}
}
/*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/
}
/** Some points to keep in mind :
* 1. don't use Arrays.sort(primitive data type array)
* 2. try to make the parameters of a recursive function as less as possible,
* more use static variables.
* 3. If n = 5000, then O(n^2 logn) need atleast 4 sec to work
* 4. dp[2][n] works faster than dp[n][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 8 | 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 | fc638ee3ce046064e63024b88a7835d4 | train_109.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>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 QH {
public static final 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();
}
StringBuilder str=new StringBuilder(" ");
int currQ=0;
for(int i=n-1;i>=0;i--) {
if(arr[i]>currQ && currQ+1<=q) {
currQ++;
str.insert(0, '1');
}else if(arr[i]<=currQ){
str.insert(0, '1');
}else{
str.insert(0, '0');
}
}
System.out.println(str.toString().trim());
}
}
}
| 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 8 | 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 | 40dabbef9e0ff4db02e70904c266588c | train_109.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>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.lang.*;
import java.io.InputStreamReader;
import static java.lang.Math.*;
import static java.lang.System.out;
import java.util.*;
import java.io.File;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.math.BigInteger;
public class Main {
/* 10^(7) = 1s.
* ceilVal = (a+b-1) / b */
static final int mod = 1000000007;
static final long temp = 998244353;
static final long MOD = 1000000007;
static final long M = (long)1e9+7;
static class Pair implements Comparable<Pair>
{
int first, second;
public Pair(int first, int second)
{
this.first = first;
this.second = second;
}
public int compareTo(Pair ob)
{
return (int)(first - ob.first);
}
}
static class Tuple implements Comparable<Tuple>
{
long first, second,third;
public Tuple(long first, long second, long third)
{
this.first = first;
this.second = second;
this.third = third;
}
public int compareTo(Tuple o)
{
return (int)(o.third - this.third);
}
}
public static class DSU
{
int count = 0;
int[] parent;
int[] rank;
public DSU(int n)
{
count = n;
parent = new int[n];
rank = new int[n];
Arrays.fill(parent, -1);
Arrays.fill(rank, 1);
}
public int find(int i)
{
return parent[i] < 0 ? i : (parent[i] = find(parent[i]));
}
public void union(int a, int b) //Union Find by Rank
{
a = find(a);
b = find(b);
if(a == b) return;
if(rank[a] < rank[b])
{
parent[a] = b;
}
else if(rank[a] > rank[b])
{
parent[b] = a;
}
else
{
parent[b] = a;
rank[a] = 1 + rank[a];
}
count--;
}
public int countConnected()
{
return count;
}
}
static class Reader
{
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) throws IOException {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] longReadArray(int n) throws IOException {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static int gcd(int a, int b)
{
if(b == 0)
return a;
else
return gcd(b,a%b);
}
public static long lcm(long a, long b)
{
return (a / LongGCD(a, b)) * b;
}
public static long LongGCD(long a, long b)
{
if(b == 0)
return a;
else
return LongGCD(b,a%b);
}
public static long LongLCM(long a, long b)
{
return (a / LongGCD(a, b)) * b;
}
//Count the number of coprime's upto N
public static long phi(long n) //euler totient/phi function
{
long ans = n;
// for(long i = 2;i*i<=n;i++)
// {
// if(n%i == 0)
// {
// while(n%i == 0) n/=i;
// ans -= (ans/i);
// }
// }
//
// if(n > 1)
// {
// ans -= (ans/n);
// }
for(long i = 2;i<=n;i++)
{
if(isPrime(i))
{
ans -= (ans/i);
}
}
return ans;
}
public static long fastPow(long x, long n)
{
if(n == 0)
return 1;
else if(n%2 == 0)
return fastPow(x*x,n/2);
else
return x*fastPow(x*x,(n-1)/2);
}
public static long powMod(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;
x = (x * x) % p;
}
return res;
}
static long modInverse(long n, long p)
{
return powMod(n, p - 2, p);
}
// Returns nCr % p using Fermat's little theorem.
public static long nCrModP(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;
}
public static long fact(long n)
{
long[] fac = new long[(int)(n) + 1];
fac[0] = 1;
for (long i = 1; i <= n; i++)
fac[(int)(i)] = fac[(int)(i - 1)] * i;
return fac[(int)(n)];
}
public static long nCr(long n, long k)
{
long ans = 1;
for(long i = 0;i<k;i++)
{
ans *= (n-i);
ans /= (i+1);
}
return ans;
}
//Modular Operations for Addition and Multiplication.
public static long perfomMod(long x)
{
return ((x%M + M)%M);
}
public static long addMod(long a, long b)
{
return perfomMod(perfomMod(a)+perfomMod(b));
}
public static long subMod(long a, long b)
{
return perfomMod(perfomMod(a)-perfomMod(b));
}
public static long mulMod(long a, long b)
{
return perfomMod(perfomMod(a)*perfomMod(b));
}
public static boolean isPrime(long n)
{
if(n == 1)
{
return false;
}
//check only for sqrt of the number as the divisors
//keep repeating so only half of them are required. So,sqrt.
for(int i = 2;i*i<=n;i++)
{
if(n%i == 0)
{
return false;
}
}
return true;
}
public static List<Long> SieveList(int n)
{
boolean prime[] = new boolean[(int)(n+1)];
Arrays.fill(prime, true);
List<Long> l = new ArrayList<>();
for (long p = 2; p*p<=n; p++)
{
if (prime[(int)(p)] == true)
{
for(long i = p*p; i<=n; i += p)
{
prime[(int)(i)] = false;
}
}
}
for (long p = 2; p<=n; p++)
{
if (prime[(int)(p)] == true)
{
l.add(p);
}
}
return l;
}
public static int countDivisors(int x)
{
int c = 0;
for(int i = 1;i*i<=x;i++)
{
if(x%i == 0)
{
if(x/i != i)
{
c+=2;
}
else
{
c++;
}
}
}
return c;
}
public static long log2(long n)
{
long ans = (long)(log(n)/log(2));
return ans;
}
public static boolean isPow2(long n)
{
return (n != 0 && ((n & (n-1))) == 0);
}
public static boolean isSq(int x)
{
long s = (long)Math.round(Math.sqrt(x));
return s*s==x;
}
/*
*
* >= <=
0 1 2 3 4 5 6 7
5 5 5 6 6 6 7 7
lower_bound for 6 at index 3 (>=)
upper_bound for 6 at index 6(To get six reduce by one) (<=)
*/
public static int LowerBound(int a[], int x)
{
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;
}
public static int UpperBound(int a[], int x)
{
int l=-1, r=a.length;
while(l+1<r)
{
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
public static void Sort(long[] a)
{
List<Long> l = new ArrayList<>();
for (long i : a) l.add(i);
// Collections.sort(l);
Collections.reverse(l); //Use to Sort decreasingly
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
public static void ssort(char[] a)
{
List<Character> l = new ArrayList<>();
for (char i : a) l.add(i);
Collections.reverse(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
public static boolean f(int q, int mid, long[] a)
{
int x = q, n = a.length;
for(int i = mid;i<=n-1;i++)
{
if(x == 0) return false;
if(a[i] <= x) continue;
if(a[i] > x) x--;
}
return true;
}
public static void main(String[] args) throws Exception
{
Reader sc = new Reader();
PrintWriter fout = new PrintWriter(System.out);
int tt = sc.nextInt();
while(tt-- > 0)
{
int n = sc.nextInt(), q= sc.nextInt();
long[] a = sc.longReadArray(n);
Sort(a);
long c = 0;
char[] s = new char[n];
for(int i = 0;i<n;i++) s[i] = '0';
for(int i = 0;i<n;i++)
{
if(c >= a[i])
{
s[i] = '1';
}
else
{
if(c + 1 <= q)
{
s[i] = '1';
c++;
}
}
}
ssort(s);
fout.println(new String(s));
}
fout.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 8 | 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 | f298ea665757c446f29541f881c9a0d6 | train_109.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>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.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 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();
int q=in.readInt();
int a[]=nia1(n);
char c[]=new char[n];
if(q>=n) {
Arrays.fill(c, '1');
print(new String(c));
return;
}
int x=0;
Arrays.fill(c,'0');
for(int i=n;i>0;i--) {
if(x>=q) {
if(x==q&&a[i]<=q) {
c[i-1]='1';
}
}
else {
if(a[i]>x) {
x++;
c[i-1]='1';
}
else {
c[i-1]='1';
}
}
}
print(new String(c));
}
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 | ["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 8 | 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 | b2df6b6e19208d95d7ce4a75b67b55e7 | train_109.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>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.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.HashSet;
import java.util.HashMap;
import java.util.StringTokenizer;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static boolean isPalindrome(String str)
{
int i=0;
int j=str.length()-1;
int flag=0;
while(i<=j)
{
if(str.charAt(i)!=str.charAt(j))
{
flag=1;
break;
}
i++;
j--;
}
return flag==1?false:true;
}
public static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
class Pair
{
int x1;
int x2;
public Pair(int x1, int x2) {
this.x1 = x1;
this.x2 = x2;
}
}
public static int highestPowerof2(int num)
{
num |= num >> 1;
num |= num >> 2;
num |= num >> 4;
num |= num >> 8;
num |= num >> 16;
return num ^ (num >> 1);
}
public static void main (String[] args) throws java.lang.Exception
{
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int t=fs.nextInt();
while(t-->0)
{
int n =fs.nextInt();
int q=fs.nextInt();
int [] arr=new int [n];
ArrayList<Integer> good=new ArrayList<>();
ArrayList<Integer> bad=new ArrayList<>();
for(int i=0;i<n;i++)
{
arr[i]=fs.nextInt();
if(arr[i]>q)
{
bad.add(i);
}
else
{
good.add(i);
}
}
int lo=0;
int hi=bad.size()-1;
int idx=n;
while(lo<=hi)
{
int mid=(lo+hi)/2;
int flag=0;
int curiq=q;
for(int i=bad.get(mid);i<n;i++)
{
if(curiq==0)
{
flag=1;
break;
}
if(arr[i]>curiq)
{
curiq--;
}
}
if(flag==1)
{
lo=mid+1;
}
else
{
idx=bad.get(mid);
hi=mid-1;
}
}
for(int i=0;i<idx;i++)
{
if(arr[i]<=q)
{
out.print(1);
}
else{
out.print(0);
}
}
for(int i=idx;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 8 | 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 | d4fcc1634ce4f35108bf9d1827653709 | train_109.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>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 {
StringBuilder s1=new StringBuilder();
public static void main(String[] args) throws IOException {
Scanner sc =new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t=1;
t = sc.nextInt();
w:while (t-- > 0)
{
int n = sc.nextInt();
int q = sc.nextInt();
int [] a = sc.nextIntArr(n);
int [] ans = new int[n];
int cur = 0;
for(int i = n-1; i >= 0; i--){
if(cur >= a[i])
ans[i] = 1;
else if(cur < a[i] && cur < q){
ans[i] = 1;
cur++;
}
}
for(int x : ans)
pw.print(x);
pw.println();
}
pw.flush();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader f) {
br = new BufferedReader(f);
}
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 double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public int[] nextIntArr(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(next());
}
return arr;
}
}
} | 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 8 | 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 | 9ebc888403c1c9f9ac98cdabc61a22f8 | train_109.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>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.PrintWriter;
import java.lang.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.spec.RSAOtherPrimeInfo;
import java.util.*;
public class First {
static long mod = (long)(1e9+7);
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void sort(long[] arr) {
ArrayList<Long> a = new ArrayList<>();
for (long i : arr) {
a.add(i);
}
Collections.sort(a);
for (int i = 0; i < a.size(); i++) {
arr[i] = a.get(i);
}
}
static long highestPowerof2(long x) {
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
public static long fact(long number) {
if (number == 0 || number == 1) {
return 1;
} else {
return number * fact(number - 1);
}
}
public static ArrayList<Long> primeFactors(long n) {
ArrayList<Long> arr = new ArrayList<>();
long count = 0;
while (n % 2 == 0) {
arr.add(2l);
n /= 2;
}
for (long i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
arr.add(i);
n /= i;
}
}
if (n > 2)
arr.add(n);
return arr;
}
static public long[] prime(long number) {
long n = number;
long count = 0;
long even = 0;
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
if (i % 2 == 1) {
count++;
} else {
even++;
}
n /= i;
}
}
if (n > 1) {
if (n % 2 == 1) {
count++;
} else {
even++;
}
}
return new long[]{even, count};
}
static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int search(ArrayList<Integer> arr, int tar) {
int low = 0, hi = arr.size() - 1;
int ans = -1;
while (low <= hi) {
int mid = (low + hi) / 2;
if (arr.get(mid) > tar) {
ans = arr.get(mid);
hi = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static long gcd(long a, long b) {
// if b=0, a is the GCD
if (b == 0)
return a;
else
return gcd(b, a % b);
}
static long power(long x, long y, long p) {
long res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static int get(long[] arr, long tar){
int ans = -1;
int l = 0;
int h = arr.length-1;
while(l <= h){
int mid = l + (h-l)/2;
if(arr[mid] <= tar){
ans = mid;
l = mid+1;
}else{
h = mid-1;
}
}
return ans;
}
public static long maxSum(long arr[],int k)
{
int n = arr.length;
if (n < k || k < 0)
{
return Long.MAX_VALUE;
}
long res = 0;
for (int i=0; i<k; i++)
res += arr[i];
long curr_sum = res;
for (int i=k; i<n; i++)
{
curr_sum += arr[i] - arr[i-k];
res = Math.min(res, curr_sum);
}
return res;
}
static int get(ArrayList<long[]> arr, long tar){
int ans = -1;
int l = 0;
int h = arr.size()-1;
while(l <= h){
int mid = (l+h)/2;
if(arr.get(mid)[0] > tar){
ans = mid;
h = mid-1;
}else{
l = mid+1;
}
}
return ans;
}
static long closestMultiple(long n, long x)
{
if(x>n)
return x;
n = n + x/2;
n = n - (n%x);
return n;
}
static void print_Array(int[] arr){
for(int i: arr){
System.out.print(i+" ");
}
System.out.println();
}
static boolean check(int mid, long[] arr, int[] ans, long q){
for(int i = 0; i < mid; i++){
if(arr[i] <= q){
ans[i] = 1;
}else{
ans[i] = 0;
}
}
for(int i = mid; i < arr.length; i++){
if(arr[i] > q){
q--;
ans[i] = 1;
}else if(arr[i] <= q){
ans[i] = 1;
}
if(q < 0) return false;
}
return q < 0 ? false: true;
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int[] ans = new int[n];
long[] arr = new long[n];
long q = sc.nextLong();
for(int i = 0; i < n; i++){
arr[i] = sc.nextLong();
}
int l = 0;
int r = n-1;
int ind = 0;
while(l <= r){
int mid = (l+r)/2;
if(check(mid,arr,ans,q)){
ind = mid;
r = mid-1;
}else{
l = mid+1;
}
}
check(ind,arr,ans,q);
for(int i: ans){
System.out.print(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 8 | 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 | d8c6ba94d1c79168881aa316260bf052 | train_109.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>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.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
static int mod = (int) 1e9 + 7;
static PrintWriter out;
static ArrayList<pair> []adj;
static char [] arr = new char [] {'R','P','S'};
static String [] line;
static int [][][] dp;
static int n,m,ans;
public static void main(String[] args) throws IOException, InterruptedException {
Scanner sc = new Scanner(System.in);
out = new PrintWriter(System.out);
int t = sc.nextInt();
w:while(t--!=0)
{
int n = sc.nextInt();
int q = sc.nextInt();
int [] arr = sc.nextIntArray(n);
int [] ans = new int [n];
int x =0;
for(int i=n-1;i!=-1;i--)
{
if(arr[i]>x)
{
if(x==q)
continue;
x++;
ans[i]=1;
}
else
ans[i]=1;
}
for(int i:ans)
out.print(i);
out.println();
}
out.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
static class pair implements Comparable<pair> {
int x;
int y;
public pair(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair) o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Long(x).hashCode() * 31 + new Long(y).hashCode();
}
public int compareTo(pair other) {
return this.x - other.x;
}
}
static class tuble {
int x;
int y;
int z;
public tuble(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return x + " " + y + " " + z;
}
}
static class SegmentTree { // 1-based DS, OOP
int N; // the number of elements in the array as a power of 2 (i.e. after padding)
int[] array, sTree, lazy;
SegmentTree(int[] in) {
array = in;
N = in.length - 1;
sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
lazy = new int[N << 1];
build(1, 1, N);
}
void build(int node, int b, int e) // O(n)
{
if (b == e)
sTree[node] = array[b];
else {
int mid = b + e >> 1;
build(node << 1, b, mid);
build(node << 1 | 1, mid + 1, e);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void update_point(int index, int val) // O(log n)
{
index += N - 1;
sTree[index] += val;
while (index > 1) {
index >>= 1;
sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
}
}
void update_range(int i, int j, int val) // O(log n)
{
update_range(1, 1, N, i, j, val);
}
void update_range(int node, int b, int e, int i, int j, int val) {
if (i > e || j < b)
return;
if (b >= i && e <= j) {
sTree[node] += (e - b + 1) * val;
lazy[node] += val;
} else {
int mid = b + e >> 1;
propagate(node, b, mid, e);
update_range(node << 1, b, mid, i, j, val);
update_range(node << 1 | 1, mid + 1, e, i, j, val);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void propagate(int node, int b, int mid, int e) {
lazy[node << 1] += lazy[node];
lazy[node << 1 | 1] += lazy[node];
sTree[node << 1] += (mid - b + 1) * lazy[node];
sTree[node << 1 | 1] += (e - mid) * lazy[node];
lazy[node] = 0;
}
int query(int i, int j) {
return query(1, 1, N, i, j);
}
int query(int node, int b, int e, int i, int j) // O(log n)
{
if (i > e || j < b)
return 0;
if (b >= i && e <= j)
return sTree[node];
int mid = b + e >> 1;
propagate(node, b, mid, e);
int q1 = query(node << 1, b, mid, i, j);
int q2 = query(node << 1 | 1, mid + 1, e, i, j);
return q1 + q2;
}
}
} | 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 8 | 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 | c4673c57c8e6258ac65e4608f81df45a | train_109.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>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 MyClass5 {
public static boolean solve (int []arr, int i){
if(i == arr.length){
return true ;
}
if((Math.floor( (arr[i]-1.0)/(arr[i-1]) ) == (arr[i]-1.0)/(arr[i-1]) || arr[i]==1) && i!=arr.length-1 ){
return true ;
}
if(arr[i]%arr[i-1] == 0){
arr[i] = arr[i-1] ;
return solve(arr,i+1) ;
}
else{
return false ;
}
}
public static void doJob(Scanner sc, PrintWriter pw) throws Exception{
//select between doJob and doJobT
int n = sc.nextInt() ;
int q = sc.nextInt() ;
int qR = 0;
int [] arr = sc.nextIntArray(n) ;
LinkedList<Integer> res = new LinkedList<>() ;
for(int i=n-1 ; i>=0 ; i--){
if(arr[i]<=qR){
res.addFirst(1);
}
else{
if(qR<q){
res.addFirst(1);
qR++ ;
}
else{
res.addFirst(0);
}
}
}
for(Integer x : res){
pw.print(x+"") ;
}
pw.println();
}
public static void doJobT(Scanner sc, PrintWriter pw) throws Exception{
int t = sc.nextInt() ;
while(t-->0){
doJob(sc,pw) ;
}
}
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in) ;
PrintWriter pw = new PrintWriter(System.out) ;
//doJob(sc,pw) ;
doJobT(sc,pw);
pw.flush();
pw.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new
InputStreamReader(s));}
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 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();}
}
static class pair implements Comparable<pair> {
long x;
long y;
public pair(long x, long y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair) o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Long(x).hashCode() * 31 + new Long(y).hashCode();
}
public int compareTo(pair other) {
if (this.x == other.x) {
return Long.compare(this.y, other.y);
}
return Long.compare(this.x, other.x);
}
}
static class tuble implements Comparable<tuble> {
int x;
int y;
int z;
public tuble(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return x + " " + y + " " + z;
}
public int compareTo(tuble other) {
if (this.x == other.x) {
if (this.y == other.y) {
return this.z - other.z;
}
return this.y - other.y;
} else {
return this.x - other.x;
}
}
}
}
| 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 8 | 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 | 2b4fcde6c135323926c38d1d062a5e7e | train_109.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>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 Balabizo {
static int GCD(int a , int b){
if(b == 0)
return a;
return GCD(b , a%b);
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int tt = sc.nextInt();
while(tt-->0){
int n = sc.nextInt() , q = sc.nextInt();
int[] a = sc.nextIntArray(n);
int low = 0 , high = n-1;
while(low <= high){
int mid = (low+high)/2;
int have = q;
boolean f = true;
for(int i=mid; i<n ;i++){
if(have == 0){
f = false;
break;
}
if(a[i] > have)
have--;
}
if(f)
high = mid-1;
else
low = mid+1;
}
for(int i=0; i<low ;i++)
pw.print((a[i] <= q)? 1 : 0);
for(int i=low; i<n ;i++)
pw.print(1);
pw.println();
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String file) throws IOException {
br = new BufferedReader(new FileReader(file));
}
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 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 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 8 | 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 | 1ef4fbea0fa8a18ea9a34032196e3cbb | train_109.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>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.io.File;
/**
* Created on 2022-07-16 22:34:23
*
* @author macinchang
*/
public class C {
public static void main(String[] args) throws Exception {
Scanner scanner;
if (System.getProperty("ONLINE_JUDGE") == null) {
File inFile = new File("in.txt");
scanner = new Scanner(inFile);
} else {
scanner = new Scanner(System.in);
}
int t = scanner.nextInt();
Solver solver = new Solver(scanner);
while (t-- > 0) {
solver.solve();
}
scanner.close();
}
public static class Solver {
private Scanner sc;
Solver(Scanner scanner) {
this.sc = scanner;
}
public void solve() {
int n = sc.nextInt(), q = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int cur = 0, ans = 0;
StringBuffer res = new StringBuffer();
for (int i = n - 1; i >= 0; i--) {
if (a[i] <= cur) {
++ans;
res.append("1");
} else if (cur < q) {
++ans;
++cur;
res.append("1");
} else {
res.append("0");
}
}
System.out.println(res.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 8 | 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 | 1d6d5f83dfaf6737c6c82839ad11e0e9 | train_109.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>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.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.Stack;
import java.util.HashSet;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.TreeMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.ArrayDeque;
import static java.lang.Math.min;
import static java.lang.Math.max;
import static java.lang.Math.sqrt;
import static java.lang.Math.pow;
import static java.lang.Math.abs;
import static java.lang.Integer.MIN_VALUE;
import static java.lang.Integer.MAX_VALUE;
public class Main {
static boolean IS_LOCAL = false;
static Fast f = new Fast();
static PrintWriter out = new PrintWriter(System.out);
static boolean TEST_CASES = true;
static int mod1 = (int)1e9+7;
static int mod2 = 998244353;
static void solve() {
int n = ri(), iq = ri();
int[] a = ra(n);
int[] ans = new int[n];
ans[n-1] = 1;
int p = 1;
int max = a[n-1];
for(int i = n-2; i > -1; i--) {
if(p>iq){
if(a[i]<=iq) ans[i] = 1;
}
else{
if(a[i]<=p) ans[i] = 1;
else{
p = Math.min(p+1,Math.min(n-i,Math.max(max,a[i])));
if(p<=iq) ans[i] = 1;
}
}
//out.println(i+" "+p);
}
for(int i = 0; i < n; i++) out.print(ans[i]);
out.println();
}
public static void main(String[] args)throws Exception{
if(TEST_CASES){
int t = ri();
while(t-->0){
solve();
}
}
else {
solve();
}
out.close();
}
static int nod(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>=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;
}
static int ri() {
return f.nextInt();
}
static long rl() {
return f.nextLong();
}
static String rs(){
return f.next();
}
static String rS(){
return f.nextLine();
}
static char rc(){
return f.next().charAt(0);
}
static int[] ra(int n) {
int[] a = new int[n];
for(int i = 0;i<n;i++) a[i] = ri();
return a;
}
static long[] ral(int n) {
long[] a = new long[n];
for(int i = 0;i<n;i++) a[i] = rl();
return a;
}
static char[] rac(){
char[] c = rs().toCharArray();
return c;
}
static int[][] rm(int n, int m){
int[][] mat = new int[n][m];
for(int i = 0; i < n; i++) mat[i] = ra(m);
return mat;
}
static char[][] rmc(int n){
char[][] cmat = new char[n][];
for(int i = 0; i < n;i++) cmat[i] = rac();
return cmat;
}
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(double[] a) {
ArrayList<Double> list=new ArrayList<>();
for (double i:a) list.add(i);
Collections.sort(list);
for (int i=0; i<a.length; i++) a[i]=list.get(i);
}
static class Fast{
public BufferedReader br;
public StringTokenizer st;
public Fast(){
try{
br = IS_LOCAL? (new BufferedReader(new FileReader("input.txt"))):(new BufferedReader(new InputStreamReader(System.in)));
}
catch(Exception e){
throw new RuntimeException(e);
}
}
String next(){
while(st==null || !st.hasMoreTokens()){
try{
st=new StringTokenizer(br.readLine());
}
catch(IOException e){
throw new RuntimeException(e);
}
}
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 8 | 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 | 748fa46a47941fa2f1ddfba7a87e939c | train_109.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>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.StringTokenizer;
public class C_Doremy_s_IQ {
static Scanner in = new Scanner();
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans = new StringBuilder();
static int testCases, n;
static long q;
static long a[];
static void solve(int t) {
long current = 0L;
long finalAns[] = new long[n + 1];
StringBuilder sb = new StringBuilder();
for (int i = n; i >= 1; --i) {
if (a[i] > current) {
if (current < q) {
++current;
finalAns[i] = 1;
}
} else {
finalAns[i] = 1L;
}
}
for (int i = 1; i <= n; ++i) {
sb.append(finalAns[i]);
}
ans.append(sb.toString().trim());
if (t != testCases) {
ans.append("\n");
}
}
public static void main(String[] priya) throws IOException {
testCases = in.nextInt();
for (int t = 0; t < testCases; ++t) {
n = in.nextInt();
q = in.nextLong();
a = new long[n + 1];
for (int i = 1; i <= n; ++i) {
a[i] = in.nextLong();
}
solve(t + 1);
}
in.close();
out.print(ans.toString());
out.flush();
}
static int search(long a[], long x, int last) {
int i = 0, j = last;
while (i <= j) {
int mid = i + (j - i) / 2;
if (a[mid] == x) {
return mid;
}
if (a[mid] < x) {
i = mid + 1;
} else {
j = mid - 1;
}
}
return -1;
}
static void swap(long a[], int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static void reverse(long a[]) {
n = a.length;
for (int i = 0; i < n / 2; ++i) {
swap(a, i, n - i - 1);
}
}
static long max(long a[], int i, int n, long max) {
if (i > n) {
return max;
}
max = Math.max(a[i], max);
return max(a, i + 1, n, max);
}
static long min(long a[], int i, int n, long max) {
if (i > n) {
return max;
}
max = Math.min(a[i], max);
return max(a, i + 1, n, max);
}
static void printArray(long a[]) {
for (long i : a) {
System.out.print(i + " ");
}
System.out.println();
}
static boolean isSmaller(String str1, String str2) {
int n1 = str1.length(), n2 = str2.length();
if (n1 < n2) {
return true;
}
if (n2 < n1) {
return false;
}
for (int i = 0; i < n1; i++) {
if (str1.charAt(i) < str2.charAt(i)) {
return true;
} else if (str1.charAt(i) > str2.charAt(i)) {
return false;
}
}
return false;
}
static String sub(String str1, String str2) {
if (isSmaller(str1, str2)) {
String t = str1;
str1 = str2;
str2 = t;
}
String str = "";
int n1 = str1.length(), n2 = str2.length();
int diff = n1 - n2;
int carry = 0;
for (int i = n2 - 1; i >= 0; i--) {
int sub
= (((int) str1.charAt(i + diff) - (int) '0')
- ((int) str2.charAt(i) - (int) '0')
- carry);
if (sub < 0) {
sub = sub + 10;
carry = 1;
} else {
carry = 0;
}
str += String.valueOf(sub);
}
for (int i = n1 - n2 - 1; i >= 0; i--) {
if (str1.charAt(i) == '0' && carry > 0) {
str += "9";
continue;
}
int sub = (((int) str1.charAt(i) - (int) '0')
- carry);
if (i > 0 || sub > 0) {
str += String.valueOf(sub);
}
carry = 0;
}
return new StringBuilder(str).reverse().toString();
}
static String sum(String str1, String str2) {
if (str1.length() > str2.length()) {
String t = str1;
str1 = str2;
str2 = t;
}
String str = "";
int n1 = str1.length(), n2 = str2.length();
int diff = n2 - n1;
int carry = 0;
for (int i = n1 - 1; i >= 0; i--) {
int sum = ((int) (str1.charAt(i) - '0')
+ (int) (str2.charAt(i + diff) - '0') + carry);
str += (char) (sum % 10 + '0');
carry = sum / 10;
}
for (int i = n2 - n1 - 1; i >= 0; i--) {
int sum = ((int) (str2.charAt(i) - '0') + carry);
str += (char) (sum % 10 + '0');
carry = sum / 10;
}
if (carry > 0) {
str += (char) (carry + '0');
}
return new StringBuilder(str).reverse().toString();
}
static long detect_sum(int i, long a[], long sum) {
if (i >= a.length) {
return sum;
}
return detect_sum(i + 1, a, sum + a[i]);
}
static String mul(String num1, String num2) {
int len1 = num1.length();
int len2 = num2.length();
if (len1 == 0 || len2 == 0) {
return "0";
}
int result[] = new int[len1 + len2];
int i_n1 = 0;
int i_n2 = 0;
for (int i = len1 - 1; i >= 0; i--) {
int carry = 0;
int n1 = num1.charAt(i) - '0';
i_n2 = 0;
for (int j = len2 - 1; j >= 0; j--) {
int n2 = num2.charAt(j) - '0';
int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
carry = sum / 10;
result[i_n1 + i_n2] = sum % 10;
i_n2++;
}
if (carry > 0) {
result[i_n1 + i_n2] += carry;
}
i_n1++;
}
int i = result.length - 1;
while (i >= 0 && result[i] == 0) {
i--;
}
if (i == -1) {
return "0";
}
String s = "";
while (i >= 0) {
s += (result[i--]);
}
return s;
}
static class Node<T> {
T data;
Node<T> next;
public Node() {
this.next = null;
}
public Node(T data) {
this.data = data;
this.next = null;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Node<T> getNext() {
return next;
}
public void setNext(Node<T> next) {
this.next = next;
}
@Override
public String toString() {
return this.getData().toString() + " ";
}
}
static class ArrayList1<T> {
Node<T> head, tail;
int len;
public ArrayList1() {
this.head = null;
this.tail = null;
this.len = 0;
}
int size() {
return len;
}
boolean isEmpty() {
return len == 0;
}
int indexOf(T data) {
if (isEmpty()) {
throw new ArrayIndexOutOfBoundsException();
}
Node<T> temp = head;
int index = -1, i = 0;
while (temp != null) {
if (temp.getData() == data) {
index = i;
}
i++;
temp = temp.getNext();
}
return index;
}
void add(T data) {
Node<T> newNode = new Node<>(data);
if (isEmpty()) {
head = newNode;
tail = newNode;
len++;
} else {
tail.setNext(newNode);
tail = newNode;
len++;
}
}
void see() {
if (isEmpty()) {
throw new ArrayIndexOutOfBoundsException();
}
Node<T> temp = head;
while (temp != null) {
out.print(temp.getData().toString() + " ");
out.flush();
temp = temp.getNext();
}
out.println();
out.flush();
}
void inserFirst(T data) {
Node<T> newNode = new Node<>(data);
Node<T> temp = head;
if (isEmpty()) {
head = newNode;
tail = newNode;
len++;
} else {
newNode.setNext(temp);
head = newNode;
len++;
}
}
T get(int index) {
if (isEmpty() || index >= len) {
throw new ArrayIndexOutOfBoundsException();
}
if (index == 0) {
return head.getData();
}
Node<T> temp = head;
int i = 0;
T data = null;
while (temp != null) {
if (i == index) {
data = temp.getData();
}
i++;
temp = temp.getNext();
}
return data;
}
void addAt(T data, int index) {
if (index >= len) {
throw new ArrayIndexOutOfBoundsException();
}
Node<T> newNode = new Node<>(data);
int i = 0;
Node<T> temp = head;
while (temp.next != null) {
if (i == index) {
newNode.setNext(temp.next);
temp.next = newNode;
}
i++;
temp = temp.getNext();
}
// temp.setNext(temp);
len++;
}
void popFront() {
if (isEmpty()) {
//return;
throw new ArrayIndexOutOfBoundsException();
}
if (head == tail) {
head = null;
tail = null;
} else {
head = head.getNext();
}
len--;
}
void removeAt(int index) {
if (index >= len) {
throw new ArrayIndexOutOfBoundsException();
}
if (index == 0) {
this.popFront();
return;
}
Node<T> temp = head;
int i = 0;
Node<T> n = new Node<>();
while (temp != null) {
if (i == index) {
n.next = temp.next;
temp.next = n;
break;
}
i++;
n = temp;
temp = temp.getNext();
}
tail = n;
--len;
}
void clearAll() {
this.head = null;
this.tail = null;
}
}
static void merge(long a[], int left, int right, int mid) {
int n1 = mid - left + 1, n2 = right - mid;
long L[] = new long[n1];
long R[] = new long[n2];
for (int i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (int i = 0; i < n2; i++) {
R[i] = a[mid + 1 + i];
}
int i = 0, j = 0, k1 = left;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
a[k1] = L[i];
i++;
} else {
a[k1] = R[j];
j++;
}
k1++;
}
while (i < n1) {
a[k1] = L[i];
i++;
k1++;
}
while (j < n2) {
a[k1] = R[j];
j++;
k1++;
}
}
static void sort(long a[], int left, int right) {
if (left >= right) {
return;
}
int mid = (left + right) / 2;
sort(a, left, mid);
sort(a, mid + 1, right);
merge(a, left, right, mid);
}
static class Scanner {
BufferedReader in;
StringTokenizer st;
public Scanner() {
in = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
String nextLine() throws IOException {
return in.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
void close() throws IOException {
in.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 8 | 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 | 102c985929fcad0e394f355efaf31602 | train_109.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>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 long startTime = System.currentTimeMillis();
// for global initializations and methods starts here
// global initialisations and methods end here
static void run() {
boolean tc = true;
AdityaFastIO r = new AdityaFastIO();
//FastReader r = new FastReader();
try (OutputStream out = new BufferedOutputStream(System.out)) {
//long startTime = System.currentTimeMillis();
int testcases = tc ? r.ni() : 1;
int tcCounter = 1;
// Hold Here Sparky------------------->>>
// Solution Starts Here
start:
while (testcases-- > 0) {
int n = r.ni();
long q = r.nl();
List<Long> al = readLongList(n, r);
long there = 0;
for (int i = n - 1; i >= 0; i--) {
long val = 1;
if (there < al.get(i)) {
if (there < q) there++;
else val = 0;
}
al.set(i, val);
}
for (long ele : al) out.write((ele + "").getBytes());
out.write(("\n").getBytes());
}
// Solution Ends Here
} catch (IOException e) {
e.printStackTrace();
}
}
static class AdityaFastIO {
final private int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
public BufferedReader br;
public StringTokenizer st;
public AdityaFastIO() {
br = new BufferedReader(new InputStreamReader(System.in));
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public AdityaFastIO(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String readLine() throws IOException {
byte[] buf = new byte[100000001]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int ni() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public long nl() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public double nd() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null) return;
din.close();
}
}
public static void main(String[] args) throws Exception {
run();
}
static int[] readIntArr(int n, AdityaFastIO r) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = r.ni();
return arr;
}
static long[] readLongArr(int n, AdityaFastIO r) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = r.nl();
return arr;
}
static List<Integer> readIntList(int n, AdityaFastIO r) throws IOException {
List<Integer> al = new ArrayList<>();
for (int i = 0; i < n; i++) al.add(r.ni());
return al;
}
static List<Long> readLongList(int n, AdityaFastIO r) throws IOException {
List<Long> al = new ArrayList<>();
for (int i = 0; i < n; i++) al.add(r.nl());
return al;
}
static long mod = 998244353;
static long modInv(long base, long e) {
long result = 1;
base %= mod;
while (e > 0) {
if ((e & 1) > 0) result = result * base % mod;
base = base * base % mod;
e >>= 1;
}
return result;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int ni() {
return Integer.parseInt(word());
}
long nl() {
return Long.parseLong(word());
}
double nd() {
return Double.parseDouble(word());
}
}
static int MOD = (int) (1e9 + 7);
static long powerLL(long x, long n) {
long result = 1;
while (n > 0) {
if (n % 2 == 1) result = result * x % MOD;
n = n / 2;
x = x * x % MOD;
}
return result;
}
static long powerStrings(int i1, int i2) {
String sa = String.valueOf(i1);
String sb = String.valueOf(i2);
long a = 0, b = 0;
for (int i = 0; i < sa.length(); i++) a = (a * 10 + (sa.charAt(i) - '0')) % MOD;
for (int i = 0; i < sb.length(); i++) b = (b * 10 + (sb.charAt(i) - '0')) % (MOD - 1);
return powerLL(a, b);
}
static long gcd(long a, long b) {
if (a == 0) return b;
else return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static long lower_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] >= x) r = m;
else l = m;
}
return r;
}
static int upper_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] <= x) l = m;
else r = m;
}
return l + 1;
}
static void addEdge(ArrayList<ArrayList<Integer>> graph, int edge1, int edge2) {
graph.get(edge1).add(edge2);
graph.get(edge2).add(edge1);
}
public static class Pair implements Comparable<Pair> {
int first;
int second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if (this.first != o.first)
return (int) (this.first - o.first);
else return (int) (this.second - o.second);
}
@Override
public int hashCode() {
int hash = 5;
hash = 17 * hash + this.first;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final Pair other = (Pair) obj;
return this.first == other.first;
}
}
public static class PairC<X, Y> implements Comparable<PairC> {
X first;
Y second;
public PairC(X first, Y second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(PairC o) {
// TODO Auto-generated method stub
return o.compareTo((PairC) first);
}
}
static boolean isCollectionsSorted(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) <= list.get(i - 1)) return false;
return true;
}
static boolean isCollectionsSortedReverseOrder(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) >= list.get(i - 1)) return false;
return true;
}
} | Java | ["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 8 | 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 | 9a0f830e4c459d341259333e9b88f118 | train_109.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>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();
long q=sc.nextLong();
long[] a=new long[n+1];
for(int i=1;i<=n;i++)
a[i]=sc.nextLong();
long current=0;
int ans=0;
boolean[] bits=new boolean[n+1];
for(int i=n;i>0;i--) {
if(current>=a[i]) {
ans++;
bits[i]=true;
continue;
}
else if(current<a[i]) {
if(current<q) {
current++;
ans++;
bits[i]=true;
}
}
}
for(int i=1;i<=n;i++)
System.out.print(bits[i] ? "1" : "0");
System.out.println();
}
sc.close();
}
private static long gcd(long a,long b) {
if(a==0 || b==0)
return a+b;
while(a%b!=0) {
long t=b;
b=a%b;
a=t;
}
return b;
}
} | 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 8 | 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 | 1121ecfa8470566902d36dc0748e9b9c | train_109.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>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.*;
// res.append("Case #"+(p+1)+": "+hh+" \n");
////***************************************************************************
/* public class E_Gardener_and_Tree implements Runnable{
public static void main(String[] args) throws Exception {
new Thread(null, new E_Gardener_and_Tree(), "E_Gardener_and_Tree", 1<<28).start();
}
public void run(){
WRITE YOUR CODE HERE!!!!
JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!!
}
}
*/
/////**************************************************************************
public class dor{
public static void main(String[] args) {
FastScanner s= new FastScanner();
//PrintWriter out=new PrintWriter(System.out);
//end of program
//out.println(answer);
//out.close();
StringBuilder res = new StringBuilder();
int t=s.nextInt();
int p=0;
while(p<t){
int n=s.nextInt();
long q=s.nextLong();
long array[]= new long[n];
for(int i=0;i<n;i++){
array[i]=s.nextLong();
}
long ans[]= new long[n];
long hh=0;
for(int i=n-1;i>=0;i--){
long num=array[i];
if(hh<q){
if(num<=hh){
ans[i]=1;
}
else{
ans[i]=1;
hh++;
}
}
else{
if(num<=q){
ans[i]=1;
}
}
}
for(int i=0;i<n;i++){
res.append(ans[i]);
}
res.append("\n");
p++;}
System.out.println(res);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
static long modpower(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
if (x == 0)
return 0; // In case x is divisible by 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;
}
// SIMPLE POWER FUNCTION=>
static long power(long x, long y)
{
long res = 1; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = res * x;
// y must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
}
return res;
}
} | 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 8 | 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 | ee57b13edf60f6e4db990f4d543ea2af | train_109.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>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 static java.lang.Math.*;
public class Codeforces {
public static PrintWriter out;
public static Scanner sc;
public static void main(String[] args) throws IOException {
sc = new Scanner(System.in);
out = new PrintWriter(System.out);
int t = 1;
t = sc.nextInt();
while(t-->0) solve();
out.flush();
out.close();
}
public static void solve() throws IOException{
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 l = 0; //can always do 0 contests
int r = n+1; //can never do r contests
while(l + 1 < r){
int M = l + (r-l)/2;
if(isPossible(M, arr, q)) l = M;
else r = M;
}
int canMiss = n-l;
for (int i = 0; i < arr.length; i++) {
if(arr[i] <= q) out.print(1);
else if(canMiss > 0){
out.print(0);
canMiss--;
}else out.print(1);
}
out.println();
}
public static boolean isPossible(int M, int[] arr, int q){
int missingRemain = arr.length - M;
for (int i = 0; i < arr.length; i++) {
if(arr[i] > q ) {
if(missingRemain > 0) missingRemain--;
else q--;
}
}
return q >= 0;
}
//greatest common divisor
public static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static void sort(int[] arr) {
sort(arr, Comparator.naturalOrder());
}
public static void sort(int[] arr, Comparator orderStyle) {
//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, orderStyle);
for(int i=0; i < arr.length; i++) arr[i] = ls.get(i);
}
public static void sort(long[] arr) {
sort(arr, Comparator.naturalOrder());
}
public static void sort(long[] arr, Comparator orderStyle) {
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Long> ls = new ArrayList<Long>();
for(long x: arr) ls.add(x);
Collections.sort(ls, orderStyle);
for(int i=0; i < arr.length; i++) arr[i] = ls.get(i);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
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 char nextChar() throws IOException {return next();}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
}
| 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 8 | 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 | c61fab385bd47bcca09a516f83d68a3b | train_109.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>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.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
StringBuffer out = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = in.nextInt();
// int T = 1;
String[] input;
LABEL:
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[] req = new int[n];
req[n-1] = 1;
for(int i=n-2; i>=0; i--) {
req[i] = req[i+1];
if (a[i]>req[i+1]) {
req[i] += 1;
}
}
boolean[] flag = new boolean[n];
for(int i=0; i<n; i++) {
if (q>=req[i]) {
break;
}
if (a[i]>q) {
flag[i] = true;
}
}
for(boolean item: flag) {
out.append(item?0:1);
}
out.append("\n");
}
System.out.print(out);
}
private static long lcm(long a, long b) {
return a * (b/gcd(a, b));
}
private static long gcd(long a, long b) {
if(a==0) {
return b;
}
return gcd(b%a, a);
}
private static int toInt(String num) {
return Integer.parseInt(num);
}
private static long toLong(String num) {
return Long.parseLong(num);
}
}
| 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 8 | 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 | f306ab537c8e68ae59539c90dca47919 | train_109.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>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.*;
public class A implements Runnable {
public void run() {
long startTime = System.nanoTime();
int tc = nextInt();
while (tc-- > 0) {
int n = nextInt();
int q = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
char[] c = new char[n];
int cur = 0;
for (int i = n; i-- > 0; ) {
if (a[i] <= cur) {
c[i] = '1';
} else {
if (cur < q) {
c[i] = '1';
cur++;
} else {
c[i] = '0';
}
}
}
println(new String(c));
}
if (fileIOMode) {
System.out.println((System.nanoTime() - startTime) / 1e9);
}
out.close();
}
//-----------------------------------------------------------------------------------
private static boolean fileIOMode;
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer tokenizer;
public static void main(String[] args) throws Exception {
fileIOMode = args.length > 0 && args[0].equals("!");
if (fileIOMode) {
in = new BufferedReader(new FileReader("a.in"));
out = new PrintWriter("a.out");
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
tokenizer = new StringTokenizer("");
new Thread(new A()).start();
}
private static String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return null;
}
}
private static String nextToken() {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
private static int nextInt() {
return Integer.parseInt(nextToken());
}
private static long nextLong() {
return Long.parseLong(nextToken());
}
private static double nextDouble() {
return Double.parseDouble(nextToken());
}
private static BigInteger nextBigInteger() {
return new BigInteger(nextToken());
}
private static void print(Object o) {
if (fileIOMode) {
System.out.print(o);
}
out.print(o);
}
private static void println(Object o) {
if (fileIOMode) {
System.out.println(o);
}
out.println(o);
}
private static void printf(String s, Object... o) {
if (fileIOMode) {
System.out.printf(s, o);
}
out.printf(s, o);
}
}
| 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 8 | 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 | 680f372956a4bd289f0714f612bb34dd | train_109.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>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 AACFCC {
// public static long mod = (long) Math.pow(10, 9) + 7;
public static long mod2 = 998244353;
public int oo = 0;
// public static HashMap<Integer, Integer> primenom;
// public static HashMap<Integer, Integer> primeden;
// public static HashMap<Integer, Integer> fin;
public static int zz = -1;
public static long ttt = 0;
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.valueOf(br.readLine());
while (t-- > 0) {
String[] s1 = br.readLine().split(" ");
int n = Integer.valueOf(s1[0]);
int q = Integer.valueOf(s1[1]);
String[] s2 = br.readLine().split(" ");
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.valueOf(s2[i]);
}
int[]aa=new int[n];
int pre=0;
//ArrayList<Integer> list=new ArrayList<>();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
if(q>=arr[i]) {
pre++;
}
aa[i]=pre;
}
int r=n-1,l=0;
int ans=n;
while(l<=r) {
int mid=(l+r)/2;
int p=q;
int oo=1;
for(int i=mid;i<n;i++) {
if(p<=0) {
oo=0;
break;
}
if(arr[i]>p) {
p--;
}
}
if(oo==1) {
ans=mid;
r=mid-1;
}else {
l=mid+1;
}
}
StringBuilder str=new StringBuilder();
for(int i=0;i<ans;i++) {
if(q>=arr[i]) {
str.append(1);
}else {
str.append(0);
}
}
for(int i=ans;i<n;i++) {
str.append(1);
}
pw.println(str.toString());
}
pw.close();
}
private static void putBit(int ind, int val, int[] bit) {
// TODO Auto-generated method stub
for (int i = ind; i < bit.length; i += (i & -i)) {
bit[i] += val;
}
}
private static int getSum(int ind, int[] bit) {
// TODO Auto-generated method stub
int ans = 0;
for (int i = ind; i > 0; i -= (i & -i)) {
ans += bit[i];
}
return ans;
}
}
// private static void putBit(int ind, int val, int[] bit) {
// // TODO Auto-generated method stub
// for (int i = ind; i < bit.length; i += (i & -i)) {
// bit[i] += val;
// }
// }
//
// private static int getSum(int ind, int[] bit) {
// // TODO Auto-generated method stub
// int ans = 0;
// for (int i = ind; i > 0; i -= (i & -i)) {
// ans += bit[i];
// }
// return ans;
// }
// private static void product(long[] bin, int ind, int currIt, long[] power) {
// // TODO Auto-generated method stub
// long pre = 1;
// if (ind > 1) {
// pre = power(power[ind - 1] - 1, mod2 - 1);
// }
// long cc = power[ind] - 1;
// // System.out.println(pre + " " + cc);
// for (int i = ind; i < bin.length; i += (i & (-i))) {
// bin[i] = (bin[i] * pre) % mod2;
// bin[i] = (bin[i] * cc) % mod2;
// }
// }
//
// private static void add(long[] bin, int ind, int val) {
// // TODO Auto-generated method stub
// for (int i = ind; i < bin.length; i += (i & (-i))) {
// bin[i] += val;
// }
// }
//
// private static long sum(long[] bin, int ind) {
// // TODO Auto-generated method stub
// long ans = 0;
// for (int i = ind; i > 0; i -= (i & (-i))) {
// ans += bin[i];
// }
// return ans;
// }
//
// private static long power(long a, long p) {
// TODO Auto-generated method stub
// long res = 1;while(p>0)
// {
// if (p % 2 == 1) {
// res = (res * a) % mod;
// }
// p = p / 2;
// a = (a * a) % mod;
// }return res;
// }}
// private static void getFac(long n, PrintWriter pw) {
// // TODO Auto-generated method stub
// int a = 0;
// while (n % 2 == 0) {
// a++;
// n = n / 2;
// }
// if (n == 1) {
// a--;
// }
// for (int i = 3; i <= Math.sqrt(n); i += 2) {
// while (n % i == 0) {
// n = n / i;
// a++;
// }
// }
// if (n > 1) {
// a++;
// }
// if (a % 2 == 0) {
// pw.println("Bob");
// } else {
// pw.println("Alice");
// }
// //System.out.println(a);
// return;
// }
// private static long power(long a, long p) {
// // TODO Auto-generated method stub
// long res = 1;
// while (p > 0) {
// if (p % 2 == 1) {
// res = (res * a) % mod;
// }
// p = p / 2;
// a = (a * a) % mod;
// }
// return res;
// }
//
// private static void fac() {
// fac[0] = 1;
// // TODO Auto-generated method stub
// for (int i = 1; i < fac.length; i++) {
// if (i == 1) {
// fac[i] = 1;
// } else {
// fac[i] = i * fac[i - 1];
// }
// if (fac[i] > mod) {
// fac[i] = fac[i] % mod;
// }
// }
// }
//
// private static int getLower(Long long1, Long[] st) {
// // TODO Auto-generated method stub
// int left = 0, right = st.length - 1;
// int ans = -1;
// while (left <= right) {
// int mid = (left + right) / 2;
// if (st[mid] <= long1) {
// ans = mid;
// left = mid + 1;
// } else {
// right = mid - 1;
// }
// }
// return ans;
// }
// private static long getGCD(long l, long m) {
//
// long t1 = Math.min(l, m);
// long t2 = Math.max(l, m);
// while (true) {
// long temp = t2 % t1;
// if (temp == 0) {
// return t1;
// }
// t2 = t1;
// t1 = temp;
// }
// }
// private static int kmp(String str) {
// // TODO Auto-generated method stub
// // System.out.println(str);
// int[] pi = new int[str.length()];
// pi[0] = 0;
// for (int i = 1; i < str.length(); i++) {
// int j = pi[i - 1];
// while (j > 0 && str.charAt(i) != str.charAt(j)) {
// j = pi[j - 1];
// }
// if (str.charAt(j) == str.charAt(i)) {
// j++;
// }
// pi[i] = j;
// System.out.print(pi[i]);
// }
// System.out.println();
// return pi[str.length() - 1];
// }
// private static void getFac(long n, PrintWriter pw) {
// // TODO Auto-generated method stub
// int a = 0;
// while (n % 2 == 0) {
// a++;
// n = n / 2;
// }
// if (n == 1) {
// a--;
// }
// for (int i = 3; i <= Math.sqrt(n); i += 2) {
// while (n % i == 0) {
// n = n / i;
// a++;
// }
// }
// if (n > 1) {
// a++;
// }
// if (a % 2 == 0) {
// pw.println("Bob");
// } else {
// pw.println("Alice");
// }
// //System.out.println(a);
// return;
// }
// private static long power(long a, long p) {
// // TODO Auto-generated method stub
// long res = 1;
// while (p > 0) {
// if (p % 2 == 1) {
// res = (res * a) % mod;
// }
// p = p / 2;
// a = (a * a) % mod;
// }
// return res;
// }
//
// private static void fac() {
// fac[0] = 1;
// // TODO Auto-generated method stub
// for (int i = 1; i < fac.length; i++) {
// if (i == 1) {
// fac[i] = 1;
// } else {
// fac[i] = i * fac[i - 1];
// }
// if (fac[i] > mod) {
// fac[i] = fac[i] % mod;
// }
// }
// }
//
// private static int getLower(Long long1, Long[] st) {
// // TODO Auto-generated method stub
// int left = 0, right = st.length - 1;
// int ans = -1;
// while (left <= right) {
// int mid = (left + right) / 2;
// if (st[mid] <= long1) {
// ans = mid;
// left = mid + 1;
// } else {
// right = mid - 1;
// }
// }
// return ans;
// }
// private static long getGCD(long l, long m) {
//
// long t1 = Math.min(l, m);
// long t2 = Math.max(l, m);
// while (true) {
// long temp = t2 % t1;
// if (temp == 0) {
// return t1;
// }
// t2 = t1;
// t1 = temp;
// }
// } | Java | ["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 8 | 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 | 7c7b9c0d65ad9fb69b03be19eb6d78f5 | train_109.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>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 {
static FastReader sc;
static void solve() {
StringBuilder res = new StringBuilder();
int n = sc.nextInt();
int q = sc.nextInt();
int[] arr = sc.readIntArray(n);
int c = 0;
for (int i = n - 1; i >= 0; i--) {
if (arr[i] <= c || (c == 0 && arr[i] <= c + 1)) {
res.append('1');
if (c == 0)
c = 1;
} else if (c < q) {
res.append('1');
c++;
} else {
res.append('0');
}
}
res.reverse();
print(res);
}
public static void main(String[] args) throws IOException {
sc = new FastReader();
int tt = sc.nextInt();
while (tt-- > 0) {
solve();
}
}
static <E> void debug(E a) {
System.err.println(a);
}
static void debug(int... a) {
System.err.println(Arrays.toString(a));
}
static int maxOf(int... array) {
return Arrays.stream(array).max().getAsInt();
}
static int minOf(int... array) {
return Arrays.stream(array).parallel().reduce(Math::min).getAsInt();
}
static <E> void print(E res) {
System.out.println(res);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readIntArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++)
res[i] = nextInt();
return res;
}
long[] readLongArray(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++)
res[i] = nextLong();
return res;
}
}
}
| Java | ["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 8 | 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 | f404ef33dfc86dc88462ac866de9ac96 | train_109.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>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 org.graalvm.compiler.core.common.Fields.ObjectTransformer;
import java.math.*;
import java.math.BigInteger;
public final class A
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
// static int g[][];
static ArrayList<Integer> g[];
static long mod=(long)1e9+7,INF=Long.MAX_VALUE;
static boolean set[];
static int max=0;
static int lca[][];
static int par[],col[],D[];
static long fact[];
static int size[],dp[][],countW[],countB[],N;
static long sum[][],f[];
static long t[],max_depth[];
static boolean sep[],isWhite[];
static boolean marked[],visited[],recStack[];
static int segR[],segC[],seg[];
static HashMap<Long,Integer> mp[];
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
int T=i();
outer:while(T-->0)
{
int N=i();
long Q=l();
long A[]=inputLong(N);
if(Q>=N)
{
for(int i=1; i<=N; i++)ans.append("1");
ans.append("\n");
}
else
{
int f[]=new int[N];
int l=-1,r=N;
while(r-l>1)
{
int m=(l+r)/2;
long q=Q;
for(int i=m; i<N; i++)
{
if(A[i]>q)q--;
}
// System.out.println("for--> "+m+ " "+q);
if(q>=0)
{
r=m;
}
else
{
l=m;
}
}
// System.out.println(l+" "+r);
for(int i=0; i<r; i++)if(A[i]<=Q)f[i]=1;
for(int i=r; i<N; i++)f[i]=1;
for(int i=1; i<=N; i++)ans.append(f[i-1]+"");
ans.append("\n");
}
}
out.println(ans);
out.close();
}
static boolean equals(char X[],char Y[])
{
for(int i=0; i<X.length; i++)if(X[i]!=Y[i])return false;
return true;
}
static long nCr(long n,long r)
{
long s=0;
long c=n-r;
n=fact[(int)n];
r=fact[(int)r];
c=fact[(int)c];
r=pow(r,mod-2)%mod;
c=pow(c,mod-2)%mod;
s=(r*c)%mod;
s=(s*n)%mod;
return s%mod;
}
static boolean isValid(int x,int y,int N,int M)
{
if(x>=N || y>=M)return false;
if(x<0 || y<0)return false;
return true;
}
static int f2(int n,int p)
{
ArrayList<Integer> X=new ArrayList<>();
for(int c:g[n])
{
if(c!=p)
{
X.add(c);
}
}
// System.out.println("for--> "+n+" "+X);
if(X.size()==0)return 0;
if(X.size()==1)return size[n]-1;
int a=X.get(0),b=X.get(1);
// System.out.println("n--> "+n+" "+(size[a]+f2(b,n))+" "+(size[b]+f2(a,n)));
return Math.max(size[a]+f2(b,n), size[b]+f2(a,n));
// return 0;
}
static void f(int n,int p)
{
for(int c:g[n])
{
if(c!=p)
{
f(c,n);
size[n]+=size[c]+1;
}
}
// size[n]++;
}
static boolean isPower(long a,long b)
{
while(a%b==0)
{
}
return a==1;
}
static String rotate(String X,int K)
{
StringBuilder sb=new StringBuilder();
int N=X.length();
int k=K%N;
for(int i=N-k; i<N;i++)
{
sb.append(X.charAt(i));
}
for(int i=0; i<N-k; i++)
{
sb.append(X.charAt(i));
}
return sb.toString();
}
static int rounds(String X,String Y)
{
int n=Y.length();
for(int i=1; i<Y.length(); i++)
{
if(X.charAt(0)==Y.charAt(0) && X.substring(i,i+n).equals(Y))return i;
}
return Y.length();
}
static int index(ArrayList<Long> X,long x)
{
int l=-1,r=X.size();
while(r-l>1)
{
int m=(l+r)/2;
if(X.get(m)<=x)l=m;
else r=m;
}
return l+1;
}
static void swap(int i,int j,long A[][])
{
for(int row=0; row<A.length; row++)
{
long t=A[row][i];
A[row][i]=A[row][j];
A[row][j]=t;
}
}
static boolean isSorted(long A[])
{
for(int i=1; i<A.length; i++)if(A[i]<A[i-1])return false;
return true;
}
static void dfs(int node, int dp[],
boolean visited[],long A[],long a)
{
// Mark as visited
visited[node] = true;
// Traverse for all its children
for (int c:g[node])
{
// If not visited
if (A[c-1]<=a && !visited[c])
dfs(c, dp, visited,A,a);
// Store the max of the paths
dp[node] = Math.max(dp[node], 1 + dp[c]);
}
}
static int findLongestPath( int n,long A[],long a)
{
// Dp array
int[] dp = new int[n+1];
// Visited array to know if the node
// has been visited previously or not
boolean[] visited = new boolean[n + 1];
// Call DFS for every unvisited vertex
for (int i = 1; i <= n; i++)
{
if (A[i-1]<=a && !visited[i])
dfs(i, dp, visited,A,a);
}
int ans = 0;
// Traverse and find the maximum of all dp[i]
for (int i = 1; i <= n; i++)
{
ans = Math.max(ans, dp[i]);
}
return ans;
}
static boolean isCyclicUtil(int n, boolean[] visited,
boolean[] recStack,long A[],long a)
{
if (recStack[n])
return true;
if (visited[n])
return false;
visited[n] = true;
recStack[n] = true;
for (int c: g[n])
{
if(A[c-1]<=a )
{
if (isCyclicUtil(c, visited, recStack,A,a))
return true;
}
}
recStack[n] = false;
return false;
}
static void push(int v) {
if (marked[v]) {
t[v*2] = t[v*2+1] = t[v];
marked[v*2] = marked[v*2+1] = true;
marked[v] = false;
}
}
static void update1(int v, int tl, int tr, int l, int r, int new_val) {
if (l > r)
return;
if (l == tl && tr == r) {
t[v] = new_val;
marked[v] = true;
} else {
push(v);
int tm = (tl + tr) / 2;
update1(v*2, tl, tm, l, Math.min(r, tm), new_val);
update1(v*2+1, tm+1, tr, Math.max(l, tm+1), r, new_val);
}
}
static long get1(int v, int tl, int tr, int pos) {
if (tl == tr) {
return t[v];
}
push(v);
int tm = (tl + tr) / 2;
if (pos <= tm)
return get1(v*2, tl, tm, pos);
else
return get1(v*2+1, tm+1, tr, pos);
}
static int cost=0;
static void fmin(int i,int j,ArrayList<Integer> A,int cZ,int cO)
{
if(j-i>1)
{
int a=A.get(i),b=A.get(j);
cO+=Math.min(a, b);
if(a<b)
{
}
else if(b>a)
{
}
else
{
}
}
}
static void fs(int n,int p)
{
if(isWhite[n])countW[n]=1;
else countB[n]=1;
for(int c:g[n])
{
if(c!=p)
{
fs(c,n);
countB[n]+=countB[c];
countW[n]+=countW[c];
}
}
}
static int f(char X[],char Y[])
{
int s=0;
for(int i=0; i<Y.length; i++)
{
s+=Math.abs(X[i]-Y[i]);
}
return s;
}
public static long mergeSort(int A[],int l,int r)
{
long a=0;
if(l<r)
{
int m=(l+r)/2;
a+=mergeSort(A,l,m);
a+=mergeSort(A,m+1,r);
a+=merge(A,l,m,r);
}
return a;
}
public static long merge(int A[],int l,int m,int r)
{
long a=0;
int i=l,j=m+1,index=0;
long c=0;
int B[]=new int[r-l+1];
while(i<=m && j<=r)
{
if(A[i]<=A[j])
{
c++;
B[index++]=A[i++];
}
else
{
long s=(m-l)+1;
a+=(s-c);
B[index++]=A[j++];
}
}
while(i<=m)B[index++]=A[i++];
while(j<=r)B[index++]=A[j++];
index=0;
for(; l<=r; l++)A[l]=B[index++];
return a;
}
static int f(int A[])
{
int s=0;
for(int i=1; i<4; i++)
{
s+=Math.abs(A[i]-A[i-1]);
}
return s;
}
static boolean f(int A[],int B[],int N)
{
for(int i=0; i<N; i++)
{
if(Math.abs(A[i]-B[i])>1)return false;
}
return true;
}
static int [] prefix(char s[],int N) {
// int n = (int)s.length();
// vector<int> pi(n);
N=s.length;
int pi[]=new int[N];
for (int i = 1; i < N; i++) {
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
static int count(long N)
{
int cnt=0;
long p=1L;
while(p<=N)
{
if((p&N)!=0)cnt++;
p<<=1;
}
return cnt;
}
static long kadane(long A[])
{
long lsum=A[0],gsum=0;
gsum=Math.max(gsum, lsum);
for(int i=1; i<A.length; i++)
{
lsum=Math.max(lsum+A[i],A[i]);
gsum=Math.max(gsum,lsum);
}
return gsum;
}
public static void reverse(int i,int j,int A[])
{
while(i<j)
{
int t=A[i];
A[i]=A[j];
A[j]=t;
i++;
j--;
}
}
public static int ask(int a,int b,int c)
{
System.out.println("? "+a+" "+b+" "+c);
return i();
}
static int[] reverse(int A[],int N)
{
int B[]=new int[N];
for(int i=N-1; i>=0; i--)
{
B[N-i-1]=A[i];
}
return B;
}
static boolean isPalin(char X[])
{
int i=0,j=X.length-1;
while(i<=j)
{
if(X[i]!=X[j])return false;
i++;
j--;
}
return true;
}
static int distance(int a,int b)
{
int d=D[a]+D[b];
int l=LCA(a,b);
l=2*D[l];
return d-l;
}
static int LCA(int a,int b)
{
if(D[a]<D[b])
{
int t=a;
a=b;
b=t;
}
int d=D[a]-D[b];
int p=1;
for(int i=0; i>=0 && p<=d; i++)
{
if((p&d)!=0)
{
a=lca[a][i];
}
p<<=1;
}
if(a==b)return a;
for(int i=max-1; i>=0; i--)
{
if(lca[a][i]!=-1 && lca[a][i]!=lca[b][i])
{
a=lca[a][i];
b=lca[b][i];
}
}
return lca[a][0];
}
static void dfs(int n,int p)
{
lca[n][0]=p;
if(p!=-1)D[n]=D[p]+1;
for(int c:g[n])
{
if(c!=p)
{
dfs(c,n);
}
}
}
static int[] prefix_function(char X[])//returns pi(i) array
{
int N=X.length;
int pre[]=new int[N];
for(int i=1; i<N; i++)
{
int j=pre[i-1];
while(j>0 && X[i]!=X[j])
j=pre[j-1];
if(X[i]==X[j])j++;
pre[i]=j;
}
return pre;
}
static TreeNode start;
public static void f(TreeNode root,TreeNode p,int r)
{
if(root==null)return;
if(p!=null)
{
root.par=p;
}
if(root.val==r)start=root;
f(root.left,root,r);
f(root.right,root,r);
}
static int right(int A[],int Limit,int l,int r)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<Limit)l=m;
else r=m;
}
return l;
}
static int left(int A[],int a,int l,int r)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<a)l=m;
else r=m;
}
return l;
}
// static void build(int v,int tl,int tr,long A[])
// {
// if(tl==tr)
// {
// long a=0;
// if(A[tl]>0)
// {
// a=A[tl];
//
// }
// seg[v]=new node(a,a,a,A[tl],A[tl]);
// return;
// }
// int tm=(tl+tr)/2;
// build(v*2,tl,tm,A);
// build(v*2+1,tm+1,tr,A);
// seg[v]=combine(seg[v*2],seg[v*2+1]);
// }
// static node combine(node a,node b)
// {
// node temp=new node(0,0,0,0);
// temp.pref=max(a.pref,a.sum+b.pref,a.sum+b.sum);
// temp.suff=max(b.suff,b.sum+a.suff,b.sum+a.sum);
// temp.max=max(a.max,b.max,a.suff+b.pref);
// temp.sum=a.sum+b.sum;
// temp.min=Math.max(a.min, b.min);
// return temp;
// }
// static long max(long a,long b,long c)
// {
// return Math.max(a,Math.max(b, c));
// }
// // static void update(int v,int tl,int tr,int index)
// // {
// // if(index==tl && index==tr)
// // {
// // segR[v]+=1;
// // segR[v]%=2;
// // }
// // else
// // {
// // int tm=(tl+tr)/2;
// // if(index<=tm)update(v*2,tl,tm,index);
// // else update(v*2+1,tm+1,tr,index);
// // segR[v]=segR[v*2]+segR[v*2+1];
// // }
// // }
// static long ask(int v,int tl,int tr,int l,int r)
// {
//
// if(l>r)return 0;
// if(tl==l && r==tr)
// {
// return seg[v].max;
// }
// int tm=(tl+tr)/2;
//
// return Math.max(ask(v*2,tl,tm,l,Math.min(tm, r)),ask(v*2+1,tm+1,tr,Math.max(tm+1, l),r));
// }
static void build(int v,int tl,int tr,int A[])
{
if(tl==tr)
{
seg[v]=A[tl];
return;
}
int tm=(tl+tr)/2;
build(v*2,tl,tm,A);
build(v*2+1,tm+1,tr,A);
seg[v]=seg[v*2]+seg[v*2+1];
}
static void update(int v,int tl,int tr,int index,int a)
{
if(index==tl && tl==tr)
{
seg[v]++;
seg[v]%=2;
}
else
{
int tm=(tl+tr)/2;
if(index<=tm)update(2*v,tl,tm,index,a);
else update(2*v+1,tm+1,tr,index,a);
seg[v]=seg[v*2]+seg[v*2+1];
}
}
static int ask(int v,int tl,int tr,int k)
{
if(tl==tr)return tl;
int tm=(tl+tr)/2;
if(seg[v*2]>=k)
{
return ask(v*2,tl,tm,k);
}
return ask(v*2+1,tm+1,tr,k-seg[v*2]);
}
static int ask(int v,int tl,int tr,int l,int r)
{
if(l>r)return 0;
if(tl==l && tr==r)return seg[v];
int tm=(tl+tr)/2;
return ask(v*2,tl,tm,l,Math.min(tm,r))+ask(v*2+1,tm+1,tr,Math.max(l, tm+1),r);
}
static void updateC(int v,int tl,int tr,int index)
{
if(index==tl && index==tr)
{
segC[v]+=1;
segC[v]%=2;
}
else
{
int tm=(tl+tr)/2;
if(index<=tm)updateC(v*2,tl,tm,index);
else updateC(v*2+1,tm+1,tr,index);
segC[v]=segC[v*2]+segC[v*2+1];
}
}
static int askC(int v,int tl,int tr,int l,int r)
{
if(l>r)return 0;
if(tl==l && r==tr)
{
return segC[v];
}
int tm=(tl+tr)/2;
return askC(v*2,tl,tm,l,Math.min(tm, r))+askC(v*2+1,tm+1,tr,Math.max(tm+1, l),r);
}
static boolean f(long A[],long m,int N)
{
long B[]=new long[N];
for(int i=0; i<N; i++)
{
B[i]=A[i];
}
for(int i=N-1; i>=0; i--)
{
if(B[i]<m)return false;
if(i>=2)
{
long extra=Math.min(B[i]-m, A[i]);
long x=extra/3L;
B[i-2]+=2L*x;
B[i-1]+=x;
}
}
return true;
}
static int f(int l,int r,long A[],long x)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]>=x)l=m;
else r=m;
}
return r;
}
static boolean f(long m,long H,long A[],int N)
{
long s=m;
for(int i=0; i<N-1;i++)
{
s+=Math.min(m, A[i+1]-A[i]);
}
return s>=H;
}
static long ask(long l,long r)
{
System.out.println("? "+l+" "+r);
return l();
}
static long f(long N,long M)
{
long s=0;
if(N%3==0)
{
N/=3;
s=N*M;
}
else
{
long b=N%3;
N/=3;
N++;
s=N*M;
N--;
long a=N*M;
if(M%3==0)
{
M/=3;
a+=(b*M);
}
else
{
M/=3;
M++;
a+=(b*M);
}
s=Math.min(s, a);
}
return s;
}
static int ask(StringBuilder sb,int a)
{
System.out.println(sb+""+a);
return i();
}
static void swap(char X[],int i,int j)
{
char x=X[i];
X[i]=X[j];
X[j]=x;
}
static int min(int a,int b,int c)
{
return Math.min(Math.min(a, b), c);
}
static long and(int i,int j)
{
System.out.println("and "+i+" "+j);
return l();
}
static long or(int i,int j)
{
System.out.println("or "+i+" "+j);
return l();
}
static int len=0,number=0;
static void f(char X[],int i,int num,int l)
{
if(i==X.length)
{
if(num==0)return;
//update our num
if(isPrime(num))return;
if(l<len)
{
len=l;
number=num;
}
return;
}
int a=X[i]-'0';
f(X,i+1,num*10+a,l+1);
f(X,i+1,num,l);
}
static boolean is_Sorted(int A[])
{
int N=A.length;
for(int i=1; i<=N; i++)if(A[i-1]!=i)return false;
return true;
}
static boolean f(StringBuilder sb,String Y,String order)
{
StringBuilder res=new StringBuilder(sb.toString());
HashSet<Character> set=new HashSet<>();
for(char ch:order.toCharArray())
{
set.add(ch);
for(int i=0; i<sb.length(); i++)
{
char x=sb.charAt(i);
if(set.contains(x))continue;
res.append(x);
}
}
String str=res.toString();
return str.equals(Y);
}
static boolean all_Zero(int f[])
{
for(int a:f)if(a!=0)return false;
return true;
}
static long form(int a,int l)
{
long x=0;
while(l-->0)
{
x*=10;
x+=a;
}
return x;
}
static int count(String X)
{
HashSet<Integer> set=new HashSet<>();
for(char x:X.toCharArray())set.add(x-'0');
return set.size();
}
static int f(long K)
{
long l=0,r=K;
while(r-l>1)
{
long m=(l+r)/2;
if(m*m<K)l=m;
else r=m;
}
return (int)l;
}
static int [] sub(int A[],int B[])
{
int N=A.length;
int f[]=new int[N];
for(int i=N-1; i>=0; i--)
{
if(B[i]<A[i])
{
B[i]+=26;
B[i-1]-=1;
}
f[i]=B[i]-A[i];
}
for(int i=0; i<N; i++)
{
if(f[i]%2!=0)f[i+1]+=26;
f[i]/=2;
}
return f;
}
static int[] f(int N)
{
char X[]=in.next().toCharArray();
int A[]=new int[N];
for(int i=0; i<N; i++)A[i]=X[i]-'a';
return A;
}
static int max(int a ,int b,int c,int d)
{
a=Math.max(a, b);
c=Math.max(c,d);
return Math.max(a, c);
}
static int min(int a ,int b,int c,int d)
{
a=Math.min(a, b);
c=Math.min(c,d);
return Math.min(a, c);
}
static HashMap<Integer,Integer> Hash(int A[])
{
HashMap<Integer,Integer> mp=new HashMap<>();
for(int a:A)
{
int f=mp.getOrDefault(a,0)+1;
mp.put(a, f);
}
return mp;
}
static long mul(long a, long b)
{
return ( a %mod * 1L * b%mod )%mod;
}
static void swap(int A[],int a,int b)
{
int t=A[a];
A[a]=A[b];
A[b]=t;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
{
if(par[a]>par[b]) //this means size of a is less than that of b
{
int t=b;
b=a;
a=t;
}
par[a]+=par[b];
par[b]=a;
}
}
static boolean isSorted(int A[])
{
for(int i=1; i<A.length; i++)
{
if(A[i]<A[i-1])return false;
}
return true;
}
static boolean isDivisible(StringBuilder X,int i,long num)
{
long r=0;
for(; i<X.length(); i++)
{
r=r*10+(X.charAt(i)-'0');
r=r%num;
}
return r==0;
}
static int lower_Bound(int A[],int low,int high, int x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static String f(String A)
{
String X="";
for(int i=A.length()-1; i>=0; i--)
{
int c=A.charAt(i)-'0';
X+=(c+1)%2;
}
return X;
}
static void sortR(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
int N=a.length;
for (int i=0; i<a.length; i++) a[i]=l.get(N-i-1);
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static String swap(String X,int i,int j)
{
char ch[]=X.toCharArray();
char a=ch[i];
ch[i]=ch[j];
ch[j]=a;
return new String(ch);
}
static int sD(long n)
{
if (n % 2 == 0 )
return 2;
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0 )
return i;
}
return (int)n;
}
// static void setGraph(int N,int nodes)
// {
//// size=new int[N+1];
// par=new int[N+1];
// col=new int[N+1];
//// g=new int[N+1][];
// D=new int[N+1];
// int deg[]=new int[N+1];
// int A[][]=new int[nodes][2];
// for(int i=0; i<nodes; i++)
// {
// int a=i(),b=i();
// A[i][0]=a;
// A[i][1]=b;
// deg[a]++;
// deg[b]++;
// }
// for(int i=0; i<=N; i++)
// {
// g[i]=new int[deg[i]];
// deg[i]=0;
// }
// for(int a[]:A)
// {
// int x=a[0],y=a[1];
// g[x][deg[x]++]=y;
// g[y][deg[y]++]=x;
// }
// }
static long pow(long a,long b)
{
//long mod=1000000007;
long pow=1;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}
static long toggleBits(long x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;
return ((1<<n)-1)^x;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static long fact(long N)
{
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(boolean A[][])
{
for(boolean a[]:A)print(a);
}
static void print(long A[][])
{
for(long a[]:A)print(a);
}
static void print(int A[][])
{
for(int a[]:A)print(a);
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
static long GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
}
class node
{
long pref,suff,max,sum,min;
node(long a,long b,long c,long d)
{
pref=a;
suff=b;
max=c;
sum=d;
min=Long.MIN_VALUE;
}
node(long a,long b,long c,long d,long e)
{
pref=a;
suff=b;
max=c;
sum=d;
min=e;
}
}
class project implements Comparable<project>
{
int score,index;
project(int s,int i)
{
// roles=r;
index=i;
score=s;
// skill=new String[r];
// lvl=new int[r];
}
public int compareTo(project x)
{
return x.score-this.score;
}
}
class post implements Comparable<post>
{
long x,y,d,t;
post(long a,long b,long c)
{
x=a;
y=b;
d=c;
}
public int compareTo(post X)
{
if(X.t==this.t)
{
return 0;
}
else
{
long xt=this.t-X.t;
if(xt>0)return 1;
return -1;
}
}
}
class TreeNode
{
int val;
TreeNode left, right,par;
TreeNode() {}
TreeNode(int item)
{
val = item;
left =null;
right = null;
par=null;
}
}
class pair implements Comparable<pair>
{
int l,r,index;
pair(int a,int b,int i)
{
l=a;
r=b;
index=i;
}
public int compareTo(pair x)
{
if(this.r==x.r)return this.l-x.l;
return this.r-x.r;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
//
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["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 8 | 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 | 07f6e7878a783df3bad495663f1cad56 | train_109.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>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 Doremys_IQ {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
for(int i=1;i<=t;i++) {
int n=in.nextInt();
int iq=in.nextInt();
int a[]=new int[n];
for(int j=0;j<n;j++) {
a[j]=in.nextInt();
}
int q=0;
for(int k=n-1;k>=0;k--) {
if(q<iq) {
if(a[k]>q) {
a[k]=1;
q++;
}
else a[k]=1;
}
else {
if(a[k]<=iq) a[k]=1;
else a[k]=0;
}
}
for(int l=0;l<n;l++) {
System.out.print(a[l]);
}
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 17 | 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 | 5627257591e707be9d5849326745dcbe | train_109.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>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 {
Input in;
PrintWriter out;
public C() {
in = new Input(System.in);
out = new PrintWriter(System.out);
}
public static void main(String[] args) {
C solution = new C();
for (int t = solution.in.nextInt(); t > 0; t--) {
solution.solve();
}
solution.out.close();
}
void solve() {
int n = in.nextInt();
int q = in.nextInt();
int[] a = in.nextIntArray(n);
char[] ans = new char[n];
int iq = 0;
for (int i=n-1; i>=0; i--) {
ans[i] = '0';
if (iq < q) {
ans[i] = '1';
if (a[i] > iq) iq++;
} else if (a[i] <= q) {
ans[i] = '1';
}
}
out.println(new String(ans));
}
static class Input {
BufferedReader br;
StringTokenizer st;
public Input(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
String nextString() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextString());
}
long nextLong() {
return Long.parseLong(nextString());
}
int[] nextIntArray(int size) {
int[] ans = new int[size];
for (int i = 0; i < size; i++) {
ans[i] = nextInt();
}
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 17 | 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 | 7b8fb04fa8943b2116307be3f32ee467 | train_109.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>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 | /*----------- ---------------*
Author : Ryan Ranaut
__Hope is a big word, never lose it__
------------- --------------*/
import java.io.*;
import java.util.*;
public class Codeforces1 {
static PrintWriter out = new PrintWriter(System.out);
static final int mod = 1_000_000_007;
static long min = (long) (-1e16);
static final int max = (int)1e6;
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());
}
int[] readIntArray(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());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
/*--------------------------------------------------------------------------*/
//Try seeing general case
//Minimization Maximization - BS..... Connections - Graphs.....
//Greedy not worthy - Try DP
//Think edge cases
public static void main(String[] args)
{
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0)
{
int n = s.nextInt();
int q0 = s.nextInt();
long[] a = s.readLongArray(n);
out.println(find(n, q0, a));
}
out.close();
}
public static char[] find(int n, int q0, long[] a)
{
List<Integer> bad = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(a[i] > q0)
bad.add(i);
}
int low = 0, high = bad.size()-1;
int ind = n;
while(low <= high)
{
int mid = low + (high - low)/2;
if(find(bad, a, q0, mid))
{
ind = bad.get(mid);
high = mid-1;
}
else
low = mid+1;
}
char[] res = new char[n];
for(int i=0;i<n;i++)
res[i] = i<ind ? (a[i] <= q0 ? '1' : '0') : '1';
return res;
}
public static boolean find(List<Integer> bad, long[] a, int q, int mid)
{
int n = a.length;
for(int i=bad.get(mid); i<n; i++)
{
if(q == 0)
return false;
if(a[i] <= q)
continue;
q--;
}
return true;
}
/*----------------------------------End of the road--------------------------------------*/
static class DSU {
int[] parent;
int[] ranks;
int[] groupSize;
int size;
public DSU(int n) {
size = n;
parent = new int[n];//0 based
ranks = new int[n];
groupSize = new int[n];//Size of each component
for (int i = 0; i < n; i++) {
parent[i] = i;
ranks[i] = 1;
groupSize[i] = 1;
}
}
public int find(int x)//Path Compression
{
if (parent[x] == x)
return x;
else
return parent[x] = find(parent[x]);
}
public void union(int x, int y)//Union by rank
{
int x_rep = find(x);
int y_rep = find(y);
if (x_rep == y_rep)
return;
if (ranks[x_rep] < ranks[y_rep]) {
parent[x_rep] = y_rep;
groupSize[y_rep] += groupSize[x_rep];
} else if (ranks[x_rep] > ranks[y_rep]) {
parent[y_rep] = x_rep;
groupSize[x_rep] += groupSize[y_rep];
} else {
parent[y_rep] = x_rep;
ranks[x_rep]++;
groupSize[x_rep] += groupSize[y_rep];
}
size--;//Total connected components
}
}
public static int gcd(int x, int y) {
return y == 0 ? x : gcd(y, x % y);
}
public static long gcd(long x, long y) {
return y == 0L ? x : gcd(y, x % y);
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static long pow(long a, long b) {
if (b == 0L)
return 1L;
long tmp = 1;
while (b > 1L) {
if ((b & 1L) == 1)
tmp *= a;
a *= a;
b >>= 1;
}
return (tmp * a);
}
public static long modPow(long a, long b, long mod) {
if (b == 0L)
return 1L;
long tmp = 1;
while (b > 1L) {
if ((b & 1L) == 1L)
tmp *= a;
a *= a;
a %= mod;
tmp %= mod;
b >>= 1;
}
return (tmp * a) % mod;
}
static long mul(long a, long b) {
return a * b;
}
static long fact(int n) {
long ans = 1;
for (int i = 2; i <= n; i++) ans = mul(ans, i);
return ans;
}
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 void debug(int... a) {
for (int x : a)
out.print(x + " ");
out.println();
}
static void debug(long... a) {
for (long x : a)
out.print(x + " ");
out.println();
}
static void debugMatrix(int[][] a) {
for (int[] x : a)
out.println(Arrays.toString(x));
}
static void debugMatrix(long[][] a) {
for (long[] x : a)
out.println(Arrays.toString(x));
}
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];
}
static void sort(int[] a) {
ArrayList<Integer> ls = new ArrayList<>();
for (int x : a) ls.add(x);
Collections.sort(ls);
for (int i = 0; i < a.length; i++)
a[i] = ls.get(i);
}
static void sort(long[] a) {
ArrayList<Long> ls = new ArrayList<>();
for (long x : a) ls.add(x);
Collections.sort(ls);
for (int i = 0; i < a.length; i++)
a[i] = ls.get(i);
}
static class Pair {
long x, y;
Pair(long x, long y) {
this.x = x;
this.y = y;
}
}
} | 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 17 | 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 | c20aa5a225094dec531b92860ad687ef | train_109.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>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 | /*----------- ---------------*
Author : Ryan Ranaut
__Hope is a big word, never lose it__
------------- --------------*/
import java.io.*;
import java.util.*;
public class Codeforces1 {
static PrintWriter out = new PrintWriter(System.out);
static final int mod = 1_000_000_007;
static long min = (long) (-1e16);
static final int max = (int)1e6;
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());
}
int[] readIntArray(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());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
/*--------------------------------------------------------------------------*/
//Try seeing general case
//Minimization Maximization - BS..... Connections - Graphs.....
//Greedy not worthy - Try DP
//Think edge cases
public static void main(String[] args)
{
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0)
{
int n = s.nextInt();
int q0 = s.nextInt();
long[] a = s.readLongArray(n);
out.println(find(n, q0, a));
}
out.close();
}
public static char[] find(int n, int q0, long[] a)
{
char[] res = new char[n];
int q = 0;
for(int i=n-1;i>=0;i--)
{
if(a[i] <= q)
res[i] = '1';
else
{
if(q < q0){//initial state
res[i] = '1';
q++;
}
else
res[i] = '0';
}
}
return res;
}
/*----------------------------------End of the road--------------------------------------*/
static class DSU {
int[] parent;
int[] ranks;
int[] groupSize;
int size;
public DSU(int n) {
size = n;
parent = new int[n];//0 based
ranks = new int[n];
groupSize = new int[n];//Size of each component
for (int i = 0; i < n; i++) {
parent[i] = i;
ranks[i] = 1;
groupSize[i] = 1;
}
}
public int find(int x)//Path Compression
{
if (parent[x] == x)
return x;
else
return parent[x] = find(parent[x]);
}
public void union(int x, int y)//Union by rank
{
int x_rep = find(x);
int y_rep = find(y);
if (x_rep == y_rep)
return;
if (ranks[x_rep] < ranks[y_rep]) {
parent[x_rep] = y_rep;
groupSize[y_rep] += groupSize[x_rep];
} else if (ranks[x_rep] > ranks[y_rep]) {
parent[y_rep] = x_rep;
groupSize[x_rep] += groupSize[y_rep];
} else {
parent[y_rep] = x_rep;
ranks[x_rep]++;
groupSize[x_rep] += groupSize[y_rep];
}
size--;//Total connected components
}
}
public static int gcd(int x, int y) {
return y == 0 ? x : gcd(y, x % y);
}
public static long gcd(long x, long y) {
return y == 0L ? x : gcd(y, x % y);
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static long pow(long a, long b) {
if (b == 0L)
return 1L;
long tmp = 1;
while (b > 1L) {
if ((b & 1L) == 1)
tmp *= a;
a *= a;
b >>= 1;
}
return (tmp * a);
}
public static long modPow(long a, long b, long mod) {
if (b == 0L)
return 1L;
long tmp = 1;
while (b > 1L) {
if ((b & 1L) == 1L)
tmp *= a;
a *= a;
a %= mod;
tmp %= mod;
b >>= 1;
}
return (tmp * a) % mod;
}
static long mul(long a, long b) {
return a * b;
}
static long fact(int n) {
long ans = 1;
for (int i = 2; i <= n; i++) ans = mul(ans, i);
return ans;
}
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 void debug(int... a) {
for (int x : a)
out.print(x + " ");
out.println();
}
static void debug(long... a) {
for (long x : a)
out.print(x + " ");
out.println();
}
static void debugMatrix(int[][] a) {
for (int[] x : a)
out.println(Arrays.toString(x));
}
static void debugMatrix(long[][] a) {
for (long[] x : a)
out.println(Arrays.toString(x));
}
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];
}
static void sort(int[] a) {
ArrayList<Integer> ls = new ArrayList<>();
for (int x : a) ls.add(x);
Collections.sort(ls);
for (int i = 0; i < a.length; i++)
a[i] = ls.get(i);
}
static void sort(long[] a) {
ArrayList<Long> ls = new ArrayList<>();
for (long x : a) ls.add(x);
Collections.sort(ls);
for (int i = 0; i < a.length; i++)
a[i] = ls.get(i);
}
static class Pair {
long x, y;
Pair(long x, long y) {
this.x = x;
this.y = y;
}
}
} | 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 17 | 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 | eaafd5fa82de6a010031046266d4a984 | train_109.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>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.lang.*;
public class Main {
static PrintWriter out=new PrintWriter(System.out);
static void testCase(FastScanner sc) {
long mod1=(long)1e9+7, mod2=998244353;
long inf=(long)1e18+5;
int n=sc.nextInt(), q=sc.nextInt();
int[] a=new int[n];
ArrayList<Integer> b=new ArrayList<>();
for(int i=0;i<=n-1;i++) {
a[i]=sc.nextInt();
if(a[i]>q) {
b.add(i);
}
}
char[] s=new char[n];
for(int i=0;i<=n-1;i++) {
s[i]=(a[i]<=q ? '1' : '0');
}
int l=0, r=b.size()-1;
while(l<=r) {
int mid=(l+r)>>1;
int cur=q;
boolean e=true;
for(int i=b.get(mid);i<=n-1;i++) {
if(cur==0) {
e=false;
}
cur-=(a[i]>cur ? 1 : 0);
}
if(e) {
for(int i=0;i<=b.get(mid)-1;i++) {
s[i]=(a[i]<=q ? '1' : '0');
}
for(int i=b.get(mid);i<=n-1;i++) {
s[i]='1';
}
r=mid-1;
} else {
l=mid+1;
}
}
out.println(s);
}
public static void main(String[] args) {
FastScanner sc=new FastScanner();
boolean test=true;
int t=1;
if(test) {
t=sc.nextInt();
}
for(int i=0;i<=t-1;i++) {
// out.print("Case #"+(i+1)+": ");
testCase(sc);
}
out.close();
}
static void ruffleSort(int[] a) {
Random rnd=new Random();
for(int i=0;i<=a.length-1;i++) {
int temp=a[i];
int rndPos=i+rnd.nextInt(a.length-i);
a[i]=a[rndPos];
a[rndPos]=temp;
}
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() {
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();
}
String nextLine() {
String str="";
try {
str=br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
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 17 | 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 | 4d9f1da4dd8e6396c9402a2faf28205c | train_109.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>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.lang.*;
public class Main {
static PrintWriter out=new PrintWriter(System.out);
static void testCase(FastScanner sc) {
long mod1=(long)1e9+7, mod2=998244353;
long inf=(long)1e18+5;
int n=sc.nextInt(), q=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<=n-1;i++) {
a[i]=sc.nextInt();
}
char[] s=new char[n];
int cur=0;
for(int i=n-1;i>=0;i--) {
if(cur>=a[i] || cur<q) {
s[i]='1';
cur+=(cur<a[i] ? 1 : 0);
} else {
s[i]='0';
}
}
out.println(s);
}
public static void main(String[] args) {
FastScanner sc=new FastScanner();
boolean test=true;
int t=1;
if(test) {
t=sc.nextInt();
}
for(int i=0;i<=t-1;i++) {
// out.print("Case #"+(i+1)+": ");
testCase(sc);
}
out.close();
}
static void ruffleSort(int[] a) {
Random rnd=new Random();
for(int i=0;i<=a.length-1;i++) {
int temp=a[i];
int rndPos=i+rnd.nextInt(a.length-i);
a[i]=a[rndPos];
a[rndPos]=temp;
}
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() {
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();
}
String nextLine() {
String str="";
try {
str=br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
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 17 | 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 | e91b49d7736384798caa9be92ff66ad4 | train_109.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>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 {
static boolean isValid(int[] a, String s, int q){
int n = a.length;
for(int i=0;i<n;i++){
if(s.charAt(i) == '1'){
if(q <= 0)
return false;
if(a[i] > q){
q--;
}
}
}
return true;
}
static int isOk(int[] a, int x, int q){
int n = a.length;
for(int i=0;i<n;i++){
if(i < x){
continue;
}
else{
if(a[i] > q){
q--;
}
}
}
return q;
}
public static void main(String[] args) throws IOException {
Soumit sc = new Soumit();
int tc = sc.nextInt();
StringBuilder sb = new StringBuilder();
while (tc-->0){
int n = sc.nextInt();
int q = sc.nextInt();
int[] a = sc.nextIntArray(n);
int l = 0, r = n-1;
while(l < r){
int mid = (l + r) / 2;
if(isOk(a, mid, q) >= 0){
r = mid;
}
else{
l = mid + 1;
}
}
StringBuilder sb1 = new StringBuilder();
int x = 0;
for(int i=0;i<n;i++){
if(i < l){
if(a[i] <= q){
sb1.append("1");
x++;
}
else{
sb1.append("0");
}
}
else{
sb1.append("1");
x++;
}
}
/*int lim = (1<<n);
int max = 0;
for(int i=0;i<lim;i++){
String bin = Integer.toBinaryString(i);
bin = pad(bin, n);
if(isValid(a, bin, q)){
max = Math.max(max, countBits(i));
}
}
if(!isValid(a, sb1.toString(), q) || max!=x){
System.out.println("Wrong answer");
System.out.println(max+" "+x);
System.out.println(q+" "+Arrays.toString(a));
System.exit(0);
}*/
sb.append(sb1).append("\n");
}
System.out.println(sb);
sc.close();
}
public static String pad(String s, int n){
StringBuilder sb = new StringBuilder();
for(int i=s.length();i<n;i++){
sb.append("0");
}
sb.append(s);
return sb.toString();
}
static int countBits(int n){
int c = 0;
while(n > 0){
n = n & (n-1);
c++;
}
return c;
}
static class Soumit {
final private int BUFFER_SIZE = 1 << 18;
final private DataInputStream din;
final private byte[] buffer;
private PrintWriter pw;
private int bufferPointer, bytesRead;
StringTokenizer st;
public Soumit() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Soumit(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public void streamOutput(String file) throws IOException {
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
pw = new PrintWriter(bw);
}
public void println(String a) {
pw.println(a);
}
public void print(String a) {
pw.print(a);
}
public String readLine() throws IOException {
byte[] buf = new byte[3000064]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public void sort(int[] arr) {
ArrayList<Integer> arlist = new ArrayList<>();
for (int i : arr)
arlist.add(i);
Collections.sort(arlist);
for (int i = 0; i < arr.length; i++)
arr[i] = arlist.get(i);
}
public void sort(long[] arr) {
ArrayList<Long> arlist = new ArrayList<>();
for (long i : arr)
arlist.add(i);
Collections.sort(arlist);
for (int i = 0; i < arr.length; i++)
arr[i] = arlist.get(i);
}
public int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public double[] nextDoubleArray(int n) throws IOException {
double[] arr = new double[n];
for (int i = 0; i < n; i++) {
arr[i] = nextDouble();
}
return arr;
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
/*if (din == null)
return;*/
if (din != null) din.close();
if (pw != null) 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 17 | 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 | 8a7953b5b0cf73f165dee1596ce59375 | train_109.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>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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
CDoremysIQ solver = new CDoremysIQ();
solver.solve(1, in, out);
out.close();
}
static class CDoremysIQ {
public void solve(int testNumber, InputReader in, OutputWriter out) {
var tc = in.nextInt();
for (int i = 0; i < tc; i++) {
solution(i, in, out);
}
}
void solution(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int q = in.nextInt();
int[] a = in.nextIntArray(n);
boolean[] b = new boolean[n];
// at the end, each Q could be used as an extra contest (unless she tests them all).
for (int i = 0; i < n; i++) {
if (a[i] <= q) {
b[i] = true;
}
}
int counter = q;
// go backwards through b
for (int i = n - 1; i >= 0 && counter > 0; i--) {
if (!b[i]) {
b[i] = true;
counter--;
} else {
// how much above the minimum required am I?
// if I am more above the minimum required than the counter (things i intend to fail), i don't need to decrement counter
if (q - a[i] >= counter) {
} else {
counter--;
}
}
}
// print the result b
for (int i = 0; i < n; i++) {
out.print(b[i] ? "1" : "0");
}
out.println();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println() {
writer.println();
}
public void close() {
writer.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 17 | 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 | 788090948b910cdf72bed462d833a5b3 | train_109.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>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) {
LinkedList<Integer> s = new LinkedList<>();
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++) {
int fir = -1;
if(!s.isEmpty()){
fir = s.getFirst();
}
if (i==fir) {
ans[i] = '1';
s.pollFirst();
} 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 17 | 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 | debdac9a588977fffe9efe8c65dbfbb1 | train_109.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>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 {
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() throws IOException{
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;
}
int[] nextArray(int n){
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(next());
}
return a;
}
}
public static void main(String[] args) throws IOException
{
// System.setIn(new FileInputStream(new File("/Users/pluo/Desktop/CF/input.txt")));
// System.setOut(new PrintStream(new File("/Users/pluo/Desktop/CF/output.txt")));
FastReader sc = new FastReader();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int tt = sc.nextInt();
for(int a0 = 0; a0 < tt; a0++){
int n = sc.nextInt();
int q = sc.nextInt();
int[] a = sc.nextArray(n);
int Q = 0;
StringBuilder s = new StringBuilder("");
for(int i = n-1; i >= 0; i--){
if(a[i] <= Q){
s.insert(0,"1");
}
else{
if(Q < q){
Q++;
s.insert(0,"1");
}
else{
s.insert(0,"0");
}
}
}
out.write(s + "\n");
}
out.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 17 | 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 | ebc109fe226238e80b175e0fe60fb2d3 | train_109.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>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 codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i=0 ; i<t ; i++){
int n = in.nextInt();
int iq = in.nextInt();
int a[] = new int[n];
for(int j=0 ; j<n ; j++){
a[j] = in.nextInt();
}
int q=0;
for(int k=n-1 ; k>=0 ; k--){
if(q<iq){
if(a[k]>q){
a[k] = 1;
q++;
}
else a[k] = 1;
}
else{
if(a[k]<=iq) a[k] = 1;
else a[k] = 0;
}
}
for(int j=0 ; j<n; j++){
System.out.print(a[j]);
}
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 17 | 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 | 2dad033a65d2763bfd0be1f398bc64b1 | train_109.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>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.ArrayList;
import java.util.Scanner;
public class Srhossain{
public static void main(String[] args){
new Srhossain();
}
public Srhossain(){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tc=1; tc<=t; tc++){
int n = sc.nextInt();
int k = sc.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++)arr[i] = sc.nextInt();
int cnt = 0;
for(int i=n-1; i>=0; i--){
if(arr[i] <= cnt)arr[i] = 1;
else if(cnt < k){
cnt++;
arr[i] = 1;
}
else{
arr[i] = 0;
}
}
for(int x: arr){
show(x+"");
}
showln("");
}
sc.close();
}
public void showarr(int[] arr){
for(int i=0; i<arr.length; i++)
System.out.print(arr[i]+" ");
showln("");
}
public void show(String s){ System.out.print(s); }
public void showln(String s){ System.out.println(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 17 | 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 | 103b38b969ea6646e7a6953e7f771487 | train_109.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>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.min;
import static java.lang.Math.max;
import static java.lang.Math.abs;
import java.util.*;
import javax.lang.model.util.ElementScanner14;
import java.math.*;
public class C_Doremy_s_IQ {
public static void solve(Scanner in){
int n = in.nextInt();
int q = in.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n ; i++){
arr[i] = in.nextInt();
}
int nq = 0;
int ans[] = new int[n];
for(int i = n-1; i>=0; i--){
if(arr[i] <= nq)
ans[i] = 1;
else if(nq < q){
nq++;
ans[i] = 1;
}
else
ans[i] = 0;
}
for(int i = 0; i<n; i++)
System.out.print(ans[i]);
System.out.println();
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i<t; i++){
solve(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 17 | 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 | 7590034d572de89ee046c62ebe97e72a | train_109.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>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.StringTokenizer;
public class TaskC {
public static void main(String[] args) {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
TaskC s = new TaskC();
s.solve(in, out);
out.flush();
}
void solveOne(FastScanner in, PrintWriter out) {
int n = in.nextInt();
long q = in.nextLong();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
int low = 0, high = n;
int r = 0;
while (low <= high) {
int mid = (low + high) / 2;
long iq = q;
for (int i = mid; i < n; i++) {
if (iq < a[i]) {
iq--;
}
}
if (iq >= 0) {
r = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
for (int i = 0; i < n; i++) {
if (i < r) {
out.print(q >= a[i] ? '1' : '0');
} else {
out.print('1');
}
}
out.println("");
}
void solve(FastScanner in, PrintWriter out) {
int t = 1;
t = in.nextInt();
for (int tc = 1; tc <= t; tc++) {
// out.printf("Case #%d: ", tc);
solveOne(in, out);
}
}
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()); }
float nextFloat() { return Float.parseFloat(next()); }
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 17 | 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 | 07de8f475b27476a63636aa43ef2ae04 | train_109.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>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.util.function.*;
import java.io.*;
// you can compare with output.txt and expected out
public class Round808C {
MyPrintWriter out;
MyScanner in;
// final static long FIXED_RANDOM;
// static {
// FIXED_RANDOM = System.currentTimeMillis();
// }
final static String IMPOSSIBLE = "IMPOSSIBLE";
final static String POSSIBLE = "POSSIBLE";
final static String YES = "YES";
final static String NO = "NO";
private void initIO(boolean isFileIO) {
if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) {
try{
in = new MyScanner(new FileInputStream("input.txt"));
out = new MyPrintWriter(new FileOutputStream("output.txt"));
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}
else{
in = new MyScanner(System.in);
out = new MyPrintWriter(new BufferedOutputStream(System.out));
}
}
public static void main(String[] args){
// Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
Round808C sol = new Round808C();
sol.run();
}
private void run() {
boolean isDebug = false;
boolean isFileIO = true;
boolean hasMultipleTests = true;
initIO(isFileIO);
int t = hasMultipleTests? in.nextInt() : 1;
for (int i = 1; i <= t; ++i) {
int n = in.nextInt();
int q = in.nextInt();
int[] a = in.nextIntArray(n);
if(isDebug){
out.printf("Test %d\n", i);
}
String ans = solve(a, q);
out.println(ans);
if(isDebug)
out.flush();
}
in.close();
out.close();
}
private String solve(int[] a, int q) {
StringBuilder sb = new StringBuilder();
// can take test only if q > 0
// if take i
// ai > q -> q--
// ai <= q -> q remains same
// need to take as many tests as possible
// ai <= q -> always take
// q >= n -> can take all
// if tried ai > q -> could have tried aj > q for j > i
// dp[i] = score where j < i -> take only if aj > q, j >= i -> always take
// q = 6
// 5 5 5 5 5 5 7 7 5 5 5 5 5 5 5 5 5
// q = 1 -- go from last, find the place where it takes the hit
// 1 x x x x x 1 x x x x x x x 1 X can't can't ....
// q = 2
//
int n = a.length;
if(q >= n) {
for(int i=0; i<n; i++)
sb.append('1');
return sb.toString();
}
// 5 2
// 5 1 2 4 3
// 5 1 2 4 3
// 2 2 2 1 0
// 0 1 1 1 1
// 2 1 0
int currQ = 0;
for(int i=n-1; i>=0; i--) {
if(currQ < q)
sb.append('1');
else if(q >= a[i]) {
sb.append('1');
}
else{
sb.append('0');
}
if(a[i] > currQ) {
currQ++;
}
}
return sb.reverse().toString();
// int[] cnt = new int[n+1];
// for(int i=0; i<n; i++) {
// if(a[i] >= n)
// cnt[n]++;
// else
// cnt[a[i]]++;
// }
//
// int bestIndex = -1;
// int bestScore = 0;
//
// int score = 0;
// for(int i=0; i<n; i++) {
//
// }
//
//
// return null;
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
// 32768?
public MyScanner(InputStream is, int bufferSize) {
br = new BufferedReader(new InputStreamReader(is), bufferSize);
}
public MyScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
// br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
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[][] nextTreeEdges(int n, int offset){
int[][] e = new int[n-1][2];
for(int i=0; i<n-1; i++){
e[i][0] = nextInt()+offset;
e[i][1] = nextInt()+offset;
}
return e;
}
int[][] nextMatrix(int n, int m) {
return nextMatrix(n, m, 0);
}
int[][] nextMatrix(int n, int m, int offset) {
int[][] mat = new int[n][m];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
mat[i][j] = nextInt()+offset;
}
}
return mat;
}
int[][] nextPairs(int n){
return nextPairs(n, 0);
}
int[][] nextPairs(int n, int offset) {
int[][] xy = new int[2][n];
for(int i=0; i<n; i++) {
xy[0][i] = nextInt() + offset;
xy[1][i] = nextInt() + offset;
}
return xy;
}
int[][] nextGraphEdges(){
return nextGraphEdges(0);
}
int[][] nextGraphEdges(int offset) {
int m = nextInt();
int[][] e = new int[m][2];
for(int i=0; i<m; i++){
e[i][0] = nextInt()+offset;
e[i][1] = nextInt()+offset;
}
return e;
}
int[] nextIntArray(int len) {
return nextIntArray(len, 0);
}
int[] nextIntArray(int len, int offset){
int[] a = new int[len];
for(int j=0; j<len; j++)
a[j] = nextInt()+offset;
return a;
}
long[] nextLongArray(int len) {
return nextLongArray(len, 0);
}
long[] nextLongArray(int len, int offset){
long[] a = new long[len];
for(int j=0; j<len; j++)
a[j] = nextLong()+offset;
return a;
}
}
public static class MyPrintWriter extends PrintWriter{
public MyPrintWriter(OutputStream os) {
super(os);
}
public void printlnAns(long ans) {
println(ans);
}
public void printlnAns(int ans) {
println(ans);
}
public void printlnAns(boolean ans) {
if(ans)
println(YES);
else
println(NO);
}
public void printAns(long[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(long[] arr){
printAns(arr);
println();
}
public void printAns(int[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(int[] arr){
printAns(arr);
println();
}
public <T> void printAns(ArrayList<T> arr){
if(arr != null && arr.size() > 0){
print(arr.get(0));
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i));
}
}
}
public <T> void printlnAns(ArrayList<T> arr){
printAns(arr);
println();
}
public void printAns(int[] arr, int add){
if(arr != null && arr.length > 0){
print(arr[0]+add);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]+add);
}
}
}
public void printlnAns(int[] arr, int add){
printAns(arr, add);
println();
}
public void printAns(ArrayList<Integer> arr, int add) {
if(arr != null && arr.size() > 0){
print(arr.get(0)+add);
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i)+add);
}
}
}
public void printlnAns(ArrayList<Integer> arr, int add){
printAns(arr, add);
println();
}
public void printlnAnsSplit(long[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public void printlnAnsSplit(int[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public <T> void printlnAnsSplit(ArrayList<T> arr, int split){
if(arr != null && !arr.isEmpty()){
for(int i=0; i<arr.size(); i+=split){
print(arr.get(i));
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr.get(j));
}
println();
}
}
}
}
static private void permutateAndSort(long[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
long temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private void permutateAndSort(int[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
int temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private int[][] constructChildren(int n, int[] parent, int parentRoot){
int[][] childrens = new int[n][];
int[] numChildren = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
numChildren[parent[i]]++;
}
for(int i=0; i<n; i++) {
childrens[i] = new int[numChildren[i]];
}
int[] idx = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
childrens[parent[i]][idx[parent[i]]++] = i;
}
return childrens;
}
static private int[][][] constructDirectedNeighborhood(int n, int[][] e){
int[] inDegree = new int[n];
int[] outDegree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outDegree[u]++;
inDegree[v]++;
}
int[][] inNeighbors = new int[n][];
int[][] outNeighbors = new int[n][];
for(int i=0; i<n; i++) {
inNeighbors[i] = new int[inDegree[i]];
outNeighbors[i] = new int[outDegree[i]];
}
int[] inIdx = new int[n];
int[] outIdx = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outNeighbors[u][outIdx[u]++] = v;
inNeighbors[v][inIdx[v]++] = u;
}
return new int[][][] {inNeighbors, outNeighbors};
}
static private int[][] constructNeighborhood(int n, int[][] e) {
int[] degree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
degree[u]++;
degree[v]++;
}
int[][] neighbors = new int[n][];
for(int i=0; i<n; i++)
neighbors[i] = new int[degree[i]];
int[] idx = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
neighbors[u][idx[u]++] = v;
neighbors[v][idx[v]++] = u;
}
return neighbors;
}
static private void drawGraph(int[][] e) {
makeDotUndirected(e);
try {
final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot")
.redirectOutput(new File("graph.png"))
.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
static private void makeDotUndirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict graph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "--" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
static private void makeDotDirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict digraph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "->" + e[i][1] + ";");
}
out2.println("}");
out2.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 17 | 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 | 4200a0031e70a091e94e5a325e27cf1e | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
import java.io.*;
public class lab_1 {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0; i < t ;i++) {
int n = sc.nextInt();
boolean flag = true;
ArrayList<Long> a = new ArrayList<>();
for(int j = 0; j < n;j++) {
a.add(sc.nextLong());
}
long n1 = a.get(0);
for(int j = 1;j < n;j++) {
if(a.get(j) % n1 !=0 ) {
flag = false;
}
}
if(flag) {
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 boolean ready() throws IOException {
return br.ready();
}
public int[] readArr(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(next());
}
return arr;
}
}
}
| Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 72731c8620bc5282a96e04ab9fadfabc | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
int time = a.nextInt();
int i;
int mid = 0;
for (int u = 0; u < time; u++) {
int len = a.nextInt();
int [] ar = new int[len];
for(int p = 0;p<len;p++){
ar[p] = a.nextInt();
}
boolean ok = false;
for (int j = 1; j <len; j++) {
if(ar[0] == 0&& ar[j] != 0 || ar[j]%ar[0] != 0){
ok = true;
System.out.println("NO");
break;
}
if(ar[j-1] == 0&& ar[j] !=0){
ok = true;
System.out.println("NO");
break;
}
}
if(!ok)
System.out.println("YES");
}
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 77c0a9ef01e6bc9fb899a687ece3f298 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.util.Scanner;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int t = scan.nextInt();
while (t-- > 0) {
solve();
}
}
private static void solve() {
int n = scan.nextInt();
int[] arr = new int[n + 1];
String flag = "YES";
arr[1] = scan.nextInt();
for (int i = 2; i <= n; i++) {
arr[i] = scan.nextInt();
if (arr[i] % arr[1] != 0) {
flag = "NO";
}
}
System.out.println(flag);
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output | |
PASSED | 72810c06501f66c9524ad5c6ba72bdc5 | train_109.jsonl | 1657982100 | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.*;
public class Main {
static FastScanner scan = new FastScanner();
static PrintWriter writer = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int t = scan.nextInt();
while (t-- > 0) {
solve();
}
writer.close();
}
private static void solve() throws IOException {
int n = scan.nextInt();
int[] arr = new int[n + 1];
String flag = "YES";
arr[1] = scan.nextInt();
for (int i = 2; i <= n; i++) {
arr[i] = scan.nextInt();
if (arr[i] % arr[1] != 0) {
flag = "NO";
}
}
writer.printf("%s\n", flag);
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
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;
}
} | Java | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | 1 second | ["YES\nYES\nYES\nNO"] | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal: Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$. Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$. Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$. | Java 8 | standard input | [
"greedy",
"math"
] | 1c597da89880e87ffe791dd6b9fb2ac7 | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$). | 800 | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.