結果

問題 No.1008 Bench Craftsman
ユーザー 沙耶花沙耶花
提出日時 2020-03-06 23:01:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,683 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 209,952 KB
実行使用メモリ 14,496 KB
最終ジャッジ日時 2024-04-22 10:18:35
合計ジャッジ時間 13,344 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 103 ms
9,600 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 40 ms
5,376 KB
testcase_09 AC 120 ms
6,656 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 523 ms
14,336 KB
testcase_16 WA -
testcase_17 AC 529 ms
14,464 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){

	int N,M;
	cin>>N>>M;
	
	vector<long long> a(N);
	for(int i=0;i<N;i++){
		scanf("%lld",&a[i]);
	}
	
	vector<pair<long long,long long>> V(M);
	for(int i=0;i<M;i++){
		scanf("%lld %lld",&V[i].first,&V[i].second);
		V[i].first--;
	}
	
	long long ok = 100005;
	long long ng = -1;
	
	while(ok-ng>1){
		long long c = (ok+ng)/2;

		vector<vector<int>> add(N,vector<int>()),del(N,vector<int>());

		for(int i=0;i<M;i++){
			if(c==0){
				add[0].push_back(i);
				continue;
			}
			long long x = (V[i].second+c-1)/c;
			x--;
			add[max(V[i].first-x,0LL)].push_back(i);
			del[min(V[i].first+x,(long long)N-1)].push_back(i);
		}
		
		bool f = true;
		
		long long sum = 0;
		multiset<int> M1,M2;

		
		for(int i=0;i<N;i++){
			sum -= c*M1.size();
			sum += c*M2.size();
			
			int C = M2.count(i);
			M2.erase(i);
			for(int j=0;j<C;j++)M1.insert(i);
			for(int j=0;j<add[i].size();j++){
				int ind = add[i][j];
				if(i>=V[ind].first){
					M1.insert(ind);
				}
				else{
					M2.insert(ind);
				}
				sum += V[ind].second - abs(i-V[ind].first)*c;
			}
			/*
			if(c==1){
				cout<<i<<','<<sum<<endl;
			}*/
			if(a[i]<=sum){
				f=false;
				break;
			}
			
			for(int j=0;j<del[i].size();j++){
				//if(c==1)cout<<i<<endl;
				int ind = del[i][j];
				if(M1.count(ind)){
					M1.erase(M1.lower_bound(ind));
				}
				else{
					M2.erase(M2.lower_bound(ind));
				}
				sum -= V[ind].second - abs(i-V[ind].first)*c;
			}
		}

		if(f)ok = c;
		else ng = c;
		
	}
	
	if(ok==100005)ok=-1;
	cout<<ok<<endl;
	
    return 0;
}


0