結果
問題 | No.1008 Bench Craftsman |
ユーザー |
![]() |
提出日時 | 2020-04-09 09:56:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,585 bytes |
コンパイル時間 | 3,141 ms |
コンパイル使用メモリ | 199,904 KB |
最終ジャッジ日時 | 2025-01-09 15:18:46 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 3 |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; void cmx(lint&x,lint y){if(x<y)x=y;} 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 inf=std::numeric_limits<lint>::max()/3; lint n,m;std::cin>>n>>m; std::vector<lint>a(n); for(lint&x:a)std::cin>>x; std::vector<std::pair<lint,lint>>xw(m); for(auto&&[x,w]:xw){ std::cin>>x>>w;x--; } { lint wmax=0; for(auto&&[x,w]:xw)cmx(wmax,w); for(auto&&[x,w]:xw)x+=wmax; std::vector<lint>swp(n+2*wmax,inf); std::copy(ALL(a),swp.begin()+wmax); n+=2*wmax; swp.swap(a); } 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::vector<lint>b(n+1); for(auto&&[x,w]:xw){ lint q=w/c; b.at(x-q+1)+=c; b.at(x+1)-=2*c; 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(x-q)+=r; b.at(x+q+1)-=r; } std::partial_sum(ALL(b),b.begin()); for(lint i=0;i<n;i++){ if(a.at(i)<b.at(i))return false; } return true; }; lint l=-1,r=inf; while(1<r-l){ lint c=(l+r)/2; (ok(c)?r:l)=c; } std::cout<<(r==inf?-1:r)<<'\n'; }