#P2468. [SDOI2010] 粟粟的书架
[SDOI2010] 粟粟的书架
Description
Susu from Class B29 of Xingfu Kindergarten is a smart, obedient, and adorable child. Her hobbies are drawing and reading, and she especially likes the articles by Thomas H. Cormen. Susu’s home has a giant bookshelf with rows and columns, with one book at every position. The book at the -th row from the top and the -th column from the left has pages.
Besides reading, Susu has another essential daily task: picking apples. Each day she must pick a specific apple. The apples on her family’s trees are at various heights, and she cannot reach them on her own. However, she found that if she stands on some books, she can reach the apples. She also noticed that for the apple designated on day , as long as the total number of pages of the books under her feet is at least , she will definitely be able to pick it.
Because there are too many books, her parents worry she might finish reading all of them in one day and be late for kindergarten, so each day they only allow her to take books from a specific region. This region is a rectangle: on day , the top-left corner is the book at row and column , and the bottom-right corner is the book at row and column . In other words, on that day, she can only select some books from these books to stand on and pick the apple.
Each time Susu takes books, she returns them promptly to their original places, and the bookshelf will not have books removed or added. The apple-picking task continues for days. Given the number of pages of each book, the daily region restrictions, and the picking requirement, please tell Susu the minimum number of books she must take each day to pick the specified apple.
Input Format
The first line contains three positive integers .
Next is a matrix with rows and columns. From top to bottom and left to right, it gives the number of pages of each book.
Then follow lines. The -th line contains five positive integers , meaning that on day the designated region is the rectangle between and , and the required total number of pages is at least .
It is guaranteed that and .
Output Format
Output lines. On the -th line, print the minimum number of books Susu needs on day to pick the apple. If she cannot pick the apple even by taking all books in the region, print Poor QLW.
5 5 7
14 15 9 26 53
58 9 7 9 32
38 46 26 43 38
32 7 9 50 28
8 41 9 7 17
1 2 5 3 139
3 1 5 5 399
3 3 4 5 91
4 1 4 1 33
1 3 5 4 185
3 3 4 3 23
3 1 3 3 108
6
15
2
Poor QLW
9
1
3
1 10 7
14 15 9 26 53 58 9 7 9 32
1 2 1 9 170
1 2 1 9 171
1 5 1 7 115
1 1 1 10 228
1 4 1 4 45704571
1 1 1 1 1
1 7 1 8 16
6
7
3
10
Poor QLW
1
2
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Additionally, for of the testdata, , , .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号