#P3444. [POI 2006] ORK-Ploughing
[POI 2006] ORK-Ploughing
Description
Byteasar, the farmer, wants to plough his rectangular field. He can begin by ploughing a slice from any of the field’s edges; then he can plough a slice from any edge of the remaining unploughed field, and so on, until the whole field is ploughed. After each slice is ploughed, the yet-unploughed field is still a rectangle. Each slice has a span of , and the field is divided into unit tiles.
We identify the tiles by their coordinates , for and . Each tile has a non-negative ploughing-difficulty. Let denote the difficulty of the tile with coordinates .
Byteasar has only one puny and frail nag (horse). Once the nag starts to plough a slice, it will not stop until the slice is completely ploughed. However, if the slice is too much for the nag to bear, it will die of exhaustion, so Byteasar has to be careful. After every ploughed slice, the nag can rest and gather strength. For every slice, the sum of ploughing-difficulties of the tiles forming it cannot exceed a certain constant .
Determine the minimum number of slices required to plough the entire field without exceeding the limit on any slice. It is guaranteed that there exists a way to plough the field according to the above rules.
Input Format
- The first line contains three positive integers , and , separated by single spaces, where and .
- The next lines contain the ploughing-difficulty coefficients. Specifically, line () contains integers , separated by single spaces, where .
Output Format
Output one integer: the minimum number of slices required to plough the field while satisfying the given conditions. It is guaranteed that a valid ploughing exists.
12 6 4
6 0 4 8 0 5
0 4 5 4 6 0
0 5 6 5 6 0
5 4 0 0 5 4
8
Hint
Thanks to @NaVi_Awson for the translation.
Translated by ChatGPT 5
京公网安备 11011102002149号