a53

Ciocolata

a53
May 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <fstream>
  2. #include <climits>
  3. using namespace std;
  4.  
  5. #define Nmax 502
  6.  
  7. ifstream fin ( "ciocolata.in" );
  8. ofstream fout ( "ciocolata.out" );
  9.  
  10. int v[Nmax][Nmax];
  11. long long sum[Nmax][Nmax];
  12.  
  13. int main(){
  14. int N, M, solx1, soly1, solx2, soly2;
  15.  
  16. long long maxx = LLONG_MIN , sol;
  17.  
  18. fin >> N >> M;
  19.  
  20. for ( int i = 1; i <= N; ++i )
  21. for ( int j = 1; j <= M; ++j )
  22. fin >> v[i][j];
  23.  
  24. for ( int i = 1; i <= M; ++i )
  25. for ( int j = 1; j <= N; ++j )
  26. sum[j][i] = sum[j-1][i] + v[j][i];
  27.  
  28. int x1, y1, x2, y2;
  29. for ( int i = 1; i <= N; ++i ){
  30. x1 = i;
  31. for ( int j = i; j <= N; ++j ){
  32. sol = 0;
  33. x2 = j;
  34. y1 = 1;
  35. y2 = 0;
  36. for ( int k = 1; k <= M; ++k ){
  37. long long x = sum[j][k] - sum[i-1][k];
  38.  
  39. if ( x > sol + x ){
  40. y1 = y2 = k;
  41. sol = x;
  42. }
  43. else{
  44. sol = sol + x;
  45. y2++;
  46. }
  47.  
  48. if ( sol > maxx ){
  49. maxx = sol;
  50. solx1 = x1; solx2 = x2;
  51. soly1 = y1; soly2 = y2;
  52. }
  53. }
  54. }
  55. }
  56.  
  57. fout << maxx << "\n";
  58. fout << solx1 << " " << soly1 << " " << solx1 << " " << soly2 << "\n";
  59. fout << solx2 << " " << soly1 << " " << solx2 << " " << soly2;
  60.  
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment