結果

問題 No.1008 Bench Craftsman
ユーザー startcppstartcpp
提出日時 2020-03-06 22:54:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,101 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 65,140 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 10:04:27
合計ジャッジ時間 4,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//TLE解
#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int a[100000];
int x[100000], w[100000];

//区間[l, r)にa, a+d, a+2d, …を足す
void add(int s[], int l, int r, int a, int d) {
	for (int i = l; i < r; i++) {
		s[i] += a;
		a += d;
	}
}

bool check(int c) {
	int i;
	static int s[100000];
	
	rep(i, n) s[i] = 0;
	
	if (c == 0) {
		int sw = 0;
		rep(i, m) sw += w[i];
		rep(i, n) if (sw >= a[i]) return false;
		return true;
	}
	
	rep(i, m) {
		int l = x[i] - (w[i] + c - 1) / c + 1; if (l < 0) l = 0;
		int r = x[i] + (w[i] + c - 1) / c; if (r > n) r = n;
		add(s, l, x[i], w[i] - c * (x[i] - l), c);
		add(s, x[i], r, w[i], -c);
	}
	
	rep(i, n) { if (s[i] >= a[i]) return false; }
	return true;
}

signed main() {
	int i;
	
	cin >> n >> m;
	rep(i, n) { cin >> a[i]; }
	rep(i, m) { cin >> x[i] >> w[i]; x[i]--; }
	
	int ng = -1, ok = 114514, mid;
	while (ok - ng >= 2) {
		mid = (ok + ng) / 2;
		if (check(mid)) ok = mid;
		else ng = mid;
	}
	if (ok >= 114514) cout << "-1" << endl;
	else cout << ok << endl;
	return 0;
}
0