Language: C++

                          
                                    #include <iostream>
                                    #include <iomanip>
                                    #include <sstream>
                                    #include <cstring>
                                    #include <vector>
                                    #include <deque>
                                    #include <queue>
                                    #include <set>
                                    #include <map>
                                    #include <valarray>
                                    #include <iterator>
                                    #include <functional>
                                    #include <limits>
                                    #include <algorithm>
                                    #include <numeric>
                                    #include <cmath>
                                    #include <cassert>
                                    #include <unordered_map>
                                    #include <unordered_set>
                                    #include <stack>
                                    using namespace std;
                                    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
                                     #define trace(x) cerr << #x << ": " << x << " " << endl;
                                 
                                    typedef int64_t ll;
                                 
                                    #define endl '\n'
                                    //#define int ll
                                    ll mod=1e9+7;
                                    ll mod1=1e9+5;
                                    
                                    ll power(ll a,ll b)
                                    {
                                        if(b==0) return 1;
                                        else if(b%2==0)
                                            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
                                        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
                                    }
                                    
                                  
                                
                                 int dp[81][81][25601];
                                int main()
                                {
                                    IOS
                                

                                
                                int n,m;
                                cin>>n>>m;
                                int a[n+1][m+1];
                                int b[n+1][m+1];
                                memset(a,0,sizeof(a));
                                memset(b,0,sizeof(b));
                                for(int i=1;i<=n;++i)
                                {
                                    for(int j=1;j<=m;++j)
                                        cin>>a[i][j];
                                }

                                for(int i=1;i<=n;++i)
                                {
                                    for(int j=1;j<=m;++j)
                                        cin>>b[i][j];
                                }
                               
                                for(int i=0;i<=n;++i)
                                {
                                    for(int j=0;j<=m;++j)
                                    {
                                        for(int k=0;k<=2;++k)
                                            dp[i][j][k]=1e10;
                                    }
                                }
                                dp[1][1]=abs(a[1][1]-b[1][1]);
                                
                                for(int i=1;i<=n;++i)
                                {
                                    for(int j=1;j<=m;++j)
                                    {
                                        if(i==1 and j==1)
                                            continue;
                                        vector<int> v;
                                        v.push_back(dp[i-1][j][1]+a[i][j]-b[i][j]);
                                        v.push_back(dp[i][j-1][1]+a[i][j]-b[i][j]);
                                        v.push_back(dp[i-1][j][2]+a[i][j]-b[i][j]);
                                        v.push_back(dp[i][j-1][2]+a[i][j]-b[i][j]);
                                      
                                        int comp=1e9;
                                        for(int k=0;k<v.size();++k)
                                        {
                                            if(comp>abs(v[k]))
                                            {
                                                dp[i][j][1]=v[k];
                                                comp=abs(v[k]);
                                            }
                                        }
                                        v.clear();
                                        v.push_back(dp[i-1][j][1]+b[i][j]-a[i][j]);
                                        v.push_back(dp[i][j-1][1]+b[i][j]-a[i][j]);
                                        v.push_back(dp[i-1][j][2]+b[i][j]-a[i][j]);
                                        v.push_back(dp[i][j-1][2]+b[i][j]-a[i][j]);
                                       
                                        comp=1e9;
                                        for(int k=0;k<v.size();++k)
                                        {
                                          
                                            if(comp>abs(v[k]))
                                            {
                                                dp[i][j][2]=v[k];
                                                comp=abs(v[k]);
                                            }
                                        }
                                        //cout<<dp[i][j][1]<<" "<<dp[i][j][2]<<" "<<i<<" "<<j<<endl;

                                        

                                    }
                                }
                                cout<<min(abs(dp[1][1][1]),abs(dp[1][1][2]));
                                


                                }                       


Compiler output:
a.cc: In function 'int main()':
a.cc:73:57: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   73 |                                             dp[i][j][k]=1e10;
      |                                                         ^~~~
a.cc:76:41: error: incompatible types in assignment of 'int' to 'int [25601]'
   76 |                                 dp[1][1]=abs(a[1][1]-b[1][1]);
      |                                 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~