b数组卡memset超时
scanf 比IO cin cout 快4倍
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=6e5+5;
const ll mod=1e9+7;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll n,m,ans,cnt;
ll a[maxn],b[maxn],minn=2e9;
ll T,x,y,res;
bool flag;
int main(){
scanf("%lld",&T);
while(T--){
res=0;
flag=true;
for(int i=1;i<=n;i++)
b[i]=0;//忍耐度为1-n对应的能量值
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",a+i);
}
scanf("%lld",&m);
while(m--){
scanf("%lld %lld",&x,&y);
b[y]=max(x,b[y]);
}
for(int i=n;i>=1;i--){
b[i]=max(b[i],b[i+1]);//相同忍耐度的最大能量值 并且延续上一个忍耐度来的最大能力值
}
ll pos=1,npos=1,mx=0;
while(pos<=n){
res++;//第几天
npos=pos;
mx=0;
while(true){
mx=max(mx,a[npos]);
if(mx>b[npos-pos+1]) break;//n个忍耐度的最大能力值都大
npos++;
}
if(pos==npos)
{
flag=false;
break;
}
pos=npos;
}
if(!flag)
printf("-1\n");
else
printf("%lld\n",res);
}
return 0;
}