fork(1) download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define fi first
  9. #define se second
  10. #define mp make_pair
  11. #define pb push_back
  12. #define fbo find_by_order
  13. #define ook order_of_key
  14.  
  15. typedef long long ll;
  16. typedef pair<ll,ll> ii;
  17. typedef vector<int> vi;
  18. typedef long double ld;
  19. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  20. typedef set<int>::iterator sit;
  21. typedef map<int,int>::iterator mit;
  22. typedef vector<int>::iterator vit;
  23.  
  24. ll r[5001];
  25. ll c[5001];
  26. ll a[5001][5001];
  27.  
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0); cin.tie(0);
  31. int n; cin >> n;
  32. for(int i = 0; i < n; i++)
  33. {
  34. for(int j = 0; j < n; j++)
  35. {
  36. cin>>a[i][j];
  37. r[i]+=a[i][j];
  38. c[j]+=a[i][j];
  39. }
  40. }
  41. ll best = -ll(1e18);
  42. for(int i = 0; i < n; i++)
  43. {
  44. for(int j = 0; j < n; j++)
  45. {
  46. best = max(best, r[i]+c[j]-a[i][j]);
  47. }
  48. }
  49. cout<<best<<'\n';
  50. }
  51.  
Runtime error #stdin #stdout 0s 198912KB
stdin
Standard input is empty
stdout
Standard output is empty