read an bn m
read -a a
read -a b
amin=`echo ${a[@]} | tr ' ' '\n' | sort -n | head -1`
bmin=`echo ${b[@]} | tr ' ' '\n' | sort -n | head -1`
smin=$((amin+bmin))
for i in `seq $m`
do
    read x y c
    t=$((a[x-1]+b[y-1]-c))
    ((t<smin)) && smin=$t
done
echo $smin
