結果

問題 No.1008 Bench Craftsman
ユーザー furafura
提出日時 2020-03-06 23:17:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,267 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 199,040 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-04-22 10:32:27
合計ジャッジ時間 5,854 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,528 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 152 ms
10,032 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 33 ms
6,016 KB
testcase_16 WA -
testcase_17 AC 32 ms
6,144 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 53 ms
8,176 KB
testcase_21 AC 60 ms
7,808 KB
testcase_22 AC 107 ms
8,192 KB
testcase_23 AC 123 ms
8,980 KB
testcase_24 AC 134 ms
8,576 KB
testcase_25 AC 42 ms
8,576 KB
testcase_26 AC 37 ms
8,064 KB
testcase_27 AC 92 ms
7,552 KB
testcase_28 AC 84 ms
8,704 KB
testcase_29 AC 134 ms
9,344 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]+=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