program niceshopping
  implicit none
  integer :: A, B, M, price, minprice, i, j
  integer,allocatable :: fri(:), ra(:), dsc(:,:)

  read(*,*) A, B, M
  allocate(fri(A), ra(B), dsc(3,M))

  read(*,*) fri
  read(*,*) ra
  do i = 1, M
     read(*,*) (dsc(j,i) ,j = 1, 3)
  end do
  minprice = minval(fri) + minval(ra)
  do i = 1, M
     price = fri(dsc(1,i)) + ra(dsc(2,i)) - dsc(3,i)
     if (price < minprice) then
        minprice = price
     end if
  end do
  write(*,*) minprice
  deallocate(fri,ra,dsc)
  stop
end program niceshopping
