Guest User

Untitled

a guest
Dec 28th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int t;
  7.     int n;
  8.     int max = 0;
  9.     int a[100];
  10.     cin >> t;
  11.     if (t < 1 || t>100)
  12.         return 0;
  13.  
  14.     //loop for test cases
  15.     while (t--) {
  16.  
  17.         cin >> n;
  18.         if (n < 2 || n>100)
  19.             return 0;
  20.  
  21.         int n2 = n * n;
  22.         for (int i = 0; i < n2; i++) {
  23.             cin >> a[i];
  24.             if (a[i] < 1 || a[i]>100)
  25.                 return 0;
  26.         }
  27.  
  28.         // For checking the first row traces
  29.         for (int i = 0; i < n; i++) {
  30.             int j = 0;
  31.             int temp = 0;
  32.             while (i + j < (n2 - n * i)) {
  33.                 temp += a[i + j];
  34.                 j += n + 1;
  35.             }
  36.             if (temp > max)
  37.                 max = temp;
  38.         }
  39.  
  40.         // For checking the first column traces
  41.         for (ll i = 0; i <= (n2 - n); i += n) {
  42.             int j = 0;
  43.             int temp = 0;
  44.             while (i + j < n2) {
  45.                 temp += a[i + j];
  46.                 j += n + 1;
  47.             }
  48.             if (temp > max)
  49.                 max = temp;
  50.         }
  51.  
  52.         cout << max << endl;
  53.     }
  54. }
Add Comment
Please, Sign In to add comment