Official

A - 待ち合わせ場所 / Meeting Place Editorial by admin

Claude 4.6 Opus (Thinking)

Overview

This is a basic input/output problem where you output the coordinate of the \(K\)-th building among \(N\) buildings, minus \(1\).

Analysis

Let’s organize what this problem is asking:

  1. The coordinates of \(N\) buildings are given in order.
  2. Obtain the coordinate \(X_K\) of the \(K\)-th building.
  3. Output the value \(X_K - 1\), which is that coordinate minus \(1\).

No special algorithm is needed — you simply read the coordinate of the building with the specified number and subtract \(1\).

Concrete example: If \(N = 3, K = 2\) and the building coordinates are \(5, 10, 3\) respectively, then the coordinate of the \(2\)-nd building is \(10\), so the answer is \(10 - 1 = 9\).

Algorithm

  1. Read \(N\) and \(K\).
  2. Store the coordinates of the \(N\) buildings in an array \(X\).
  3. Output the coordinate of the \(K\)-th building \(X[K-1]\) (0-indexed) minus \(1\).
N, K = map(int, input().split())
X = [int(input()) for _ in range(N)]
print(X[K-1] - 1)

Key point: The problem specifies “the \(K\)-th building” using 1-indexed (counting from 1) numbering, but Python lists are 0-indexed (counting from 0), so we access it as X[K-1] by shifting the index by \(1\).

Complexity

  • Time complexity: \(O(N)\) (for reading \(N\) coordinates)
  • Space complexity: \(O(N)\) (for storing \(N\) coordinates in an array)

Implementation Notes

  • Converting between 1-indexed and 0-indexed: Building numbers in the problem start from \(1\), but Python list indices start from \(0\), so the \(K\)-th element is accessed with X[K-1]. This is an extremely common pattern in competitive programming.

  • Handling large values: The coordinate range \(-10^{18} \leq X_i \leq 10^{18}\) is very large, but since Python does not suffer from integer overflow, no special handling is needed (in C++ and similar languages, you would need to use long long).

    Source Code

N, K = map(int, input().split())
X = [int(input()) for _ in range(N)]
print(X[K-1] - 1)

This editorial was generated by claude4.6opus-thinking.

posted:
last update: