포럼
문제 ICPC00193

F. Fastest Speedrun

설명

The classic video game "Prince of Python" comprises \(n\) levels, numbered from \(1\) to \(n\). You are going to speedrun this game by finishing all of the levels as fast as possible, and you can beat them in any order that you want.

You enter each level equipped with one of \(n+1\) magical items. In the beginning you only have item \(0\) in your inventory. Once you beat a level, you get to keep the item numbered the same as that level. For example, on finishing level \(5\), you obtain a mighty Gauntlet of 5 Fingers you may equip thereafter instead of the less-acclaimed Sword of 0 Damage you always start out with.

Beating a level can take different amounts of time depending on which item you take into the level with you. Higher-numbered items are more powerful, so if playing by the rules it is always at least as fast to finish the level with a higher-numbered item as with a lower-numbered item.

However, each level also has a shortcut left in by the developers. The shortcut for a level can be accessed by applying a specific item in an unconventional way. By doing so you can finish the level as fast as, or even faster than, if you had used any of the other items.

How long will it take you to beat all of the levels of the game?

제약
입력 형식

The input consists of:
- One line containing an integer \(n\) (\(1 \le n \le 2\,500\)), the number of levels.
- \(n\) lines, describing the levels.

The \(i\)th such line starts with two integers \(x_i\) and \(s_i\) (\(0 \le x_i \le n\), \(1 \le s_i \le 10^9\)), the shortcut item for level \(i\) and the completion time for level \(i\) when using the shortcut.

The remainder of the line has \(n+1\) integers \(a_{i,0}, \ldots, a_{i,n}\) (\(10^9 \ge a_{i,0} \ge a_{i,1} \ge \ldots \ge a_{i,n} \ge s_i\)), where \(a_{i,j}\) is the completion time for level \(i\) when playing by the rules using item \(j\).

출력 형식

Output the minimum time it takes to beat, in any order, all of the levels in the game.

예제 1
입력
3
1 1 40 30 20 10
3 1 95 95 95 10
2 1 95 50 30 20
출력
91
예제 2
입력
4
4 4 5 5 5 5 5
4 4 5 5 5 5 5
4 4 5 5 5 5 5
4 4 5 5 5 5 5
출력
17
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2018

평가 및 의견

F. Fastest Speedrun

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

F. Fastest Speedrun

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8