結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-06 23:56:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 1,365 bytes |
| コンパイル時間 | 2,184 ms |
| コンパイル使用メモリ | 193,024 KB |
| 最終ジャッジ日時 | 2025-01-09 05:40:08 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%lld", a + i);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d%lld", x + i, w + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 2e5 + 3;
int n, m, x[maxn];
ll a[maxn], w[maxn];
ll ceildiv(ll a, ll b) {
return a % b ? a / b + 1 : a / b;
}
ll pt[maxn][2];
bool check(ll c) {
if(c <= 0) {
return std::accumulate(w, w + m, 0ll) <= *std::min_element(a + 1, a + n + 1);
}
for(int i = 1; i <= n + 1; ++i)
pt[i][0] = pt[i][1] = 0;
for(int j = 0; j < m; ++j) {
ll u = w[j] / c + x[j];
ll v = x[j] - w[j] / c;
pt[std::max(1ll, v)][0] += c;
pt[std::max(1ll, v)][1] += w[j] - c * x[j];
pt[x[j]][0] += -c - c;
pt[x[j]][1] += w[j] + c * x[j] - (w[j] - c * x[j]);
pt[std::min(n + 1ll, u + 1)][0] += c;
pt[std::min(n + 1ll, u + 1)][1] += -(w[j] + c * x[j]);
}
ll u = 0, v = 0;
for(int i = 1; i <= n; ++i) {
u += pt[i][0];
v += pt[i][1];
if(u * (ll)i + v >= a[i])
return false;
}
return true;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
scanf("%lld", a + i);
for(int i = 0; i < m; ++i)
scanf("%d%lld", x + i, w + i);
ll l = -1, r = 1e10;
while(r - l > 1) {
ll mid = (l + r) / 2;
if(check(mid))
r = mid;
else
l = mid;
}
printf("%lld\n", r < 1e10 ? r : -1);
return 0;
}