結果

問題 No.1008 Bench Craftsman
ユーザー furafura
提出日時 2020-03-06 23:50:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,138 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 200,268 KB
実行使用メモリ 10,308 KB
最終ジャッジ日時 2024-04-22 10:46:47
合計ジャッジ時間 6,232 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 170 ms
10,036 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 144 ms
7,736 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 34 ms
6,944 KB
testcase_16 WA -
testcase_17 AC 35 ms
6,940 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 59 ms
8,112 KB
testcase_21 AC 67 ms
8,064 KB
testcase_22 AC 117 ms
8,000 KB
testcase_23 AC 133 ms
8,884 KB
testcase_24 AC 142 ms
8,704 KB
testcase_25 AC 45 ms
8,576 KB
testcase_26 AC 41 ms
8,072 KB
testcase_27 AC 101 ms
7,684 KB
testcase_28 AC 92 ms
8,704 KB
testcase_29 AC 139 ms
9,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);
	vector<int> x(m);
	vector<lint> w(m);
	rep(j,m) scanf("%d%lld",&x[j],&w[j]), x[j]--;

	vector<lint> wsum(n);
	rep(j,m) wsum[x[j]]+=w[j];
	rep(i,n) if(wsum[i]>=a[i]) return puts("-1"),0;

	if(accumulate(w.begin(),w.end(),0LL)<*min_element(a.begin(),a.end())) return puts("0"),0;

	const int OFFSET=2e5;
	vector<lint> sum(n+2*OFFSET);

	int lo=0,hi=1e5;
	while(hi-lo>1){
		int mi=(lo+hi)/2;

		int c=mi;
		fill(sum.begin(),sum.end(),0LL);
		rep(j,m){
			// left
			sum[x[j]-w[j]/c+OFFSET]+=c;
			sum[x[j]+OFFSET]-=c;
			sum[x[j]-w[j]/c+OFFSET]+=w[j]%c;
			sum[x[j]-w[j]/c+OFFSET+1]-=w[j]%c;
			// right
			sum[x[j]+OFFSET]-=c;
			sum[x[j]+w[j]/c+OFFSET]+=c;
			sum[x[j]+w[j]/c+OFFSET+1]-=w[j]%c;
			sum[x[j]+w[j]/c+OFFSET+2]+=w[j]%c;
		}
		rep(_,2) rep(i,(int)sum.size()-1) sum[i+1]+=sum[i];

		bool ok=true;
		rep(i,n) if(sum[i+OFFSET]>=a[i]) { ok=false; break; }
		if(ok) hi=mi;
		else   lo=mi;
	}
	printf("%d\n",hi);

	return 0;
}
0