結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-06 23:32:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,442 bytes |
| コンパイル時間 | 2,765 ms |
| コンパイル使用メモリ | 206,788 KB |
| 最終ジャッジ日時 | 2025-01-09 05:37:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 2 TLE * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%lld", a + i);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:47:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | 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;
}
std::vector<std::tuple<int, ll, ll>> pt;
bool check(ll c) {
if(c <= 0) {
return std::accumulate(w, w + m, 0ll) <= *std::min_element(a + 1, a + n + 1);
}
pt.clear();
for(int j = 0; j < m; ++j) {
ll u = w[j] / c + x[j];
ll v = x[j] - w[j] / c;
pt.emplace_back(v, c, w[j] - c * x[j]);
pt.emplace_back(x[j], -c, -(w[j] - c * x[j]) + w[j]);
pt.emplace_back(x[j] + 1, -c, w[j] + c * x[j] - w[j]);
pt.emplace_back(u + 1, c, -(w[j] + c * x[j]));
}
std::sort(pt.begin(), pt.end());
int j = 0;
ll u = 0, v = 0;
for(int i = 1; i <= n; ++i) {
while(j < pt.size() && std::get<0>(pt[j]) <= i) {
u += std::get<1>(pt[j]);
v += std::get<2>(pt[j]);
j += 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 = 1e18;
while(r - l > 1) {
ll mid = (l + r) / 2;
if(check(mid))
r = mid;
else
l = mid;
}
printf("%lld\n", r < 1e18 ? r : -1);
return 0;
}