Language: C++

#include <iostream>

using namespace std;


int main()
{
  long  W,H;
  int cost=0;
  int lastcost=-1;
  long long  *P=new long long[W];
  long long  *Q=new long long[H];
  cin >> W>>H;
  int **data = new int*[W+1];
  for(int i=0;i<W+1;i++){
    data[i] = new int [H+1];
  }

  for(int i=0;i<W;i++){
    cin >> P[i];
  }
  for(int i=0;i<H;i++){
    cin >> Q[i];
  }


  for(int i=0;i<W+1;i++){
    for(int c=0;c<H+1;c++){
      data[i][c]=0;
    }
  }


  for(int ii=0;ii<W+1;ii++){
    for(int cc=0;cc<H+1;cc++){
      for(int i=0;i<W+1;i++){
        for(int c=0;c<H+1;c++){
          data[i][c]=0;
        }
      }
      data[ii][cc]=1;

      while(1){
        int tmpi=-1;
        int tmpc=-1;
        long long tmpcost=100000001;
        int dir=0;
        for(int i=0;i<W+1;i++){
          for(int c=0;c<H+1;c++){
            if(data[i][c]==1){
              if(i>0){
                if(data[i-1][c]==0){
                  if(P[i-1]<tmpcost){tmpcost=P[i-1];dir=1;tmpi=i;tmpc=c;}
                }
              }
              if(i<W){
                if(data[i+1][c]==0){
                  if(P[i]<tmpcost){tmpcost=P[i];dir=2;tmpi=i;tmpc=c;}
                }
              }
              if(c>0){
                if(data[i][c-1]==0){
                  if(Q[c-1]<tmpcost){tmpcost=Q[c-1];dir=3;}tmpi=i;tmpc=c;}
                }
              }
              if(c<H){
                if(data[i][c+1]==0){
                  if(Q[i]<tmpcost){tmpcost=Q[i];dir=4;tmpi=i;tmpc=c;}
                }
              }

              if(tmpcost!=100000001){
                if(dir==1) data[tmpi-1][tmpc]=1;
                else if(dir==2)data[tmpi+1][tmpc]=1;
                else if(dir==3)data[tmpi][tmpc-1]=1;
                else if(dir==4)data[tmpi][tmpc+1]=1;

                cost+=tmpcost;
                tmpcost=100000001;dir=0;
              }

            }




          }
        }
        



        int check = 0;
        for(int i=0;i<W+1;i++){
          for(int c=0;c<H+1;c++){
            if(data[i][c]==0)check=1;
          }
        }
        if(check==0)break;
      }

      if(ii==0&&cc==0)lastcost=cost;
      else{
        if(lastcost>cost)lastcost=cost;
      }
      cout<<ii<<cc<<":"<<cost<<endl;///////////////////////////////
      cost=0;

    }
  }

  cout<<lastcost<<endl;
  for(int i=0;i<W+1;i++){
    delete[] data[i];data[i]=0;
  }
  delete [] data;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:102:17: error: 'cc' was not declared in this scope
  102 |       if(ii==0&&cc==0)lastcost=cost;
      |                 ^~
a.cc:106:17: error: 'cc' was not declared in this scope
  106 |       cout<<ii<<cc<<":"<<cost<<endl;///////////////////////////////
      |                 ^~
a.cc: At global scope:
a.cc:112:3: error: 'cout' does not name a type
  112 |   cout<<lastcost<<endl;
      |   ^~~~
a.cc:113:3: error: expected unqualified-id before 'for'
  113 |   for(int i=0;i<W+1;i++){
      |   ^~~
a.cc:113:15: error: 'i' does not name a type
  113 |   for(int i=0;i<W+1;i++){
      |               ^
a.cc:113:21: error: 'i' does not name a type
  113 |   for(int i=0;i<W+1;i++){
      |                     ^
a.cc:116:3: error: expected unqualified-id before 'delete'
  116 |   delete [] data;
      |   ^~~~~~
a.cc:117:3: error: expected unqualified-id before 'return'
  117 |   return 0;
      |   ^~~~~~
a.cc:118:1: error: expected declaration before '}' token
  118 | }
      | ^