HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


125. 50538 - Sum of kth Diagonal

Guest
• Review clarifications (1)

Volume problems

• 50468 - Draw Matrix - 2
• 010. 50381 - Sum of the numbers
• 030. 50737 - Sum of the k-largest n...
• 060. 50389 - Reverse an Array
• 100. 50330 - Find the average of n ...
• 110. 50359 - Mode of a Series
• 120. 50331 - Number of Numbers o...
• 120. 50329 - Draw Matrix-1
• 125. 50538 - Sum of kth Diagonal
• 140. 50599 - Sum of Squared Error ...
• 15-SprPrE1-80. 50741 - DNA Distance
• 151. 50557 - nth Power of m (Long...
• 155. 50334 - What is the class aver...
• 155. 50726 - Pascal Triangle - 1
• 160. 50301 - Fractions to Decimals
• 165. 50360 - National Elections
• 170. 50319 - Toll Plazas

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Sum of kth Diagonal

Question: Diagonal of a matrix starts from upper left corner and goes to the lower right corner. You are given an nXn square matrix. Find the sum of kth diagonal. For example, the third diagonal starts from the third row first element (4). And then, every element is connected to its lower right neigbour (13 and then 4) until it reaches to the border of the square.

Input specification
You will be given two integer numbers (n and k) at the beginning where 1 ≤ n ≤ 100 and 1 ≤ k ≤ 2*n-1. Then, in the following n lines, you will be given n integers, which are between 0 and 1000.

Output specification
Show just one number: sum of kth diagonal.

 Sample Input   
  5 6
  7 6 4 1 5
  5 9 7 8 7
  6 7 8 7 5
  8 8 0 4 10
  7 5 0 2 0
 Sample Output   
  30


Explanation:   6+7+7+10=30


Для отправки решений необходимо выполнить вход.

www.contester.ru