Why Runtime Error?
https://atcoder.jp/contests/abc161/submissions/35445063 It is obviously a greedy algorithm problem.
Repovive Starter Round 1 Solution Discussion (with Anirudh)