Submission #34462643


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main() {
  iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int n, q;
  cin >> n >> q;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  const long long N = (long long)1e18;
  while (q--) {
    long long k;
    cin >> k;
    long long low = 1, high = N;
    long long ans = -1;
    while (low <= high) {
      long long mid = (high - low) / 2 + low;
      int idx = lower_bound(A.begin(), A.end(), mid) - A.begin();
      bool in = idx < n && A[idx] == mid;
      long long how_many = mid - idx;
      if (!in && how_many == k) {
        ans = mid;
        break;
      }
      if (how_many <= k) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    cout << ans << '\n';
  }

  return 0;
}

Submission Info

Submission Time
Task D - Kth Excluded
User shoshoshom
Language C++ (GCC 9.2.1)
Score 0
Code Size 850 Byte
Status WA
Exec Time 258 ms
Memory 3988 KiB

Judge Result

Set Name Sample All After_Contest
Score / Max Score 0 / 0 0 / 400 0 / 0
Status
AC × 2
AC × 17
WA × 2
AC × 2
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
After_Contest after_00.txt, after_01.txt
Case Name Status Exec Time Memory
after_00.txt AC 227 ms 3824 KiB
after_01.txt AC 224 ms 3804 KiB
block_00.txt AC 161 ms 3860 KiB
block_01.txt AC 128 ms 3492 KiB
block_02.txt AC 92 ms 3596 KiB
block_03.txt AC 89 ms 3660 KiB
block_04.txt AC 34 ms 3600 KiB
example_00.txt AC 2 ms 3544 KiB
example_01.txt AC 2 ms 3436 KiB
killer_00.txt WA 224 ms 3868 KiB
killer_01.txt WA 132 ms 3808 KiB
random_00.txt AC 258 ms 3952 KiB
random_01.txt AC 31 ms 3512 KiB
random_02.txt AC 180 ms 3988 KiB
random_03.txt AC 208 ms 3608 KiB
random_04.txt AC 48 ms 3972 KiB
random_05.txt AC 221 ms 3596 KiB
random_06.txt AC 56 ms 3544 KiB
random_07.txt AC 79 ms 3652 KiB
random_08.txt AC 179 ms 3988 KiB
random_09.txt AC 229 ms 3556 KiB