#include #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n,m;std::cin>>n>>m; std::vectora(n); for(lint&x:a)std::cin>>x; std::vector>xw(m); for(auto&&[x,w]:xw){ std::cin>>x>>w;x--; } auto ok=[&](lint c){ if(c==0){ lint sum=0; for(auto&&[x,w]:xw)sum+=w; return std::all_of(ALL(a),[sum](lint x){return sum<=x;}); } std::vectorb(n+1); for(auto&&[x,w]:xw){ lint q=w/c; b.at(std::max(0ll,x-q)+1)+=c; b.at(x+1)-=2*c; if(x+q+1<=n)b.at(x+q+1)+=c; } std::partial_sum(ALL(b),b.begin()); for(auto&&[x,w]:xw){ lint q=w/c,r=w%c; b.at(std::max(0ll,x-q))+=r+c*std::max(0ll,q-x); if(x+q+1<=n)b.at(x+q+1)-=r; } std::partial_sum(ALL(b),b.begin()); for(lint i=0;i::max()/3; lint l=-1,r=inf; while(1