Skip to content

Instantly share code, notes, and snippets.

@skysign
Created August 24, 2025 03:43
Show Gist options
  • Select an option

  • Save skysign/bd270480fa1e36734ad07d19b99da033 to your computer and use it in GitHub Desktop.

Select an option

Save skysign/bd270480fa1e36734ad07d19b99da033 to your computer and use it in GitHub Desktop.
2번
import sys
def solve():
N, Q, K = list(map(int, sys.stdin.readline().split()))
seolbis = list(map(int, sys.stdin.readline().split()))
usages = [0 for _ in range(len(seolbis))]
beginEnd = []
for _ in range(Q):
beginEnd.append(list(map(int, sys.stdin.readline().split())))
for begin, end in beginEnd:
idxl = mybs(begin, seolbis)
idxr = mybs(end, seolbis)
for idx in range(idxl, idxr + 1):
usages[idx] -= 1
results = []
for idx in range(len(seolbis)):
p = [usages[idx], seolbis[idx]]
results.append(p)
results.sort()
print(results[K][1])
def mybs(seolbi_target, seolbis):
idxl = 0
idxr = len(seolbis) - 1
while idxl < idxr:
idxm = (idxl + idxr) // 2
if seolbis[idxm] == seolbi_target:
return idxm
if seolbis[idxm] > seolbi_target:
idxr = idxm - 1
else:
idxl = idxm + 1
return idxl
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
solve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment