結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 879 ms
18,048 KB
testcase_06 AC 357 ms
16,640 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 124 ms
6,940 KB
testcase_10 AC 839 ms
18,088 KB
testcase_11 AC 803 ms
18,048 KB
testcase_12 AC 822 ms
18,048 KB
testcase_13 AC 844 ms
18,176 KB
testcase_14 AC 820 ms
18,176 KB
testcase_15 AC 79 ms
6,940 KB
testcase_16 AC 683 ms
18,176 KB
testcase_17 AC 82 ms
6,944 KB
testcase_18 AC 764 ms
18,156 KB
testcase_19 AC 692 ms
18,048 KB
testcase_20 AC 288 ms
11,648 KB
testcase_21 AC 251 ms
10,056 KB
testcase_22 AC 274 ms
8,072 KB
testcase_23 AC 491 ms
12,996 KB
testcase_24 AC 382 ms
11,008 KB
testcase_25 AC 355 ms
14,812 KB
testcase_26 AC 260 ms
11,932 KB
testcase_27 AC 204 ms
6,940 KB
testcase_28 AC 425 ms
13,524 KB
testcase_29 AC 647 ms
15,504 KB
権限があれば一括ダウンロードができます

ソースコード

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),0LL)){
        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 < m; 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