結果

問題 No.1008 Bench Craftsman
ユーザー StrorkisStrorkis
提出日時 2020-03-08 12:34:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,589 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 71,488 KB
実行使用メモリ 7,316 KB
最終ジャッジ日時 2024-04-24 15:38:59
合計ジャッジ時間 4,380 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 143 ms
7,056 KB
testcase_06 AC 40 ms
5,644 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 9 ms
5,376 KB
testcase_09 AC 79 ms
5,376 KB
testcase_10 AC 130 ms
7,056 KB
testcase_11 AC 119 ms
7,056 KB
testcase_12 AC 110 ms
7,052 KB
testcase_13 AC 126 ms
7,060 KB
testcase_14 AC 122 ms
7,056 KB
testcase_15 AC 119 ms
7,056 KB
testcase_16 AC 130 ms
7,180 KB
testcase_17 AC 119 ms
7,056 KB
testcase_18 WA -
testcase_19 AC 133 ms
7,184 KB
testcase_20 AC 45 ms
5,376 KB
testcase_21 AC 45 ms
5,376 KB
testcase_22 AC 72 ms
5,376 KB
testcase_23 AC 96 ms
5,888 KB
testcase_24 AC 84 ms
5,632 KB
testcase_25 AC 40 ms
5,376 KB
testcase_26 AC 32 ms
5,376 KB
testcase_27 AC 63 ms
5,376 KB
testcase_28 AC 68 ms
5,632 KB
testcase_29 AC 100 ms
6,528 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<ll> a(N); for (int i = 0; i < N; i++) cin >> a[i];
  vector<ll> x(M), w(M);
  ll maxw = 0;
  for (int j = 0; j < M; j++) {
    cin >> x[j] >> w[j]; x[j]--;
    maxw = (maxw, w[j]);
  }

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

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

      ft[max(0LL, 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++) {
      ll d = c ? w[j] / c : N;

      if (x[j] + 1 < N) {
        cd[max(1LL, 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++) {
      ll 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