#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define PII pair<int,int>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define clr(c) c.clear()
#define pb push_back
#define mp make_pair
#define cin(x) scanf("%d",&x)
#define MOD 1000000007
#define EPS 1E-10
const LL maxval = MOD;
const int maxn = 300005;
vector<int> owner[maxn];
LL reqd[maxn];
int ql[maxn],qr[maxn];
LL qa[maxn];
int lo[maxn], hi[maxn];
vector<int> tocheck[maxn];
long long tree[maxn];
int n,m;
int k;
long long maxi=0;
void update(int x, long long val){
while(x<=m){
tree[x]+=val;
//[x]=min(tree[x],maxi);
x+=(x&-x);
}
}
long long read(int x){
long long s=0;
while(x>0){
s+=tree[x];
//s=min(tree[x],maxi);
x-=(x&-x);
}
return s;
}
void apply(int x){
if(ql[x]<=qr[x])
update(ql[x],qa[x]),update(qr[x]+1,-qa[x]);
else{
update(1,qa[x]);
update(qr[x]+1,-qa[x]);
update(ql[x],qa[x]);
}
}
int main()
{
cin(n);
cin(m);
for(int i = 1; i <= m; i++)
{
int x;
cin(x);
owner[x].pb(i);
}
for(int i = 1; i <= n; i++)
scanf("%lld",&reqd[i]);
cin(k);
for(int i = 1; i <= k; i++)
{
cin(ql[i]);
cin(qr[i]);
scanf("%lld",&qa[i]);
}
for(int i = 1; i <= n; i++)
{
lo[i] = 1;
hi[i] = k + 1;
}
bool changed = true;
while(changed)
{
changed = false;
// clean up mess.
for(int a = 0; a <= m; a++)
tree[a] = 0;
for(int i = 1; i <= n; i++)
if(lo[i] != hi[i])
tocheck[ (lo[i] + hi[i]) >> 1 ].pb(i);
// end of cleaning up
for(int q = 1; q <= k; q++)
{
apply(q);
while(sz(tocheck[q]))
{
changed = true;
int id = tocheck[q].back();
tocheck[q].pop_back();
LL sum = 0;
for(auto sectors: owner[id])
{
sum += read(sectors);
if(sum >= reqd[id]) break;
}
if(sum >= reqd[id])
hi[id] = q;
else
lo[id] = q + 1;
}
}
}
for(int i = 1; i <= n; i++)
{
assert(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