This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import sys
import threading
def main():
import sys
input = sys.stdin.readline
N, R = map(int, sys.stdin.readline().split())
R0 = int(sys.stdin.readline()) # Our rank
other_ranks = []
for _ in range(2*N - 1):
other_ranks.append(int(sys.stdin.readline()))
# Arrange other archers into targets
better_archers_count_per_target = [0] * (N + 2) # 1-indexed, up to N
for t in range(1, N+1):
idx1 = 2*(t-1) # positions in other_ranks list (0-based)
idx2 = 2*(t-1) + 1
count = 0
if idx1 < len(other_ranks) and other_ranks[idx1] < R0:
count += 1
if idx2 < len(other_ranks) and other_ranks[idx2] < R0:
count += 1
better_archers_count_per_target[t] = count
# Compute suffix sums
suffix_sum_better_archers = [0] * (N + 2) # indices from 1 to N+1
for t in range(N, 0, -1):
suffix_sum_better_archers[t] = suffix_sum_better_archers[t+1] + better_archers_count_per_target[t]
# Find the best starting target
min_finishing_target = float('inf')
best_t = -1
for t in range(1, N+1):
finishing_target = t + suffix_sum_better_archers[t+1]
if finishing_target < min_finishing_target:
min_finishing_target = finishing_target
best_t = t
elif finishing_target == min_finishing_target and t > best_t:
best_t = t
print(best_t)
threading.Thread(target=main).start()
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |