結果

問題 No.1008 Bench Craftsman
ユーザー ゆきのんゆきのん
提出日時 2020-03-10 06:22:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,783 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 175,880 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-04-27 18:30:15
合計ジャッジ時間 13,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1,304 ms
18,176 KB
testcase_06 RE -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 1,131 ms
18,048 KB
testcase_11 AC 1,179 ms
18,048 KB
testcase_12 AC 1,274 ms
18,176 KB
testcase_13 AC 1,284 ms
18,048 KB
testcase_14 AC 1,154 ms
18,048 KB
testcase_15 AC 95 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 96 ms
6,940 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n,m;cin >> n >> m;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<LL> x(m),w(m);
    bool fl = true;
    vector<LL> p(n,0);
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> w[i];
        x[i]--;
        p[x[i]] += w[i];
    }
    for (int i = 0; i < n; i++) {
        if(a[i] <= p[i]) fl = false;
    }
    if(not fl){
        puts("-1");
    }
    else if(*min_element(ALL(a)) > accumulate(ALL(w),0)){
        puts("0");
    }
    else{
        LL l = 0,r = INF;
        while(abs(r - l) > 1){
            LL c = (r + l) / 2;
            vector<vector<LL>> imosr(n+1,vector<LL> (3,0));
            vector<vector<LL>> imosl(n+1,vector<LL> (3,0));
            vector<LL> v(n,0);
            for (int i = 0; i < n; i++) {
                LL k = w[i] / c;
                imosr[x[i]][2] += w[i];
                imosr[x[i]+1][0] -= c;
                if(x[i] + k + 1<= n){
                    imosr[x[i]+k+1][0] += c;
                    imosr[x[i]+k+1][2] -= w[i]%c;
                }
                imosl[x[i]][2] += w[i];
                if(x[i] - 1 >= 0) imosl[x[i]-1][0] -= c;
                if(x[i] - k - 1 >= 0){
                    imosl[x[i]-k-1][0] += c;
                    imosl[x[i]-k-1][2] -= w[i]%c;
                }
                v[x[i]] -= w[i];
            }
            for (int i = 0; i < n; i++) {
                for (int j = 1; j < 3; j++) {
                    imosr[i][j] += imosr[i][j-1];
                    if(i) imosr[i][j] += imosr[i-1][j];
                }
            }
            for (int i = n-1; i >= 0; i--) {
                for (int j = 1; j < 3; j++) {
                    imosl[i][j] += imosl[i][j-1];
                    imosl[i][j] += imosl[i+1][j];
                }
            }
            for (int i = 0; i < n; i++) {
                v[i] += imosr[i][2] + imosl[i][2];
            }
            bool f = true;
            for (int i = 0; i < n; i++) {
                if(a[i] <= v[i]) f = false;
            }
            if(f) r = c;
            else l = c;
        }
        cout << r << endl;
    }
    return 0;
}
0