#CT0000130. Phần thưởng (Prizes)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Phần thưởng (Prizes)
Prizes
Source: Bộ Giáo dục và Đào tạo
Version: Phuoc Hung OJ Extended
Problem Statement
Vinh may choose exactly one of prize plans. The organizers place a prize in every cell of an grid. The prize at row , column has value ; row and column indices start at .
Each plan contains squares, each covering cells. Square in plan is specified by the top-left cell . Every square lies entirely within the grid, and squares may overlap. Selecting a plan awards the prizes in all cells contained in at least one of its squares; a cell is counted only once even if several squares cover it.
Determine the maximum total prize value obtainable by choosing exactly one plan.
Input
- The first line contains four positive integers .
- Each of the next lines contains positive integers; the th integer on line is .
- Each of the final lines contains integers identifying the top-left corners of the squares in plan .
Output
Print one integer equal to the maximum total prize value.
Subtasks
- Subtask 1 (25 points): ; ; ; ; ; .
- Subtask 2 (25 points): ; ; ; ; ; .
- Subtask 3 (25 points): ; ; ; ; ; .
- Subtask 4 (25 points): ; ; ; ; ; .
Examples
Example 1
Input
4 2 2 3
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 2 2 3 3
1 1 1 3 3 1
Output
12
Explanation: Plan uses top-left corners , , and covers distinct cells. Plan uses , , and covers distinct cells. Every prize has value , so the maximum sum is .
Liên quan
Trong các cuộc thi sau: