結果

問題 No.1008 Bench Craftsman
ユーザー leaf_1415leaf_1415
提出日時 2020-03-06 22:23:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,570 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 65,492 KB
実行使用メモリ 21,956 KB
最終ジャッジ日時 2024-04-22 08:46:56
合計ジャッジ時間 10,825 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,368 KB
testcase_01 AC 5 ms
10,368 KB
testcase_02 AC 4 ms
10,368 KB
testcase_03 AC 4 ms
10,368 KB
testcase_04 AC 5 ms
10,368 KB
testcase_05 AC 612 ms
21,956 KB
testcase_06 AC 62 ms
12,616 KB
testcase_07 AC 5 ms
10,368 KB
testcase_08 AC 13 ms
10,728 KB
testcase_09 AC 104 ms
13,148 KB
testcase_10 AC 596 ms
21,120 KB
testcase_11 AC 615 ms
21,248 KB
testcase_12 AC 578 ms
21,188 KB
testcase_13 AC 596 ms
21,176 KB
testcase_14 AC 645 ms
21,120 KB
testcase_15 WA -
testcase_16 AC 593 ms
20,480 KB
testcase_17 WA -
testcase_18 AC 545 ms
20,036 KB
testcase_19 AC 568 ms
20,480 KB
testcase_20 AC 137 ms
14,720 KB
testcase_21 AC 148 ms
15,104 KB
testcase_22 AC 183 ms
15,872 KB
testcase_23 AC 346 ms
18,816 KB
testcase_24 AC 271 ms
18,200 KB
testcase_25 AC 102 ms
15,104 KB
testcase_26 AC 83 ms
14,036 KB
testcase_27 AC 135 ms
14,720 KB
testcase_28 AC 246 ms
17,084 KB
testcase_29 AC 455 ms
19,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint a[100005];
vector<llint> vec[100005], rvec[100005];
vector<llint> dvec[100005];
llint w[100005];

void calc(vector<llint> vec[], llint c)
{
	for(int i = 1; i <= n; i++) dvec[i].clear();
	llint sum = 0, num = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < vec[i].size(); j++){
			sum += vec[i][j];
			if(c > 0){
				if(i + vec[i][j]/c <= n){
					dvec[i+vec[i][j]/c].push_back(vec[i][j]%c);
				}
			}
			num++;
		}
		w[i] += sum;
		for(int j = 0; j < dvec[i].size(); j++){
			sum -= dvec[i][j];
			num--;
		}
		sum -= c * num;
	}
}

bool check(llint c)
{
	for(int i = 1; i <= n; i++) w[i] = 0;
	
	calc(vec, c);
	reverse(w+1, w+n+1);
	calc(rvec, c);
	reverse(w+1, w+n+1);
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < vec[i].size(); j++){
			w[i] -= vec[i][j];
		}
	}
	for(int i = 1; i <= n; i++){
		if(a[i] <= w[i]) return false;
	}
	return true;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint x, w;
	for(int i = 1; i <= m; i++){
		cin >> x >> w;
		vec[x].push_back(w);
		rvec[n-x+1].push_back(w);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < vec[i].size(); j++){
			if(vec[i][j] >= a[i]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	
	llint ub = 1e9+7, lb = -1, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
	
	return 0;
}
0