fork(2) download
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. size_t i, j, n;
  10. cin >> n;//Размер матрицы.
  11. vector<int> sums(2 * n - 1);//Суммы модулей диагоналей.
  12. //Пусть диагонали пронумерованы слева-сверху направо-вниз.
  13. for (i = 0; i < n; i++)
  14. for (j = 0; j < n; j++) {
  15. int x;
  16. cin >> x;//Элементы матрицы.
  17. sums[i + j] += abs(x);
  18. }
  19. cout << *min_element(sums.begin(), sums.end()) << '\n';
  20. }
  21.  
Success #stdin #stdout 0s 3464KB
stdin
4
-5  3  3  1
 5  0 -1  2
 3 -1 -2  0
 4  0  6 -7
stdout
4