Bitaro the Brave 2
시간 제한1초메모리 제한2048 MB
시작 몬스터 j를 정해 j번부터 N번까지, 그다음 1번부터 j-1번까지 처치할 때 필요한 최소 초기 강도를 구한다.
문제
Bitaro, the brave hero, has set out on an adventure to defeat monsters.
Bitaro has a strength value, denoted as , which starts at an initial value. There are monsters, each labeled with a number from to . To defeat the -th monster (), Bitaro must have a strength of at least . Defeating the -th monster increases Bitaro’s strength by .
Bitaro wants to defeat all the monsters using the following strategy:
- Start with a specific monster () and defeat the monsters in order: .
- If , go back and defeat the monsters in sequence.
Given the information about the monsters, write a program to determine the minimum initial strength required for Bitaro to defeat all the monsters.
입력
Read the following data from the standard input.
출력
Output a single integer, the minimum initial strength required for Bitaro to defeat all the monsters.
제한
- .
- ().
- ().
- Given values are all integers.