結果

問題 No.1008 Bench Craftsman
ユーザー 👑 jupirojupiro
提出日時 2020-03-07 17:14:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,148 bytes
コンパイル時間 1,249 ms
コンパイル使用メモリ 117,488 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-23 01:50:50
合計ジャッジ時間 5,940 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 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 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 #

#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 imos[100500];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, M; scanf("%lld %lld", &N, &M);
	vector<ll> a(N); for (int i = 0; i < N; i++) scanf("%lld", &a[i]);
	vector<ll> x(M), w(M);
	for (int i = 0; i < M; i++) {
		scanf("%lld %lld", &x[i], &w[i]);
		x[i]--;
		if (a[x[i]] < w[i]) {
			puts("-1");
			return 0;
		}
	}

	ll left = 0;
	ll right = 1000000001;
	while (right - left > 1) {
		ll mid = (right + left) >> 1;
		for (int i = 0; i <= N; i++) imos[i] = 0;
		for (ll i = 0; i < M; i++) {
			ll mx = w[i] / mid;
			{
				ll cnt = 0;
				for (int j = x[i] + 1; j < N && cnt < mx; j++) {
					cnt++;
					imos[j] += -mid;
				}
				imos[x[i] + 1 + cnt] += -mid * cnt - w[i];
				
			}
			{
				ll cnt = 0;
				int l = max(0LL, x[i] - mx);
				imos[l] += w[i];
				for (ll j = l + 1; j < i; j++) {
					cnt++;
					imos[j] += -mid;
				}
				imos[l + 1 + cnt] += -mid * cnt;
			}
		}
		for (ll i = 0; i < N; i++) {
			imos[i + 1] += imos[i];
		}
		bool flag = true;
		for (ll i = 0; i < N; i++) {
			if (imos[i] > a[i]) flag = false;
		}
		if (flag) right = mid;
		else left = mid;
	}
	cout << left << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0