Why Runtime Error?
https://atcoder.jp/contests/abc161/submissions/35445063
I think it is obviously a greedy algorithm problem.
Leetcode Weekly 501 + Biweekly 182 Solution Discussion
Repovive Starter Round 1 Solution Discussion (with Anirudh)