public static void main(String[] args) {
   FastScanner in = new FastScanner(System.in);
   int sum = in.nextInt();
   int limit = in.nextInt();
   int cnt = 0;
   StringBuilder sb = new StringBuilder();
   Point[] points = new Point[limit + 1];
   points[0] = new Point(0, 0);
   for (int i = 1; i <= limit; i++) points[i] = new Point(i, lb(i));
   Arrays.sort(
       points,
       new Comparator<Point>() {
         public int compare(Point a, Point b) {
           return a.y - b.y;
         }
       });
   // System.out.println(Arrays.toString(points));
   for (int i = limit; i >= 1; i--) {
     if (sum >= points[i].y) {
       sum -= points[i].y;
       sb.append(" ");
       sb.append(points[i].x);
       cnt++;
     }
   }
   if (sum == 0) {
     System.out.println(cnt);
     System.out.println(sb.toString().trim());
   } else {
     System.out.println(-1);
   }
 }
Exemple #2
0
  public void solve() throws IOException {
    int n = in.nextInt();
    int m = in.nextInt();
    graph = new ArrayList[n + 1];
    color = new int[n + 1];
    Arrays.fill(color, 0);

    for (int i = 0; i < m; i++) {
      int from = in.nextInt();
      int to = in.nextInt();
      if (graph[from] == null) {
        graph[from] = new ArrayList<Integer>();
      }
      graph[from].add(to);
    }

    topSort();
    if (hasCycle) {
      out.print(-1);
      return;
    }

    for (Integer anAnswer : answer) {
      out.printf("%d ", anAnswer);
    }
  }
  public static void main(String[] args) {
    FastScanner in = new FastScanner(System.in);
    int n = in.nextInt();
    int[] s = new int[n + 5];
    int[] s2 = new int[n + 5];
    for (int i = 1; i <= n; i++) {
      s[i] = in.nextInt();
      s2[n - i + 1] = s[i];
    }

    int[] stack = new int[n + 5];
    int size = 0;
    int answer = 0;
    for (int i = 1; i <= n; i++) {
      while (size > 0 && stack[size - 1] < s[i]) size--;

      stack[size++] = s[i];

      if (size >= 2) answer = Math.max(answer, stack[size - 1] ^ stack[size - 2]);
    }
    size = 0;
    for (int i = 1; i <= n; i++) {
      while (size > 0 && stack[size - 1] < s2[i]) size--;

      stack[size++] = s2[i];

      if (size >= 2) answer = Math.max(answer, stack[size - 1] ^ stack[size - 2]);
    }
    System.out.println(answer);
  }
 public void solve() throws IOException {
   /* MAIN CODE GOES HERE!!! */
   MyQueueOnMyLinkedList q = new MyQueueOnMyLinkedList();
   int n = in.nextInt();
   for (int i = 0; i < n; i++) {
     String s = in.next();
     if (s.charAt(0) == '-') {
       out.println(q.pop());
     } else if (s.charAt(0) == '+') {
       q.push(in.nextInt());
     }
   }
 }
Exemple #5
0
 public static void main(String[] args) {
   FastScanner scanner = new FastScanner(System.in);
   int n = scanner.nextInt();
   int m = scanner.nextInt();
   assert 1 <= n && n <= 1e6 : "out of range, n: " + n;
   assert 2 <= m && m <= 1e3 : "out of range, m: " + m;
   int[] A = new int[n];
   for (int i = 0; i < A.length; i++) {
     A[i] = scanner.nextInt();
     assert 0 <= A[i] && A[i] <= 1e9 : "out of range, A[i]: " + A[i];
     if (A[i] == 0) {
       System.out.println("YES");
       return;
     }
   }
   Bravo o = new Bravo(n, m, A);
   System.out.println((o.solve()) ? "YES" : "NO");
 }
Exemple #6
0
 public void run() {
   Locale.setDefault(Locale.US);
   try {
     sc = new FastScanner("access.in");
     out = new PrintWriter("access.out");
     solve();
     sc.close();
     out.close();
   } catch (Throwable e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
Exemple #7
0
 double nextDouble() {
   return sc.nextDouble();
 }
Exemple #8
0
 long nextLong() {
   return sc.nextLong();
 }
Exemple #9
0
 String nextToken() {
   return sc.nextToken();
 }
Exemple #10
0
 int nextInt() {
   return sc.nextInt();
 }
Exemple #11
0
 BigInteger nextBigInteger() {
   return sc.nextBigInteger();
 }