Advertisement
Matteogoli

sottomat.cpp

Oct 11th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5.  
  6. int max(int a, int b);
  7. int sum_col(int k, int j);
  8.  
  9. int r, c;
  10. int a[1000][1000];
  11.  
  12. int main(){
  13.     ifstream in("input.txt");
  14.     ofstream out("output.txt");
  15.    
  16.     in >> r >> c;
  17.     for(int i = 0; i < r; i++){
  18.         for (int j = 0; j < c; j++)
  19.             in >> a[i][j];
  20.     }
  21.    
  22.     int sum;
  23.     int max_sum = 0;
  24.    
  25.     for(int i = 0; i < r; i++){
  26.         for(int j = 0; j < c; j++){
  27.             int sum = 0;
  28.             for(int k = 0; k <= j; k++){
  29.                 int n = 0;
  30.                 for(int cont = 0; cont <= i; cont++)
  31.                     n += a[cont][k];
  32.                 cout << n << endl;
  33.                 sum = max(sum + n, 0);
  34.                 max_sum = max(max_sum, sum);
  35.             }
  36.         }
  37.     }
  38.    
  39.     out << max_sum;
  40.    
  41.     return 0;
  42. }
  43.  
  44. int max(int a, int b){
  45.     return (a > b ? a : b);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement