結果

問題 No.1008 Bench Craftsman
ユーザー furafura
提出日時 2020-03-06 22:59:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,140 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 199,820 KB
実行使用メモリ 10,284 KB
最終ジャッジ日時 2024-04-22 10:15:01
合計ジャッジ時間 6,537 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 AC 14 ms
6,944 KB
testcase_04 AC 14 ms
6,944 KB
testcase_05 AC 170 ms
10,028 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,648 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 64 ms
8,176 KB
testcase_21 AC 69 ms
7,936 KB
testcase_22 AC 116 ms
8,192 KB
testcase_23 AC 133 ms
9,184 KB
testcase_24 AC 142 ms
8,704 KB
testcase_25 AC 46 ms
8,560 KB
testcase_26 AC 41 ms
8,064 KB
testcase_27 AC 101 ms
7,780 KB
testcase_28 AC 92 ms
8,768 KB
testcase_29 AC 141 ms
9,320 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+1);

	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-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];

		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