#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b a; vector> w(100001); bool f(ll c){ vector cost(n,0); // dec { vector> in(n); vector> out(n); ll sum=0,cnt=0; rep(i,n){ for(auto x:w[i]){ in[i].push_back(x); out[min(n-1,i+(int)(x/c))].push_back(x%c); } } rep(i,n){ for(auto x:in[i]){ sum+=x; cnt++; } cost[i]+=sum; for(auto x:out[i]){ cnt--; sum-=x; } sum-=c*cnt; } } //inc { vector> in(n); vector> out(n); ll sum=0,cnt=0; rep(i,n){ for(auto x:w[i]){ in[i].push_back(x); out[max(0,i-(int)(x/c))].push_back(x%c); } } for(int i=n-1;i>=0;i--){ for(auto x:in[i]){ sum+=x; cnt++; } cost[i]+=sum; for(auto x:out[i]){ cnt--; sum-=x; } sum-=c*cnt; } } // cout<a[i]){ // cout<>n>>m; a.resize(n);w.resize(n); rep(i,n) cin>>a[i]; rep(i,m){ int j,x;cin>>j>>x;j--; w[j].push_back(x); } rep(i,n){ ll sum=0; for(auto x:w[i]) sum+=x; if(sum>a[i]){ cout<<-1<=sum){ cout<<0<