#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long> 
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, m, q, t[MAX_N], x[MAX_N], y[MAX_N], memo[MAX_N][2];
map<int, int> ma;
vector<ll> ans;

P bit[MAX_N + 2][2];

P sum(int i, int j) {
    P s = P(0, 0);
    while (i > 0) {
        s.fi += bit[i][j].fi;
        s.se += bit[i][j].se;
        i -= i & -i;
    }
    return s;
}

void add(int i, int j, int x, int y) {
    while (i <= q + 1) {
        bit[i][j].fi += x;
        bit[i][j].se += y;
        i += i & -i;
    }
}

int main() {
    ci3(n, m, q);
    rep(i, q) {
        ci3(t[i], x[i], y[i]);
        ma.ep(y[i], 0);
    }
    ma.ep(0, 0);
    int cnt = 0;
    for (auto &i: ma) i.se = ++cnt;
    ans.epb(0);
    rep(i, n) add(1, 0, 1, 0);
    rep(i, m) add(1, 1, 1, 0);
    rep(i, q) {
        int old_y = memo[x[i] - 1][t[i] - 1];
        add(ma[y[i]], t[i] - 1, 1, y[i]);
        add(ma[old_y], t[i] - 1, -1, -old_y);
        P p1 = sum(ma[y[i]] - t[i] % 2, t[i] % 2);
        P p2 = sum(ma[old_y] - t[i] % 2, t[i] % 2);
        ll tmp = ans.back();
        tmp += scll(p1.fi) * y[i] - scll(p2.fi) * old_y; 
        tmp += p2.se - p1.se;
        ans.epb(tmp);
        memo[x[i] - 1][t[i] - 1] = y[i];
    }
    rep(i, q) co(ans[i + 1]);
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <cassert>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define ALL(a) (a).begin(),(a).end()
#define ALL2(a, n) (a),(a)+(n)
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n,-1) {}
  void init(int n) { par.assign(n,-1); }
  //木の根であれば連結する頂点数×(-1),そうでなければ親ノードのID
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x==y) return;//既に連結
    
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return -par[root(x)];
  }
};
ll mm[200010];
vector<ll> edge[200010];
ll a[LIMIT2]={0};
vector<bool> visited(200010,false);
ll dfs(ll i){
  if(visited[i]==true) return mm[i];
  visited[i] = true;
  ll j;
  ll res=-LLINF;
  rep(j,edge[i].size()){
    res = max(res,dfs(edge[i][j]));
    res = max(res,a[edge[i][j]]);
  }
  mm[i] = res;
  return res;
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,x,y;
  string s;
  
  cin >> n >> m;
  rep(i,n) cin >> a[i];
  rep(i,m){
    cin >> x >> y;
    x--;y--;
    edge[x].push_back(y);
  }
  rep(i,n){
    dfs(i);
  }
  result = -LLINF;
  rep(i,n){
    result = max(result,mm[i]-a[i]);
  }
  cout << result << endl;
  return 0;
}
