結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 13 ms
6,944 KB
testcase_04 AC 14 ms
6,944 KB
testcase_05 AC 169 ms
9,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 145 ms
7,584 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 35 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 35 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 59 ms
8,116 KB
testcase_21 AC 68 ms
7,956 KB
testcase_22 AC 115 ms
8,180 KB
testcase_23 AC 130 ms
8,896 KB
testcase_24 AC 141 ms
8,576 KB
testcase_25 AC 47 ms
8,576 KB
testcase_26 AC 38 ms
8,068 KB
testcase_27 AC 101 ms
7,680 KB
testcase_28 AC 91 ms
8,676 KB
testcase_29 AC 140 ms
9,520 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+1;
	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-1]+=w[j]%c;
			sum[x[j]-w[j]/c+OFFSET]-=w[j]%c;
			// right
			sum[x[j]+OFFSET]-=c;
			sum[x[j]+w[j]/c+OFFSET]+=c;
			sum[x[j]+w[j]/c+OFFSET]-=w[j]%c;
			sum[x[j]+w[j]/c+OFFSET+1]+=w[j]%c;
		}
		rep(_,2) rep(i,(int)sum.size()-1) sum[i+1]+=sum[i];
//printf("lo = %d, mi = %d, hi = %d\n",lo,mi,hi);
//for(int d=-7;d<20;d++) printf("%lld ",sum[x[0]+d+OFFSET]); puts(""); puts("");

		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