Iamtui1010

summax.cpp

Sep 16th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<map>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     cin.tie(0)->sync_with_stdio(0);
  13.     freopen("summax.inp", "r", stdin);
  14.     freopen("summax.ans.out", "w", stdout);
  15.     long n;
  16.     cin >> n;
  17.     vector<vector<long>> a(n);
  18.     for (long i = 0; i < n; ++i){
  19.         a[i].resize(n, 0);
  20.         for (long j = 0; j < n; ++j)
  21.             cin >> a[i][j];
  22.     }
  23.     map<long, long> sum;
  24.     for (long i = 0; i < n; ++i)
  25.         for (long j = 0; j < n; ++j)
  26.             sum[i-j] += a[i][j];
  27.  
  28.     long res = LLONG_MIN;
  29.     for (auto i : sum)
  30.         res = (i.second > res) ? i.second : res;
  31.     cout << res << nln;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment