結果

問題 No.1008 Bench Craftsman
ユーザー 👑 kmjpkmjp
提出日時 2020-03-07 00:54:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,764 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 166,392 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-22 11:37:59
合計ジャッジ時間 5,287 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,680 KB
testcase_01 AC 9 ms
7,296 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 9 ms
7,552 KB
testcase_04 AC 9 ms
7,552 KB
testcase_05 AC 139 ms
10,252 KB
testcase_06 AC 40 ms
8,960 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 16 ms
7,552 KB
testcase_09 AC 81 ms
8,832 KB
testcase_10 AC 134 ms
10,168 KB
testcase_11 AC 137 ms
10,076 KB
testcase_12 AC 135 ms
10,368 KB
testcase_13 AC 137 ms
10,228 KB
testcase_14 AC 136 ms
10,220 KB
testcase_15 AC 36 ms
6,400 KB
testcase_16 AC 137 ms
10,260 KB
testcase_17 AC 34 ms
6,400 KB
testcase_18 AC 137 ms
10,368 KB
testcase_19 AC 140 ms
10,004 KB
testcase_20 AC 50 ms
8,832 KB
testcase_21 AC 52 ms
8,704 KB
testcase_22 AC 80 ms
8,832 KB
testcase_23 AC 104 ms
9,600 KB
testcase_24 AC 104 ms
9,216 KB
testcase_25 AC 42 ms
9,088 KB
testcase_26 AC 36 ms
8,576 KB
testcase_27 AC 64 ms
8,576 KB
testcase_28 AC 73 ms
9,344 KB
testcase_29 AC 112 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
ll A[101010];
ll B[101010];
int X[101010];
ll Y[101010];
ll LD[101010];
ll RD[101010];
ll LS[101010];
ll RS[101010];
ll S[101010];


int ok(ll c) {
	int i;
	ZERO(LD);
	ZERO(RD);
	ZERO(S);
	ZERO(LS);
	ZERO(RS);
	
	if(c==0) {
		ll sum=0;
		FOR(i,M) sum+=Y[i];
		FOR(i,N) if(A[i+1]<=sum) return 0;
		return 1;
	}
	
	FOR(i,M) {
		int w=Y[i]/c;
		S[max(0,X[i]-w)]+=Y[i];
		S[min(X[i]+w+1,101000)]-=Y[i];
		RD[X[i]+1]++;
		RD[min(X[i]+w+1,101000)]--;
		RS[min(X[i]+w,101000)]-=w;
		LD[X[i]-1]++;
		LD[max(X[i]-w-1,0)]--;
		LS[max(X[i]-w,0)]-=w;
	}
	
	ll d=0,s=0;
	for(i=1;i<=N;i++) {
		d+=RD[i]*c;
		s+=d;
		S[i]+=S[i-1];
		B[i]=S[i]-s;
		s+=RS[i]*c;
	}
	d=s=0;
	for(i=N;i>=1;i--) {
		d+=LD[i]*c;
		s+=d;
		B[i]-=s;
		s+=LS[i]*c;
	}
	FOR(i,N) if(B[i+1]>=A[i+1]) return 0;
	return 1;
	
	
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	ll sum=0;
	FOR(i,N) {
		cin>>A[i+1];
	}
	FOR(i,M) {
		cin>>X[i]>>Y[i];
		B[X[i]]+=Y[i];
	}
	FOR(i,N) if(B[i+1]>=A[i+1]) return _P("-1\n");
	
	ll ret=(1LL<<30)-1;
	for(i=29;i>=0;i--) if(ok(ret-(1<<i))) ret-=1<<i;
	cout<<ret<<endl;
		
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0