結果

問題 No.1008 Bench Craftsman
ユーザー FF256grhyFF256grhy
提出日時 2023-08-23 18:08:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 3,076 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 205,212 KB
実行使用メモリ 6,464 KB
最終ジャッジ日時 2023-08-23 18:08:50
合計ジャッジ時間 7,355 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 137 ms
6,164 KB
testcase_06 AC 49 ms
4,728 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 78 ms
4,664 KB
testcase_10 AC 120 ms
6,264 KB
testcase_11 AC 122 ms
6,280 KB
testcase_12 AC 123 ms
6,220 KB
testcase_13 AC 123 ms
6,168 KB
testcase_14 AC 122 ms
6,276 KB
testcase_15 AC 122 ms
6,164 KB
testcase_16 AC 123 ms
6,176 KB
testcase_17 AC 146 ms
6,164 KB
testcase_18 AC 123 ms
6,464 KB
testcase_19 AC 124 ms
6,216 KB
testcase_20 AC 47 ms
4,504 KB
testcase_21 AC 48 ms
4,492 KB
testcase_22 AC 78 ms
4,928 KB
testcase_23 AC 99 ms
5,448 KB
testcase_24 AC 96 ms
5,312 KB
testcase_25 AC 46 ms
4,728 KB
testcase_26 AC 36 ms
4,376 KB
testcase_27 AC 66 ms
4,504 KB
testcase_28 AC 71 ms
4,916 KB
testcase_29 AC 131 ms
5,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

template<typename T, typename U> istream & operator>>(istream & s, pair<T, U> & p) { return (s >> p.FI >> p.SE); }
template<typename T, typename U> ostream & operator<<(ostream & s, pair<T, U> const & p) { return (s << p.FI << " " << p.SE); }

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n, m);
	vector<LL> a(n);
	vector<pair<LL, LL>> v(m);
	cin >> a >> v;
	
	auto f = [&](LL c) -> bool {
		vector<LL> s(n + 2);
		RF(e, v) {
			LL x = e.FI;
			LL w = e.SE;
			LL v1 = w - c * (x - 1);
			LL vn = w - c * (n - x);
			LL L = (v1 >= 0 ? 1 : x - (w / c));
			LL R = (vn >= 0 ? n : x + (w / c));
			assert(inII(L, 1, n));
			assert(inII(R, 1, n));
			LL vl = w - c * (x - L);
			LL vr = w - c * (R - x);
			assert(vl >= 0 && vr >= 0);
			s[L + 0] += vl;
			s[L + 1] -= vl;
			s[L + 1] += c;
			s[x + 1] -= 2 * c;
			s[R + 1] += c;
			s[R + 1] -= vr;
			s[R + 2] += vr;
		}
		inc1(i, n + 1) { s[i + 1] += s[i]; }
		inc1(i, n + 1) { s[i + 1] += s[i]; }
		assert(s.FR == 0 && s.BA == 0);
		inc(i, n) { if(a[i] <= s[i + 1]) { return false; } }
		return true;
	};
	
	LL INF = 0;
	RF(e, v) { setmax(INF, e.SE); }
	INF++;
	
	LL ng = -1, ok = INF;
	until(abs(ok - ng) == 1) {
		LL mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	if(ok == INF) { ok = -1; }
	OUT(ok);
}
0