結果
問題 | No.1008 Bench Craftsman |
ユーザー | Mayimg |
提出日時 | 2020-03-07 02:57:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 2,847 bytes |
コンパイル時間 | 1,967 ms |
コンパイル使用メモリ | 201,628 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-10-14 11:06:55 |
合計ジャッジ時間 | 6,068 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
11,392 KB |
testcase_01 | AC | 4 ms
7,424 KB |
testcase_02 | AC | 23 ms
11,392 KB |
testcase_03 | AC | 28 ms
11,392 KB |
testcase_04 | AC | 29 ms
11,264 KB |
testcase_05 | AC | 148 ms
12,928 KB |
testcase_06 | AC | 50 ms
11,520 KB |
testcase_07 | AC | 24 ms
11,392 KB |
testcase_08 | AC | 6 ms
7,424 KB |
testcase_09 | AC | 119 ms
12,928 KB |
testcase_10 | AC | 148 ms
12,928 KB |
testcase_11 | AC | 149 ms
12,928 KB |
testcase_12 | AC | 149 ms
12,928 KB |
testcase_13 | AC | 142 ms
12,800 KB |
testcase_14 | AC | 149 ms
12,800 KB |
testcase_15 | AC | 112 ms
12,928 KB |
testcase_16 | AC | 139 ms
12,928 KB |
testcase_17 | AC | 112 ms
12,800 KB |
testcase_18 | AC | 157 ms
12,800 KB |
testcase_19 | AC | 145 ms
12,800 KB |
testcase_20 | AC | 62 ms
11,776 KB |
testcase_21 | AC | 66 ms
11,904 KB |
testcase_22 | AC | 103 ms
12,416 KB |
testcase_23 | AC | 116 ms
12,544 KB |
testcase_24 | AC | 126 ms
12,672 KB |
testcase_25 | AC | 52 ms
11,392 KB |
testcase_26 | AC | 46 ms
11,520 KB |
testcase_27 | AC | 93 ms
12,416 KB |
testcase_28 | AC | 98 ms
12,160 KB |
testcase_29 | AC | 129 ms
12,544 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; constexpr long long INF = 1LL << 60; constexpr int geta = 2e5; constexpr int N = 505050, M = 101010; long long a[N], x[M], w[M]; long long imos[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; fill(a, a + N, INF); for (int i = 1; i <= n; i++) cin >> a[i + geta]; long long sum = 0; for (int i = 0; i < m; i++) { cin >> x[i] >> w[i]; x[i] += geta; sum += w[i]; } bool zero = true; for (int i = 0; i < N; i++) { if (a[i] <= sum) zero = false; } if (zero) { cout << 0 << endl; return 0; } auto judge = [&] (long long d) { for (int i = 0; i < N; i++) imos[i] = 0; for (int i = 0; i < m; i++) { long long pos_fi = x[i] - w[i] / d; long long pos_la = x[i]; if (pos_fi < pos_la) { imos[pos_fi + 1] += d; } if (pos_fi < pos_la) { imos[pos_la + 1] -= d; } } for (int i = 0; i < m; i++) { long long fi = max(0LL, w[i] - d); long long pos_fi = x[i] + 1; long long pos_la = x[i] + 1 + fi / d; if (pos_fi < pos_la) { imos[pos_fi + 1] += -d; } if (pos_fi < pos_la) { imos[pos_la + 1] -= -d; } } // cerr << d << endl; // for (int i = 0; i <= n; i++) cerr << imos[i + geta] << " "; // cerr << endl; for (int i = 1; i < N; i++) imos[i] += imos[i - 1]; // cerr << d << endl; // for (int i = 0; i <= n; i++) cerr << imos[i + geta] << " "; // cerr << endl; for (int i = 0; i < m; i++) { long long fi = w[i] % d; long long pos_fi = x[i] - w[i] / d; long long pos_la = x[i]; imos[pos_fi] += fi; imos[pos_la + 1] -= fi; if (pos_fi < pos_la) { imos[pos_la + 1] -= d * (pos_la - pos_fi); } } // cerr << d << endl; // for (int i = 0; i <= n; i++) cerr << imos[i + geta] << " "; // cerr << endl; for (int i = 0; i < m; i++) { long long fi = max(0LL, w[i] - d); long long pos_fi = x[i] + 1; long long pos_la = x[i] + 1 + fi / d; imos[pos_fi] += fi; imos[pos_la + 1] -= fi; if (pos_fi < pos_la) { imos[pos_la + 1] -= -d * (pos_la - pos_fi); } } // cerr << d << endl; // for (int i = 0; i <= n; i++) cerr << imos[i + geta] << " "; // cerr << endl; for (int i = 1; i < N; i++) imos[i] += imos[i - 1]; // cerr << d << endl; // for (int i = 0; i <= n; i++) cerr << imos[i + geta] << " "; // cerr << endl; for (int i = 0; i < N; i++) { if (a[i] <= imos[i]) return false; } return true; }; long long lo = 0, hi = 2e5; while (hi - lo > 1) { long long mid = (lo + hi) >> 1; if (judge(mid)) hi = mid; else lo = mid; } cout << (hi == 2e5 ? -1 : hi) << endl; return 0; }