結果

問題 No.1008 Bench Craftsman
ユーザー leaf_1415leaf_1415
提出日時 2020-03-06 22:31:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 638 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 66,236 KB
実行使用メモリ 21,968 KB
最終ジャッジ日時 2023-08-04 11:20:01
合計ジャッジ時間 10,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,780 KB
testcase_01 AC 5 ms
10,856 KB
testcase_02 AC 4 ms
10,776 KB
testcase_03 AC 5 ms
10,788 KB
testcase_04 AC 5 ms
10,776 KB
testcase_05 AC 587 ms
21,968 KB
testcase_06 AC 75 ms
12,592 KB
testcase_07 AC 5 ms
10,800 KB
testcase_08 AC 16 ms
11,120 KB
testcase_09 AC 123 ms
13,784 KB
testcase_10 AC 553 ms
21,284 KB
testcase_11 AC 541 ms
21,272 KB
testcase_12 AC 598 ms
21,324 KB
testcase_13 AC 638 ms
21,264 KB
testcase_14 AC 636 ms
21,176 KB
testcase_15 AC 58 ms
16,204 KB
testcase_16 AC 532 ms
20,516 KB
testcase_17 AC 59 ms
16,200 KB
testcase_18 AC 536 ms
20,032 KB
testcase_19 AC 523 ms
20,708 KB
testcase_20 AC 169 ms
14,956 KB
testcase_21 AC 183 ms
15,016 KB
testcase_22 AC 220 ms
16,132 KB
testcase_23 AC 378 ms
18,824 KB
testcase_24 AC 313 ms
18,220 KB
testcase_25 AC 131 ms
15,076 KB
testcase_26 AC 106 ms
14,100 KB
testcase_27 AC 164 ms
15,088 KB
testcase_28 AC 283 ms
17,184 KB
testcase_29 AC 435 ms
19,876 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, y;
	for(int i = 1; i <= m; i++){
		cin >> x >> y;
		vec[x].push_back(y);
		rvec[n-x+1].push_back(y);
	}
	
	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]){
			cout << -1 << endl;
			return 0;
		}
	}
	
	llint ub = 1e12, 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