Skip to main content
5 of 7
added 8 characters in body
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 24 19 15 13 bytes

pUS¡€U+\€UỤị⁵ 

Takes number of rows, number of columns and a flat list as separate command-line arguments.

Try it online!

How it works (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 
Dennis
  • 211.7k
  • 41
  • 380
  • 830