結果

問題 No.1008 Bench Craftsman
ユーザー 👑 jupirojupiro
提出日時 2020-03-08 16:23:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,552 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 118,536 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2024-04-24 22:45:37
合計ジャッジ時間 7,154 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 204 ms
9,604 KB
testcase_06 AC 99 ms
8,192 KB
testcase_07 WA -
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 65 ms
5,376 KB
testcase_10 AC 221 ms
9,476 KB
testcase_11 AC 215 ms
9,480 KB
testcase_12 AC 206 ms
9,604 KB
testcase_13 AC 216 ms
9,480 KB
testcase_14 AC 206 ms
9,600 KB
testcase_15 AC 200 ms
9,604 KB
testcase_16 AC 211 ms
9,476 KB
testcase_17 AC 210 ms
9,476 KB
testcase_18 WA -
testcase_19 AC 210 ms
9,480 KB
testcase_20 AC 81 ms
6,424 KB
testcase_21 AC 76 ms
6,144 KB
testcase_22 AC 90 ms
5,888 KB
testcase_23 AC 137 ms
7,552 KB
testcase_24 AC 130 ms
7,040 KB
testcase_25 AC 98 ms
7,552 KB
testcase_26 AC 71 ms
6,400 KB
testcase_27 AC 69 ms
5,376 KB
testcase_28 AC 121 ms
7,560 KB
testcase_29 AC 167 ms
8,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll n, m;
vector<ll> a, x, w;

bool check(ll mid) {
	vector<ll> sum(n + 5), L(n + 5), R(n + 5), Lcnt(n + 5), Rcnt(n + 5);
	for (int i = 0; i < m; i++) {
		ll d = w[i] / mid;
		ll left = max(0LL, x[i] - d);
		ll right = min(n - 1, x[i] + d);
		sum[left] += w[i];
		sum[right + 1] -= w[i];
		if (x[i] != 0) L[x[i] - 1]++;
		if (left != 0) L[left - 1]--, Lcnt[left - 1] -= d;
		R[x[i] + 1]++;
		R[right + 1]--, Rcnt[right + 1] -= d;
	}
	for (int i = 0; i <= n; i++) sum[i + 1] += sum[i];
	for (int i = n; i >= 0; i--) L[i] += L[i + 1];
	for (int i = 0; i <= n; i++) R[i + 1] += R[i];
	for (int i = 0; i <= n; i++) L[i] += Lcnt[i], R[i] += Rcnt[i];
	for (int i = n; i >= 0; i--) L[i] += L[i + 1];
	for (int i = 0; i <= n; i++) R[i + 1] += R[i];
	for (int i = 0; i <= n; i++) sum[i] -= (L[i] + R[i]) * mid;
	for (ll i = 0; i < n; i++) {
		//cout << mid << " " << sum[i] << " " << a[i] << endl;
		if (sum[i] > a[i]) return false;
	}
	return true;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	scanf("%lld %lld", &n, &m);
	a.resize(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	ll sum = 0;
	x.resize(m), w.resize(m); for (int i = 0; i < m; i++) scanf("%lld %lld", &x[i], &w[i]), x[i]--, sum += w[i];
	bool flag = true;
	for (int i = 0; i < n; i++) if (a[i] < sum) flag = false;
	if (flag) {
		puts("0");
		return 0;
	}
	ll left = 0;
	ll right = mod;
	while (right - left > 1) {
		ll mid = (left + right) >> 1;
		if (check(mid)) right = mid;
		else left = mid;
	}
	if (right == mod) right = -1;
	cout << right << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0