Advertisement
vitormartinotti

Untitled

May 21st, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.     int n, m; scanf("%d %d", &n, &m);
  7.  
  8.     int campo[n][m];
  9.  
  10.     //Leitura da matriz
  11.     for(int i = 0; i < n; i++){
  12.         for(int j = 0; j < m; j++){
  13.             scanf("%d", &campo[i][j]);
  14.         }
  15.     }
  16.  
  17.     //Soma das lihas e colunas
  18.     int somaL[n], somaC[m];
  19.     for(int k = 0; k < n; k++){
  20.         somaL[k] = 0;
  21.     }
  22.     for(int k = 0; k < m; k++){
  23.         somaC[k] = 0;
  24.     }
  25.  
  26.     for(int i = 0; i < n; i++){
  27.         for(int j = 0; j < m; j++){
  28.             somaL[i] += campo[i][j];
  29.             somaC[j] += campo[i][j];
  30.         }
  31.     }
  32.  
  33.     int maior = -1;
  34.     for(int k = 0; k < n; k++){
  35.         if (somaL[k] > maior){
  36.             maior = somaL[k];
  37.         }
  38.     }
  39.     for(int k = 0; k < m; k++){
  40.         if (somaC[k] > maior){
  41.             maior = somaC[k];
  42.         }
  43.     }
  44.  
  45.     printf("%d", maior);
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement