結果

問題 No.1008 Bench Craftsman
ユーザー leaf_1415leaf_1415
提出日時 2020-03-06 22:14:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 65,436 KB
実行使用メモリ 21,988 KB
最終ジャッジ日時 2024-04-22 08:16:01
合計ジャッジ時間 9,902 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,652 KB
testcase_01 AC 4 ms
10,316 KB
testcase_02 AC 4 ms
10,404 KB
testcase_03 AC 4 ms
10,336 KB
testcase_04 AC 4 ms
10,392 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
11,588 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
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 <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];
			w[i] += sum;
			if(c > 0){
				if(i + vec[i][j]/c <= n){
					dvec[i+vec[i][j]/c].push_back(vec[i][j]%c);
				}
			}
			num++;
		}
		for(int j = 0; j < dvec[i].size(); j++){
			sum -= dvec[i][j];
			num--;
		}
		sum -= c * num;
	}
}

bool check(llint c)
{
	//cout << c << endl;
	for(int i = 1; i <= n; i++){
		w[i] = 0;
		for(int j = 0; j < vec[i].size(); j++){
			w[i] -= vec[i][j];
		}
	}
	
	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++){
		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