fork download
  1. #include<bits/stdc++.h>
  2. #define int long long int
  3. #define inf 100000000000000
  4. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. using namespace std;
  6. int mod=998244353;
  7. int arr[8][8];
  8. int n,m;
  9. void print()
  10. {
  11. for(int i=0;i<n;i++)
  12. {
  13. for(int j=0;j<m;j++)
  14. {
  15. cout<<arr[i][j]<<" ";
  16. }
  17. cout<<endl;
  18. }
  19. }
  20.  
  21.  
  22. int32_t main()
  23. {
  24. IOS;
  25.  
  26. cin>>n>>m;
  27.  
  28.  
  29.  
  30. for(int i=0;i<n;i++)
  31. {
  32. for(int j=0;j<m;j++)
  33. {
  34. cin>>arr[i][j];
  35. }
  36. }
  37.  
  38. for(int j=0;j<m;j++)
  39. {
  40. for(int i=n-2;i>=0;i--)
  41. {
  42. arr[i][j]+=arr[i+1][j];
  43. }
  44. }
  45. for(int i=0;i<n;i++)
  46. {
  47. for(int j=m-2;j>=0;j--)
  48. {
  49. arr[i][j]+=arr[i][j+1];
  50. }
  51. }
  52. int ans=0;
  53. int sum=arr[0][0];
  54. for(int i=1;i<n;i++)
  55. {
  56. for(int j=1;j<m;j++)
  57. {
  58. if(arr[i][j]<=sum/2)
  59. {
  60. ans=max(ans,arr[i][j]);
  61. }
  62. }
  63. }
  64. cout<<sum-ans<<endl;
  65. }
  66.  
  67.  
Success #stdin #stdout 0s 4164KB
stdin
4 4
3 4 7 5
6 6 8 4
7 6 6 4
6 6 1 1
stdout
56