CT181

Main Diagonal Parcel Totals

EasyL2 · Byte BanditAcceptance: 0.0%XP: 10

A square parcel table contributes only its top-left to bottom-right diagonal. Task: Sum the main diagonal from top-left to bottom-right. Input format: A square matrix: n followed by n*n integers in row-major order. Output format: One integer: the diagonal sum. Constraints: 1 <= n <= 100; -10^6 <= entries <= 10^6 Edge rules: Apply the stated zero, tie, boundary, and ordering conventions exactly.

Example 1:

Input: 1 5
Output: 5

Example 2:

Input: 2 1 2 3 4
Output: 5

Example 3:

Input: 3 1 2 3 4 5 6 7 8 9
Output: 15

Constraints:

1 <= n <= 100; -10^6 <= entries <= 10^6

Tags:

matrices diagonal
Loading...
Test Cases:No test cases
No test cases available.