結果

問題 No.1008 Bench Craftsman
ユーザー StrorkisStrorkis
提出日時 2020-03-08 12:23:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,593 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 72,296 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-24 15:28:17
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 88 ms
6,016 KB
testcase_06 AC 35 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 45 ms
5,376 KB
testcase_10 AC 78 ms
5,888 KB
testcase_11 AC 73 ms
5,888 KB
testcase_12 AC 70 ms
5,888 KB
testcase_13 AC 78 ms
5,888 KB
testcase_14 AC 75 ms
6,016 KB
testcase_15 AC 77 ms
5,888 KB
testcase_16 AC 81 ms
5,888 KB
testcase_17 AC 75 ms
6,016 KB
testcase_18 WA -
testcase_19 AC 82 ms
5,888 KB
testcase_20 AC 35 ms
5,376 KB
testcase_21 AC 34 ms
5,376 KB
testcase_22 AC 48 ms
5,376 KB
testcase_23 AC 63 ms
5,376 KB
testcase_24 AC 56 ms
5,376 KB
testcase_25 AC 34 ms
5,376 KB
testcase_26 AC 27 ms
5,376 KB
testcase_27 AC 41 ms
5,376 KB
testcase_28 AC 48 ms
5,376 KB
testcase_29 AC 67 ms
5,548 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 = (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