Problem
Given a matrix and Q queries, each query is four integers (r1, c1, r2, c2). For each query, print the sum of all elements in the submatrix with top-left (r1,c1) and bottom-right (r2,c2) (0-based, inclusive).
Input format
Input
input.txt
- Three integers: N M Q (1 β€ N, M β€ 20, 1 β€ Q β€ 10) - N rows of M integers - Q lines, each with r1 c1 r2 c2 (0 β€ r1 β€ r2 < N, 0 β€ c1 β€ c2 < M)
Output format
Output
output.txt
- Q lines: sum for each query
Example
input
2 2 2 1 2 3 4 0 0 0 1 0 0 1 1
output
3 10
π¬ Discussion
Loading...π¬
No comments yet. Be the first to start the discussion!
π» No output yet.
Click Run in the editor to execute your code with the custom input.
Sample cases (from the problem)
Sample Case 1
Input
2 2 2 1 2 3 4 0 0 0 1 0 0 1 1
Expected output
3 10
Solve it your way first
Community solutions unlock after you submit a passing solution. Don't peek.
Ready to solve this challenge?
Create a free account to write code, submit solutions, and track your progress.
β¨οΈ Keyboard Shortcuts
Code Editor
Run Code
Ctrl
Enter
Submit Code
Ctrl
Shift
Enter
Format Code
Shift
Alt
F
Toggle Comment
Ctrl
/
Undo
Ctrl
Z
Redo
Ctrl
Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc