MojaCoder
Playground
Problems
Post Problem
Contests
Create Contest
EN
JA
Sign up
Sign in
Yet Another MAD TEAM
2 secs
1024 MB
tatyam
Tweet
Problem
Submissions
Test cases
Editorial
https://atcoder.jp/contests/zone2021/editorial/1197
の DP 解で線形です。
他にも解法はたくさん