PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000217. Tổng hình chữ nhật lớn nhất theo diện tích (Rectangle Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng hình chữ nhật lớn nhất theo diện tích (Rectangle Sum)
Rectangle Sum
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A square tray has cells with tastiness values . For each worker with capacity , choose a nonempty rectangle of consecutive cells of area at most , using every cell in it. Find the maximum total tastiness. Queries are independent.
Input
The first line contains , followed by rows of integers . The next line contains , followed by lines each containing one integer .
Output
Print lines, the maximum tastiness for each worker.
Subtasks
- Subtask 1 (50 points): ; ; .
- Subtask 2 (50 points): ; ; .
Example 1
Input
3
3 2 1
2 2 1
1 1 1
3
1
4
9
Output
3
9
14
Explanation
For capacities 1, 4 and 9, choose the largest cell, the upper-left 2-by-2 square and the full tray, respectively.
Example 2
Input
3
1 1 1
1 1 1
9 9 9
1
4
Output
27
Explanation
The last row sums to 27 using only three cells; the capacity need not be filled.