結果

問題 No.1008 Bench Craftsman
ユーザー ngtkanangtkana
提出日時 2020-04-09 09:48:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,383 bytes
コンパイル時間 3,304 ms
コンパイル使用メモリ 204,900 KB
実行使用メモリ 6,248 KB
最終ジャッジ日時 2023-09-28 21:10:38
合計ジャッジ時間 9,385 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 236 ms
6,240 KB
testcase_06 AC 46 ms
4,872 KB
testcase_07 WA -
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 174 ms
4,664 KB
testcase_10 AC 233 ms
6,244 KB
testcase_11 AC 232 ms
6,232 KB
testcase_12 AC 235 ms
6,244 KB
testcase_13 AC 236 ms
6,144 KB
testcase_14 AC 233 ms
6,232 KB
testcase_15 AC 225 ms
6,164 KB
testcase_16 AC 232 ms
6,204 KB
testcase_17 AC 227 ms
6,148 KB
testcase_18 WA -
testcase_19 AC 230 ms
6,248 KB
testcase_20 AC 63 ms
4,380 KB
testcase_21 AC 75 ms
4,376 KB
testcase_22 AC 149 ms
4,608 KB
testcase_23 AC 172 ms
5,352 KB
testcase_24 AC 179 ms
5,240 KB
testcase_25 AC 48 ms
4,568 KB
testcase_26 AC 38 ms
4,504 KB
testcase_27 AC 126 ms
4,396 KB
testcase_28 AC 110 ms
5,040 KB
testcase_29 AC 193 ms
5,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#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::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--;
    }
    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(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<n;i++){
            if(a.at(i)<b.at(i))return false;
        }
        return true;
    };
    lint inf=std::numeric_limits<lint>::max()/3;
    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';
}
0