#include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;} template bool chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } ostream &operator<<(ostream &os, pair&p){ return os << p.first << " " << p.second; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll n,m;cin>>n>>m; vectora(n); rep(i,0,n)cin>>a[i]; vectorx(m),w(m); rep(i,0,m){ cin>>x[i]>>w[i];x[i]--; } vector>g(n); rep(i,0,m){ g[x[i]].PB(i); } ll le=-1,ri=INF; while(ri-le>=2){ ll mid=(le+ri)/2; vectormx(n); ll nowa=0,nowb=0; vector>in(n),out(n); rep(i,0,m){ ll k; if(mid==0)k==INF; else k=w[i]/mid; in[max(0LL,x[i]-k)].PB(i); out[min(n-1,x[i]+k)].PB(i); } rep(i,0,n){ for(auto k:in[i]){ nowa+=mid,nowb+=-mid*x[k]+w[k]; } for(auto k:g[i]){ nowa-=2*mid,nowb+=2*mid*x[k]; } //cout<=a[i])sw=false; if(sw)ri=mid; else le=mid; } //cout<<"上限を直す"<