program sample
    implicit none
  
    integer(8) :: i,j,m,n,s,t,xi,yi,a,b,c
   
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) a,b,m
    allocate(x(a),y(b))
    read(*,*)x
    read(*,*)y
    s=minval(x)+minval(y)
    do i=1,m
        read(*,*)xi,yi,c
        if (x(xi)+y(yi)-c<s)then
            s=x(xi)+y(yi)-c
        end if
    end do


  
    write(*,*) s
  
    stop
end program sample
  

