Sudhanshu_03's blog

By Sudhanshu_03, history, 4 years ago, In English

Can anyone explain to me why my code doesn't work for https://mirror.codeforces.com/contest/1708/problem/C .

import java.util.*;

public class A {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    StringBuilder str = new StringBuilder();
    int t = sc.nextInt();
    for (int xx = 1; xx <= t; xx++) {
       int n = sc.nextInt();
       int q = sc.nextInt();
       int[] arr = new int[n];
       for (int i = 0; i < n; i++) {
         arr[i] = sc.nextInt();
       }
       int[] ans = new int[n];
       Arrays.fill(ans, 0);
       for (int i = 0; i < n; i++) {
         if (arr[i] <= q) {
          ans[i] = 1;
         }
       }
       int max = 0;
       int q1 = q;
       for (int i = n - 1; i >= 0; i--) {
         if (ans[i] == 1)
          max = Math.max(max, arr[i]);
         else if (max < q || q1 >= n - i) {
          ans[i] = 1;
          q--;
         }
       }
       for (int i : ans)
         str.append(i);
       str.append("\n");
    }
    System.out.println(str);
    sc.close();
}

}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it