PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000220. Tổng đường chéo Tây Bắc – Đông Nam (Diagonal Prefix NW-SE)
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 đường chéo Tây Bắc – Đông Nam (Diagonal Prefix NW-SE)
Diagonal Prefix NW-SE
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
An integer matrix has rows and columns, indexed from 1 from top to bottom and left to right. Each query asks for the sum of exactly cells on the down-right diagonal beginning at : . Each query fits entirely inside the matrix. Values may be negative.
Input
The first line contains . The next lines each contain integers. Each of the following lines contains three integers .
Output
Print lines, one diagonal sum per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; ; .
Example 1
Input
3 4 4
2 -1 3 7
4 5 -2 6
9 8 -4 1
1 1 3
1 2 3
2 1 2
3 4 1
Output
3
-2
12
1
Explanation
The sums are 2+5-4, -1-2+1, 4+8 and 1.
Example 2
Input
1 1 1
-1000000000
1 1 1
Output
-1000000000
Explanation
The only cell is negative and its value is returned unchanged.