#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,M; ll A[101010]; ll B[101010]; int X[101010]; ll Y[101010]; ll LD[101010]; ll RD[101010]; ll LS[101010]; ll RS[101010]; ll S[101010]; int ok(ll c) { int i; ZERO(LD); ZERO(RD); ZERO(S); ZERO(LS); ZERO(RS); if(c==0) { ll sum=0; FOR(i,M) sum+=Y[i]; FOR(i,N) if(A[i+1]=1;i--) { d+=LD[i]*c; s+=d; B[i]-=s; s+=LS[i]*c; } FOR(i,N) if(B[i+1]>=A[i+1]) return 0; return 1; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; ll sum=0; FOR(i,N) { cin>>A[i+1]; } FOR(i,M) { cin>>X[i]>>Y[i]; B[X[i]]+=Y[i]; } FOR(i,N) if(B[i+1]>A[i+1]) return _P("-1\n"); ll ret=(1LL<<30)-1; for(i=29;i>=0;i--) if(ok(ret-(1<