Submission #23465233


Source Code Expand

import java.util.*;
import java.io.*;

public class Main{ 
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] nq = in.readLine().split(" ");
    long n = Long.parseLong(nq[0]);
    long q = Long.parseLong(nq[1]);
    String[] ast = in.readLine().split(" ");
    long stock = 0;
    List<Long[]> list = new ArrayList<>();

    long temp = 0;
    for (String as : ast) {
      long a = Long.parseLong(as);
      if (temp != a-stock) {
        list.add(new Long[]{temp, stock});
        temp = a-stock;
      }
      stock++;
    }
    list.add(new Long[]{temp,stock});
    list.add(new Long[]{Long.MAX_VALUE,Long.MAX_VALUE});

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < q; i++) {
      long query = Long.parseLong(in.readLine());
      int min = 0; 
      int max = list.size()-1;
      int curr = (min+max)/2;
      while (min+1 != max) {
        if (list.get(curr)[0] > query) {
          max = curr;
        } else {
          min = curr;
        }
        curr = (min+max)/2;
      }
      sb.append(query + list.get(min)[1]);
      sb.append('\n');
    }
    System.out.println(sb);
  }
}

Submission Info

Submission Time
Task D - Kth Excluded
User nophey
Language Java (OpenJDK 11.0.6)
Score 400
Code Size 1264 Byte
Status AC
Exec Time 429 ms
Memory 68016 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 19
Set Name Test Cases
Sample example_00.txt, example_01.txt
All block_00.txt, block_01.txt, block_02.txt, block_03.txt, block_04.txt, example_00.txt, example_01.txt, killer_00.txt, killer_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt
Case Name Status Exec Time Memory
block_00.txt AC 348 ms 51988 KiB
block_01.txt AC 323 ms 51068 KiB
block_02.txt AC 290 ms 54668 KiB
block_03.txt AC 288 ms 46308 KiB
block_04.txt AC 170 ms 38224 KiB
example_00.txt AC 74 ms 32044 KiB
example_01.txt AC 76 ms 32344 KiB
killer_00.txt AC 404 ms 67992 KiB
killer_01.txt AC 290 ms 51272 KiB
random_00.txt AC 429 ms 67532 KiB
random_01.txt AC 166 ms 38268 KiB
random_02.txt AC 377 ms 68016 KiB
random_03.txt AC 376 ms 59544 KiB
random_04.txt AC 276 ms 59496 KiB
random_05.txt AC 386 ms 59868 KiB
random_06.txt AC 219 ms 40176 KiB
random_07.txt AC 306 ms 56408 KiB
random_08.txt AC 386 ms 67724 KiB
random_09.txt AC 364 ms 59296 KiB