Advertisement
mickypinata

PROG-T1044: Road Cut

Jul 4th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7.     int row, col;
  8.     scanf("%d", &row);
  9.     scanf("%d", &col);
  10.  
  11.     vector<int> berow(row + 1, 0);
  12.     vector<int> becol(col + 1, 0);
  13.     int sum = 0;
  14.     for(int i = 1; i <= row; ++i){
  15.         for(int j = 1; j <= col; ++j){
  16.             int x;
  17.             scanf("%d", &x);
  18.             berow[i] += x;
  19.             becol[j] += x;
  20.             sum += x;
  21.         }
  22.     }
  23.  
  24.     vector<int> afrow(row + 2, 0);
  25.     vector<int> afcol(col + 2, 0);
  26.     for(int i = 1; i <= row; ++i){
  27.         for(int j = 1; j <= col; ++j){
  28.             int x;
  29.             scanf("%d", &x);
  30.             afrow[i] += x;
  31.             afcol[j] += x;
  32.         }
  33.     }
  34.  
  35.     int mx = 0;
  36.     for(int i = 1; i <= row; ++i){
  37.         mx = max(mx, sum + afrow[i - 1] + afrow[i + 1] - berow[i]);
  38.     }
  39.     for(int i = 1; i <= col; ++i){
  40.         mx = max(mx, sum + afcol[i - 1] + afcol[i + 1] - becol[i]);
  41.     }
  42.  
  43.     cout << mx;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement