Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <string>
#include <complex>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <deque>
#include <queue>
#include <map>
#include <utility>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <set>
using namespace std;
using ull = unsigned long long;
using  ll =long long ;
using  prll =pair<ll, ll>;
constexpr ll MOD = 1000000007;           //10億　= 10^9になってる
constexpr ll mINF = -922337200085470000; //llのmax-1桁の小さい方
constexpr ll pINF = 1LL << 60;
constexpr ull uINF=  1844674407399900000; //ullのmax-1桁してる
constexpr double  pi = 3.1415926535897932384;
constexpr ll juu = 100000;             //10万 10e5
constexpr ll hyaku = 1000000;         //100万　10e6
constexpr int dx[4] = {0,0,1,-1}; //上下左右のベクトル
constexpr int dy[4] = {1,-1,0,0}; //上下左右のベクトル
constexpr int ddx[8] = {0,0,1,-1,1,1,-1,-1};
constexpr int ddy[8] = {1,-1,0,0,-1,1,1,-1};
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Debug(xx) cerr << " DEBUG:"<< xx << endl ;
#define Debug2(xx,yy) cerr << " DEBUG:"<< xx << ":" << yy<< endl ;
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}
//繰り返し二乗。掛けられる数、回数、mod
ll powpow(ll n, ll p)
{
    if (p == 1)
        return n % MOD;
    if (p % 2 == 1)
    {
        return (n * powpow(n, p - 1)) % MOD;
    }
    ll dob = powpow(n, p / 2);
    return (dob * dob) % MOD;
}
//MODとn、rが互いに素である事が確定していないとこれは出来ない。小定理、またchild,parentでおかしくなる。 mod取った後にそれら同士で割り算するとおかしくなるから逆元使う。（合同式の性質考えろ）
ll nCrMod(ll n, ll r)
{
    ll child = 1;
    ll parent = 1;
    if (r == 0)
        return 1;
    for (ll i = 0; i < r; ++i)
    {
        child = child * (n - i) % MOD;
        parent = parent * (r - i) % MOD;
    }
    ll ans = child * powpow(parent, MOD - 2);
    return ans % MOD;
}
ll to_digit(ll num){
    return (ll)(to_string(num).size());
}
ll nCr(ll n, ll r)
{
    ll val = 1,val2 = 1;
    if (r == 0)
        return 1;
    if(n < r)
        return 0;
    for (ll i = 0; i < r; ++i)
    {
        val *= (n - i);
        val2 *= (r - i);
    }
    return val/val2;
}
ll nPr(ll n, ll r)
{
    ll val = 1;
    for (ll i = 0; i < r; ++i)
    {
        val *= (n - i);
    }
    return val;
}
template <typename T>
bool chmin(T &a, const T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &a, const T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

/*ソートして被りを無くす*/
template <typename T>
void eraseSame(T &a)
{
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

/*aとbで大きい方を後ろにする。変更なしならtrue、ありならfalse */
template <typename T>
bool swapmax(T &a, T &b)
{
    T temp;
    temp = a;
    if (a > b)
    {
        a = b;
        b = temp;
        return false;
    }
    return true;
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

/*一行に入力が何個あるかを1,ぶち込むvectorを2*/
template <typename T>
void splitIn(ll N, vector<T> &array)
{
    T temp;
    int i = 0;
    if (N == 0)
    {
        return;
    }
    array.resize(N);
    while (cin >> temp)
    {
        array[i] = temp;
        i++;
        if (i >= N)
        {
            break;
        }
    }
    return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(20);
    ll n, k, m,l;
    ll ans = pINF;
    ll sum = 0;
    string s;
    vector<ll> cost1,cost2;
    cin >> n >> m >> k;
    splitIn(n,cost1);
    splitIn(m,cost2);
    ll a,b,c;
    rep(i,k){
    	cin >> a >> b >> c;
    	sum = cost1[a-1] + cost2[b-1] - c;
    	chmin(ans,sum);
    	}
    sort(all(cost1));
    sort(all(cost2));
    chmin(ans,cost1[0]+cost2[0]);
    cout << ans << "\n";
    return 0;
}#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <string>
#include <complex>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <deque>
#include <queue>
#include <map>
#include <utility>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <set>
using namespace std;
using ull = unsigned long long;
using  ll =long long ;
using  prll =pair<ll, ll>;
constexpr ll MOD = 1000000007;           //10億　= 10^9になってる
constexpr ll mINF = -922337200085470000; //llのmax-1桁の小さい方
constexpr ll pINF = 1LL << 60;
constexpr ull uINF=  1844674407399900000; //ullのmax-1桁してる
constexpr double  pi = 3.1415926535897932384;
constexpr ll juu = 100000;             //10万 10e5
constexpr ll hyaku = 1000000;         //100万　10e6
constexpr int dx[4] = {0,0,1,-1}; //上下左右のベクトル
constexpr int dy[4] = {1,-1,0,0}; //上下左右のベクトル
constexpr int ddx[8] = {0,0,1,-1,1,1,-1,-1};
constexpr int ddy[8] = {1,-1,0,0,-1,1,1,-1};
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Debug(xx) cerr << " DEBUG:"<< xx << endl ;
#define Debug2(xx,yy) cerr << " DEBUG:"<< xx << ":" << yy<< endl ;
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}
//繰り返し二乗。掛けられる数、回数、mod
ll powpow(ll n, ll p)
{
    if (p == 1)
        return n % MOD;
    if (p % 2 == 1)
    {
        return (n * powpow(n, p - 1)) % MOD;
    }
    ll dob = powpow(n, p / 2);
    return (dob * dob) % MOD;
}
//MODとn、rが互いに素である事が確定していないとこれは出来ない。小定理、またchild,parentでおかしくなる。 mod取った後にそれら同士で割り算するとおかしくなるから逆元使う。（合同式の性質考えろ）
ll nCrMod(ll n, ll r)
{
    ll child = 1;
    ll parent = 1;
    if (r == 0)
        return 1;
    for (ll i = 0; i < r; ++i)
    {
        child = child * (n - i) % MOD;
        parent = parent * (r - i) % MOD;
    }
    ll ans = child * powpow(parent, MOD - 2);
    return ans % MOD;
}
ll to_digit(ll num){
    return (ll)(to_string(num).size());
}
ll nCr(ll n, ll r)
{
    ll val = 1,val2 = 1;
    if (r == 0)
        return 1;
    if(n < r)
        return 0;
    for (ll i = 0; i < r; ++i)
    {
        val *= (n - i);
        val2 *= (r - i);
    }
    return val/val2;
}
ll nPr(ll n, ll r)
{
    ll val = 1;
    for (ll i = 0; i < r; ++i)
    {
        val *= (n - i);
    }
    return val;
}
template <typename T>
bool chmin(T &a, const T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &a, const T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

/*ソートして被りを無くす*/
template <typename T>
void eraseSame(T &a)
{
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

/*aとbで大きい方を後ろにする。変更なしならtrue、ありならfalse */
template <typename T>
bool swapmax(T &a, T &b)
{
    T temp;
    temp = a;
    if (a > b)
    {
        a = b;
        b = temp;
        return false;
    }
    return true;
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

/*一行に入力が何個あるかを1,ぶち込むvectorを2*/
template <typename T>
void splitIn(ll N, vector<T> &array)
{
    T temp;
    int i = 0;
    if (N == 0)
    {
        return;
    }
    array.resize(N);
    while (cin >> temp)
    {
        array[i] = temp;
        i++;
        if (i >= N)
        {
            break;
        }
    }
    return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(20);
    ll n, k, m,l;
    ll ans = pINF;
    ll sum = 0;
    string s;
    vector<ll> cost1,cost2;
    cin >> n >> m >> k;
    splitIn(n,cost1);
    splitIn(m,cost2);
    ll a,b,c;
    rep(i,k){
    	cin >> a >> b >> c;
    	sum = cost1[a-1] + cost2[b-1] - c;
    	chmin(ans,sum);
    	}
    sort(all(cost1));
    sort(all(cost2));
    chmin(ans,cost1[0]+cost2[0]);
    cout << ans << "\n";
    return 0;
}

Compiler output:
a.cc:229:2: error: stray '#' in program
  229 | }#include <cstdio>
      |  ^
a.cc:229:3: error: 'include' does not name a type
  229 | }#include <cstdio>
      |   ^~~~~~~
a.cc:252:14: error: redefinition of 'constexpr const ll MOD'
  252 | constexpr ll MOD = 1000000007;           //10億　= 10^9になってる
      |              ^~~
a.cc:24:14: note: 'constexpr const ll MOD' previously defined here
   24 | constexpr ll MOD = 1000000007;           //10億　= 10^9になってる
      |              ^~~
a.cc:253:14: error: redefinition of 'constexpr const ll mINF'
  253 | constexpr ll mINF = -922337200085470000; //llのmax-1桁の小さい方
      |              ^~~~
a.cc:25:14: note: 'constexpr const ll mINF' previously defined here
   25 | constexpr ll mINF = -922337200085470000; //llのmax-1桁の小さい方
      |              ^~~~
a.cc:254:14: error: redefinition of 'constexpr const ll pINF'
  254 | constexpr ll pINF = 1LL << 60;
      |              ^~~~
a.cc:26:14: note: 'constexpr const ll pINF' previously defined here
   26 | constexpr ll pINF = 1LL << 60;
      |              ^~~~
a.cc:255:15: error: redefinition of 'constexpr const ull uINF'
  255 | constexpr ull uINF=  1844674407399900000; //ullのmax-1桁してる
      |               ^~~~
a.cc:27:15: note: 'constexpr const ull uINF' previously defined here
   27 | constexpr ull uINF=  1844674407399900000; //ullのmax-1桁してる
      |               ^~~~
a.cc:256:19: error: redefinition of 'constexpr const double pi'
  256 | constexpr double  pi = 3.1415926535897932384;
      |                   ^~
a.cc:28:19: note: 'constexpr const double pi' previously defined here
   28 | constexpr double  pi = 3.1415926535897932384;
      |                   ^~
a.cc:257:14: error: redefinition of 'constexpr const ll juu'
  257 | constexpr ll juu = 100000;             //10万 10e5
      |              ^~~
a.cc:29:14: note: 'constexpr const ll juu' previously defined here
   29 | constexpr ll juu = 100000;             //10万 10e5
      |              ^~~
a.cc:258:14: error: redefinition of 'constexpr const ll hyaku'
  258 | constexpr ll hyaku = 1000000;         //100万　10e6
      |              ^~~~~
a.cc:30:14: note: 'constexpr const ll hyaku' previously defined here
   30 | constexpr ll hyaku = 1000000;         //100万　10e6
      |              ^~~~~
a.cc:259:15: error: redefinition of 'constexpr const int dx [4]'
  259 | constexpr int dx[4] = {0,0,1,-1}; //上下左右のベクトル
      |               ^~
a.cc:31:15: note: 'constexpr const int dx [4]' previously defined here
   31 | constexpr int dx[4] = {0,0,1,-1}; //上下左右のベクトル
      |               ^~
a.cc:260:15: error: redefinition of 'constexpr const int dy [4]'
  260 | constexpr int dy[4] = {1,-1,0,0}; //上下左右のベクトル
      |               ^~
a.cc:32:15: note: 'constexpr const int dy [4]' previously defined here
   32 | constexpr int dy[4] = {1,-1,0,0}; //上下左右のベクトル
      |               ^~
a.cc:261:15: error: redefinition of 'constexpr const int ddx [8]'
  261 | constexpr int ddx[8] = {0,0,1,-1,1,1,-1,-1};
      |               ^~~
a.cc:33:15: note: 'constexpr const int ddx [8]' previously defined here
   33 | constexpr int ddx[8] = {0,0,1,-1,1,1,-1,-1};
      |               ^~~
a.cc:262:15: error: redefinition of 'constexpr const int ddy [8]'
  262 | constexpr int ddy[8] = {1,-1,0,0,-1,1,1,-1};
      |               ^~~
a.cc:34:15: note: 'constexpr const int ddy [8]' previously defined here
   34 | constexpr int ddy[8] = {1,-1,0,0,-1,1,1,-1};
      |               ^~~
a.cc:267:4: error: redefinition of 'll factor [300]'
  267 | ll factor[300];
      |    ^~~~~~
a.cc:39:4: note: 'll factor [300]' previously declared here
   39 | ll factor[300];
      |    ^~~~~~
a.cc:268:4: error: redefinition of 'll memory [300]'
  268 | ll memory[300];
      |    ^~~~~~
a.cc:40:4: note: 'll memory [300]' previously declared here
   40 | ll memory[300];
      |    ^~~~~~
a.cc:273:6: error: redefinition of 'void primefac(ll)'
  273 | void primefac(ll num)
      |      ^~~~~~~~
a.cc:45:6: note: 'void primefac(ll)' previously defined here
   45 | void primefac(ll num)
      |      ^~~~~~~~
a.cc:289:5: error: redefinition of 'int elast(ll)'
  289 | int elast(ll number)
      |     ^~~~~
a.cc:61:5: note: 'int elast(ll)' previously defined here
   61 | int elast(ll number)
      |     ^~~~~
a.cc:313:4: error: redefinition of 'll powpow(ll, ll)'
  313 | ll powpow(ll n, ll p)
      |    ^~~~~~
a.cc:85:4: note: 'll powpow(ll, ll)' previously defined here
   85 | ll powpow(ll n, ll p)
      |    ^~~~~~
a.cc:325:4: error: redefinition of 'll nCrMod(ll, ll)'
  325 | ll nCrMod(ll n, ll r)
      |    ^~~~~~
a.cc:97:4: note: 'll nCrMod(ll, ll)' previously defined here
   97 | ll nCrMod(ll n, ll r)
      |    ^~~~~~
a.cc:339:4: error: redefinition of 'll to_digit(ll)'
  339 | ll to_digit(ll num){
      |    ^~~~~~~~
a.cc:111:4: note: 'll to_digit(ll)' previously defined here
  111 | ll to_digit(ll num){
      |    ^~~~~~~~
a.cc:342:4: error: redefinition of 'll nCr(ll, ll)'
  342 | ll nCr(ll n, ll r)
      |    ^~~
a.cc:114:4: note: 'll nCr(ll, ll)' previously defined here
  114 | ll nCr(ll n, ll r)
      |    ^~~
a.cc:356:4: error: redefinition of 'll nPr(ll, ll)'
  356 | ll nPr(ll n, ll r)
      |    ^~~
a.cc:128:4: note: 'll nPr(ll, ll)' previously defined here
  128 | ll nPr(ll n, ll r)
      |    ^~~
a.cc:366:6: error: redefinition of 'template<class T> bool chmin(T&, T)'
  366 | bool chmin(T &a, const T b)
      |      ^~~~~
a.cc:138:6: note: 'template<class T> bool chmin(T&, T)' previously declared here
  138 | bool chmin(T &a, const T b)
      |      ^~~~~
a.cc:376:6: error: redefinition of 'template<class T> bool chmax(T&, T)'
  376 | bool chmax(T &a, const T b)
      |      ^~~~~
a.cc:148:6: note: 'template<class T> bool chmax(T&, T)' previously declared here
  148 | bool chmax(T &a, const T b)
      |      ^~~~~
a.cc:388:6: error: redefinition of 'template<class T> void eraseSame(T&)'
  388 | void eraseSame(T &a)
      |      ^~~~~~~~~
a.cc:160:6: note: 'template<class T> void eraseSame(T&)' previously declared here
  160 | void eraseSame(T &a)
      |      ^~~~~~~~~
a.cc:396:6: error: redefinition of 'template<class T> bool swapmax(T&, T&)'
  396 | bool swapmax(T &a, T &b)
      |      ^~~~~~~
a.cc:168:6: note: 'template<class T> bool swapmax(T&, T&)' previously declared here
  168 | bool swapmax(T &a, T &b)
      |      ^~~~~~~
a.cc:408:4: error: redefinition of 'll gcd(ll, ll)'
  408 | ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
      |    ^~~
a.cc:180:4: note: 'll gcd(ll, ll)' previously defined here
  180 | ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
      |    ^~~
a.cc:409:4: error: redefinition of 'll lcm(ll, ll)'
  409 | ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
      |    ^~~
a.cc:181:4: note: 'll lcm(ll, ll)' previously defined here
  181 | ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
      |    ^~~
a.cc:413:6: error: redefinition of 'template<class T> void splitIn(ll, std::vector<_Tp>&)'
  413 | void splitIn(ll N, vector<T> &array)
      |      ^~~~~~~
a.cc:185:6: note: 'template<class T> void splitIn(ll, std::vector<_Tp>&)' previously declared here
  185 | void splitIn(ll N, vector<T> &array)
      |      ^~~~~~~
a.cc:433:8: error: redefinition of 'int main()'
  433 | signed main()
      |        ^~~~
a.cc:205:8: note: 'int main()' previously defined here
  205 | signed main()
      |        ^~~~