report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Diagonal sum - MarisaOJ: Marisa Online Judge

Diagonal sum

Time limit: 1000 ms
Memory limit: 256 MB
Given a 2D array $A$ with $n$ rows and $m$ columns, and two integers $x$ and $y$, calculate the sum of the elements on the two diagonals that pass through the element at row $x$ and column $y$ ($A_{x, y}$). ### Input - The first line contains 4 integers $n, m, x, y$. - The next $n$ lines each contain $m$ integers representing the array $A$. ### Output - Calculate the sum of the elements lying on the two diagonals that pass through the element at row $x$ and column $y$ ($A_{x, y}$). ### Constraints - $1 \le n, m \le 100$. - $1 \le x \le n$, $1 \le y \le m$. - $|A_{i,j}| \le 100$. ### Example Input: Input: ``` 3 4 2 2 1 -2 3 2 4 -5 9 0 3 3 2 -2 ``` Output: ``` 4 ``` Note: $1 + 3 + -5 + 3 + 2 = 4$ **1** -2 **3** 2 4 **-5** 9 0 **3** 3 **2** -2
Two dimensional array
Pascal's triangle
Column sum
Appearance
Diagonal sum
Point coverage
Swap operation
Spiral matrix
Word search
Matrix rotation
Matrix Zigzag
Topic
Basic
Rating 800
Solution (0) Solution