Iamtui1010

sum.cpp

Sep 28th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 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("sum.inp", "r", stdin);
  14.     freopen("sum.out", "w", stdout);
  15.     long n;
  16.     cin >> n;
  17.     vector<vector<long>> a;
  18.     a.resize(n);
  19.     for (long i = 0; i < n; ++i){
  20.         a[i].resize(n, 0);
  21.         for (long j = 0; j < n; ++j)
  22.             cin >> a[i][j];
  23.     }
  24.     map<long, long> sum;
  25.     for (long i = 0; i < n; ++i)
  26.         for (long j = 0; j < n; ++j)
  27.             sum[i-j] += a[i][j];
  28.  
  29.     long res = LLONG_MIN;
  30.     for (auto i : sum)
  31.         res = (i.second > res) ? i.second : res;
  32.     cout << res << nln;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment