結果

問題 No.1008 Bench Craftsman
ユーザー StrorkisStrorkis
提出日時 2020-03-08 13:01:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,596 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 72,800 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-24 16:07:53
合計ジャッジ時間 3,327 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 82 ms
5,888 KB
testcase_06 AC 33 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 39 ms
5,376 KB
testcase_10 AC 78 ms
6,144 KB
testcase_11 AC 79 ms
5,888 KB
testcase_12 AC 79 ms
5,888 KB
testcase_13 AC 81 ms
5,888 KB
testcase_14 AC 80 ms
6,016 KB
testcase_15 AC 68 ms
5,888 KB
testcase_16 AC 74 ms
6,144 KB
testcase_17 AC 72 ms
6,016 KB
testcase_18 AC 71 ms
5,888 KB
testcase_19 AC 73 ms
6,016 KB
testcase_20 AC 30 ms
5,376 KB
testcase_21 AC 29 ms
5,376 KB
testcase_22 AC 45 ms
5,376 KB
testcase_23 AC 58 ms
5,376 KB
testcase_24 AC 55 ms
5,376 KB
testcase_25 AC 31 ms
5,376 KB
testcase_26 AC 24 ms
5,376 KB
testcase_27 AC 37 ms
5,376 KB
testcase_28 AC 44 ms
5,376 KB
testcase_29 AC 66 ms
5,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

  int N, M; cin >> N >> M;
  vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i];
  vector<int> x(M), w(M);
  int maxw = 0;
  for (int j = 0; j < M; j++) {
    cin >> x[j] >> w[j]; x[j]--;
    maxw = max(maxw, w[j]);
  }

  int left = 0, right = maxw+1;
  while (left < right) {
    int c = (left + right) / 2;

    vector<ll> ft(N);
    for (int j = 0; j < M; j++) {
      int d = c ? w[j] / c : N;

      ft[max(0, x[j] - d)] += w[j];
      if (x[j] + d + 1 < N)
        ft[x[j] + d + 1] -= w[j];
    }
    for (int i = 1; i < N; i++) ft[i] += ft[i-1];

    vector<ll> cd(N);
    for (int j = 0; j < M; j++) {
      int d = c ? w[j] / c : N;

      if (x[j] + 1 < N) {
        cd[max(1, x[j] - d + 1)] += c;
        cd[x[j] + 1] -= c;
      }

      if (x[j] + 1 < N)
        cd[x[j] + 1] -= c;
      if (x[j] + d + 1 < N)
        cd[x[j] + d + 1] += c;
    }
    for (int i = 1; i < N; i++) cd[i] += cd[i-1];

    for (int j = 0; j < M; j++) {
      int d = c ? w[j] / c : N;

      if (x[j] - d < 0)
        cd[0] -= x[j] * c;
      else
        cd[x[j] - d] -= d * c;

      if (x[j] + d + 1 < N)
        cd[x[j] + d + 1] += d * c;
    }
    for (int i = 1; i < N; i++) cd[i] += cd[i-1];

    bool flag = false;
    for (int i = 0; i < N; i++) {
      if (a[i] <= ft[i] + cd[i]) {
        flag = true;
        break;
      }
    }
    if (flag)
      left = c + 1;
    else
      right = c;
  }

  cout << (left < maxw+1 ? left : -1) << "\n";
}
0