Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main() {
- int t;
- int n;
- int max = 0;
- int a[100];
- cin >> t;
- if (t < 1 || t>100)
- return 0;
- //loop for test cases
- while (t--) {
- cin >> n;
- if (n < 2 || n>100)
- return 0;
- int n2 = n * n;
- for (int i = 0; i < n2; i++) {
- cin >> a[i];
- if (a[i] < 1 || a[i]>100)
- return 0;
- }
- // For checking the first row traces
- for (int i = 0; i < n; i++) {
- int j = 0;
- int temp = 0;
- while (i + j < (n2 - n * i)) {
- temp += a[i + j];
- j += n + 1;
- }
- if (temp > max)
- max = temp;
- }
- // For checking the first column traces
- for (ll i = 0; i <= (n2 - n); i += n) {
- int j = 0;
- int temp = 0;
- while (i + j < n2) {
- temp += a[i + j];
- j += n + 1;
- }
- if (temp > max)
- max = temp;
- }
- cout << max << endl;
- }
- }
Add Comment
Please, Sign In to add comment