HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN112 Homeworks 2013-2015 > problem:


14-Spr1-40. 50538 - Sum of kth Diagonal

CEN112 Homeworks 2013-2015

Start: Dec.15.2013 at 12:00:00 PM
Finish: Dec.15.2013 at 05:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 50393 - Palindromic Numbers
• 50339 - The Largest Rectangle
• 50345 - Orders
• 50758 - National Elections - Revisited
• 50754 - Team Standings
• 12-Spr1-40. 50327 - Parallel Lines
• 13-Fall2-20. 50395 - Page "Like" Av...
• 14-Spr1-30. 50492 - Contest Score...
• 14-Spr1-40. 50538 - Sum of kth...
• 14-Spr1-60. 50647 - Spiral
• 14-Spr2-20. 50442 - Polynomial Add...
• 14-Spr2-40. 50361 - Align Two Lists
• 14-Spr2-50. 50616 - Snake
• 14-Spr2-60. 50444 - n digit kth nu...
• 15-SprHW-20. 50446 - Snake
• 15-SprHW-30. 50788 - Eight Puzzle
• 15-SprHW-40. 50746 - Most Visited

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