結果

問題 No.1008 Bench Craftsman
ユーザー StrorkisStrorkis
提出日時 2020-03-08 11:31:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,890 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 72,648 KB
実行使用メモリ 6,032 KB
最終ジャッジ日時 2024-04-24 14:20:51
合計ジャッジ時間 4,805 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 WA -
testcase_04 WA -
testcase_05 AC 85 ms
6,016 KB
testcase_06 AC 34 ms
6,016 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 30 ms
5,376 KB
testcase_21 AC 30 ms
5,376 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 32 ms
5,444 KB
testcase_26 AC 25 ms
5,376 KB
testcase_27 RE -
testcase_28 AC 43 ms
5,376 KB
testcase_29 AC 59 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(N), w(N);
  int maxw = 0;
  for (int j = 0; j < M; j++) {
    cin >> x[j] >> w[j]; x[j]--;
    maxw = (maxw, w[j]);
  }

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

    if (c == 0) {
      ll sumw = 0;
      for (int j = 0; j < M; j++) sumw += w[j];
      bool flag = false;
      for (int i = 0; i < N; i++) {
        if (a[i] <= sumw) {
          flag = true;
          break;
        }
      }
      if (flag)
        left = c + 1;
      else
        right = c;
      continue;
    }

    vector<ll> ft(N);
    for (int j = 0; j < M; j++) {
      ft[max(0, x[j] - w[j]/c)] += w[j];
      if (x[j] + w[j]/c + 1 < N)
        ft[x[j] + w[j]/c + 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++) {
      cd[max(0, x[j] - w[j]/c)] += c;
      cd[x[j]] -= c;

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

    for (int j = 0; j < M; j++) {
      if (w[j]/c == 0) continue;

      if (x[j] - w[j]/c < 0)
        cd[0] -= x[j] ? (x[j] + 1) * c : 0;
      else
        cd[x[j] - w[j]/c] -= (w[j]/c + 1) * c;

      if (x[j] + w[j]/c + 1 < N)
        cd[x[j] + w[j]/c + 1] += w[j]/c * 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