結果

問題 No.1008 Bench Craftsman
ユーザー startcppstartcpp
提出日時 2020-03-06 22:29:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,913 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 84,780 KB
実行使用メモリ 7,628 KB
最終ジャッジ日時 2024-04-22 08:55:35
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

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

//[l, r)に, +a, +a+d, +a+2*d, …していく.
void add(int l, int r, int a, int d, int s1[], int s2[]) {
	if (r - l <= 0) return;
	//cout << "l = " << l << ", r = " << r << ", a = " << a << ", d = " << d << endl;
	s1[l] += a;
	s1[r] -= a;
	s2[l + 1] += d;
	s2[r] -= (r - l) * d;
	
	//int i;
	//rep(i, n + 1) cout << s1[i] << " "; cout << endl;
	//rep(i, n + 1) cout << s2[i] << " "; cout << endl;
}

void Add(int p, int w, int c, int s1[], int s2[]) {
	int l, r, w0l;	//add[l, p), add[p, r)
	
	if (c == 0) {
		add(0, n, w, 0, s1, s2);
		return;
	}
	
	l = p - (w + c - 1) / c + 1;
	if (l < 0) { l = 0; }
	
	r = p + (w + c - 1) / c;
	if (r > n) { r = n; }
	
	w0l = w - c * (p - l);
	add(l, p, w0l, c, s1, s2);
	add(p, r, w, -c, s1, s2);
}

bool check(int c) {
	//cout << "c = " << c << endl;
	static int s1[100001];
	static int s2[100001];
	int i;
	
	rep(i, n + 1) s1[i] = 0;
	rep(i, n + 1) s2[i] = 0;
	
	rep(i, m) Add(x[i], w[i], c, s1, s2);
	rep(i, n) s1[i + 1] += s1[i];
	rep(i, n) s2[i + 1] += s2[i];
	rep(i, n) s2[i + 1] += s2[i];
	
	//cout << "kansei" << endl;
	//rep(i, n + 1) cout << s1[i] << " "; cout << endl;
	//rep(i, n + 1) cout << s2[i] << " "; cout << endl;
	
	rep(i, n) if (s1[i] + s2[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