結果

問題 No.1008 Bench Craftsman
ユーザー StrorkisStrorkis
提出日時 2020-03-07 09:28:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 69,876 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-22 12:27:03
合計ジャッジ時間 2,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_06 AC 18 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 4 ms
5,376 KB
testcase_09 WA -
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 16 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 18 ms
5,376 KB
testcase_26 AC 13 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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> v(N), w(M);
  for (int i = 0; i < M; i++) {
    int x; cin >> x >> w[i]; x--;
    v[x]++;
  }

  ll sow = 0;
  for (int i = 0; i < M; i++) sow += w[i];
  for (int i = 0; i < N; i++) a[i] = max(0LL, sow - a[i]);

  ll left = 0, right = 0, col = 0, cor = 0;
  for (int i = 1; i < N; i++) {
    cor += v[i];
    right += v[i] * i;
  }

  ll ans = 0;
  if (a[0] != 0) {
    if (right == 0) {
      cout << -1 << "\n";
      return 0;
    }
    ans = (a[0]+right-1) / right;
  }
  
  for (int i = 1; i < N; i++) {
    col += v[i-1];
    left += col;
    right -= cor;
    cor -= v[i];
    if (a[i] == 0) continue;
    if (left + right == 0) {
      cout << -1 << "\n";
      return 0;
    }
    ans = max(ans, (a[i]+left+right-1) / (left+right));
  }
  cout << ans << "\n";
}
0