結果

問題 No.1008 Bench Craftsman
ユーザー CinnamorollCinnamoroll
提出日時 2019-04-09 03:19:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 6,708 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 167,224 KB
実行使用メモリ 9,500 KB
最終ジャッジ日時 2024-04-22 03:41:48
合計ジャッジ時間 8,241 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
5,632 KB
testcase_02 AC 3 ms
5,632 KB
testcase_03 AC 3 ms
5,632 KB
testcase_04 AC 3 ms
5,632 KB
testcase_05 AC 312 ms
9,372 KB
testcase_06 AC 152 ms
9,392 KB
testcase_07 AC 4 ms
5,632 KB
testcase_08 AC 5 ms
5,632 KB
testcase_09 AC 104 ms
5,760 KB
testcase_10 AC 310 ms
9,372 KB
testcase_11 AC 306 ms
9,492 KB
testcase_12 AC 304 ms
9,372 KB
testcase_13 AC 303 ms
9,372 KB
testcase_14 AC 310 ms
9,408 KB
testcase_15 AC 305 ms
9,368 KB
testcase_16 AC 321 ms
9,496 KB
testcase_17 AC 315 ms
9,500 KB
testcase_18 AC 316 ms
9,372 KB
testcase_19 AC 322 ms
9,500 KB
testcase_20 AC 128 ms
7,952 KB
testcase_21 AC 122 ms
7,308 KB
testcase_22 AC 146 ms
6,540 KB
testcase_23 AC 229 ms
8,080 KB
testcase_24 AC 211 ms
7,316 KB
testcase_25 AC 154 ms
8,832 KB
testcase_26 AC 114 ms
7,952 KB
testcase_27 AC 109 ms
6,168 KB
testcase_28 AC 185 ms
8,448 KB
testcase_29 AC 266 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 = INF;
  while (abs(ng-ok)>1) {
    int mid = (ng+ok)/2;
    (check(mid)?ok:ng) = mid;
  }

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

  return 0;
}
0