結果

問題 No.1008 Bench Craftsman
ユーザー CinnamorollCinnamoroll
提出日時 2019-04-09 03:19:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 6,712 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 167,644 KB
実行使用メモリ 9,500 KB
最終ジャッジ日時 2024-04-22 03:40:39
合計ジャッジ時間 5,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,504 KB
testcase_01 AC 4 ms
5,760 KB
testcase_02 AC 4 ms
5,632 KB
testcase_03 AC 4 ms
5,632 KB
testcase_04 AC 4 ms
5,760 KB
testcase_05 AC 147 ms
9,376 KB
testcase_06 AC 65 ms
9,376 KB
testcase_07 AC 4 ms
5,760 KB
testcase_08 AC 6 ms
5,760 KB
testcase_09 AC 46 ms
5,760 KB
testcase_10 AC 140 ms
9,372 KB
testcase_11 AC 142 ms
9,372 KB
testcase_12 AC 141 ms
9,372 KB
testcase_13 AC 133 ms
9,372 KB
testcase_14 AC 137 ms
9,372 KB
testcase_15 AC 137 ms
9,360 KB
testcase_16 AC 138 ms
9,368 KB
testcase_17 AC 134 ms
9,500 KB
testcase_18 AC 138 ms
9,376 KB
testcase_19 AC 138 ms
9,372 KB
testcase_20 AC 54 ms
7,948 KB
testcase_21 AC 50 ms
7,436 KB
testcase_22 AC 60 ms
6,544 KB
testcase_23 AC 92 ms
7,952 KB
testcase_24 AC 87 ms
7,440 KB
testcase_25 AC 62 ms
8,832 KB
testcase_26 AC 45 ms
7,952 KB
testcase_27 AC 46 ms
6,300 KB
testcase_28 AC 77 ms
8,448 KB
testcase_29 AC 111 ms
8,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
const double EPS = 1e-9;
#define INF (1LL<<60)
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

const int MAX = 1e5;
int n,m;
vec a(MAX),r(MAX),s(MAX);

bool check(int mid){
  vec sum(n+1,0),wL(n+1,0),wR(n+1,0),Lcnt(n+1,0),Rcnt(n+1,0);
  REP(i,m){
    int dist = s[i]/mid;
    int L = max(0LL,r[i]-dist), R = min(n-1,r[i]+dist);
    sum[L] += s[i];
    sum[R+1] -= s[i];

    if(r[i] != 0) wL[r[i]-1]++;
    if(L != 0) wL[L-1]--, Lcnt[L-1] -= dist;

    if(r[i] != n-1) wR[r[i]+1]++;
    if(R != n-1) wR[R+1]--, Rcnt[R+1] -= dist;
  }

  REP(i,n) sum[i+1] += sum[i];
  REP(i,n) wR[i+1] += wR[i];
  RREP(i,n) wL[i] += wL[i+1];

  REP(i,n+1) wL[i] += Lcnt[i], wR[i] += Rcnt[i];
  REP(i,n) wR[i+1] += wR[i];
  RREP(i,n) wL[i] += wL[i+1];

  REP(i,n) if(a[i] <= sum[i]-(wL[i]+wR[i])*mid) return false;
  return true;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int tmp = 0, mn = INF;

  cin >> n >> m;
  REP(i,n) cin >> a[i], mn = min(mn,a[i]);
  REP(i,m) cin >> r[i] >> s[i], r[i]--, tmp += s[i];

  if(mn > tmp){
    cout << 0 << endl;
    return 0;
  }

  int ng = 0, ok = MAX+1;
  while (abs(ng-ok)>1) {
    int mid = (ng+ok)/2;
    (check(mid)?ok:ng) = mid;
  }

  if(ok == MAX+1) cout << -1 << endl;
  else cout << ok << endl;

  return 0;
}
0