포럼
문제 COCI00107

Dostava

설명

Little Ivica recently got a job delivering pizzas for the most popular pizzeria in town.

At the start of his work day, he receives a list with the locations to which he needs to deliver pizzas, in the order in which the locations are given.

The city is divided into \(R \times C\) cells. The rows are numbered \(1\) through \(R\), columns \(1\) through \(C\).

From every cell, it is possible to move to neighbouring cells to the left and right. Moving up or down is only allowed in the first and last columns (columns \(1\) and \(C\)).

The pizzeria is in the top left corner \((1, 1)\) and this is the location Ivica starts from. Ivica takes with him all the pizzas he will deliver that day so he does not have to return to the pizzeria between deliveries or after the last delivery.

For each location in the city, Ivica knows how much time he will spend every time he is in it (trying to get through the intersection, for example).

Write a program that calculates the smallest amount of time for Ivica to deliver all the pizzas.

제약
입력 형식

The first line contains the integers \(R\) and \(C\) (\(1 \le R \le 2000\), \(1 \le C \le 200\)), the dimensions of the city.

Each of the following \(R\) lines contains \(C\) integers. These are the times Ivica spends every time he enters a location. The times will be integers between \(0\) and \(5000\), inclusive.

The next line contains an integer \(D\) (\(1 \le D \le 200000\)), the number of pizza deliveries that day.

Each of the following \(D\) lines contains two integers \(A\) and \(B\) (\(1 \le A \le R\), \(1 \le B \le C\)), the location to which a pizza must be delivered. The pizzas are given in the order in which they must be delivered. No location will be given twice in a row.

출력 형식

Output the smallest amount of time for Ivica to deliver all the pizzas.

Scoring: In test cases worth \(70\%\) of points, \(R\) will be at most \(250\).

서브태스크
서브태스크점수설명

Subtask 1

84점

\(R \le 250\)

Subtask 2

36점

No additional constraints (\(R \le 2000\)).

예제 1
입력
3 3
1 8 2
2 3 2
1 0 1
3
1 3
3 3
2 2
출력
17
예제 2
입력
2 5
0 0 0 0 0
1 4 2 3 2
4
1 5
2 2
2 5
2 1
출력
9
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 6

평가 및 의견

Dostava

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

Log in to rate problems.

개별 의견

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

풀이 제출

Dostava

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