結果

問題 No.1008 Bench Craftsman
ユーザー kotatsugamekotatsugame
提出日時 2020-03-07 00:47:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 438 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 77,684 KB
実行使用メモリ 10,408 KB
最終ジャッジ日時 2024-04-22 11:36:29
合計ジャッジ時間 8,125 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,656 KB
testcase_01 AC 4 ms
6,656 KB
testcase_02 AC 4 ms
6,528 KB
testcase_03 AC 4 ms
6,656 KB
testcase_04 AC 4 ms
6,656 KB
testcase_05 AC 438 ms
10,408 KB
testcase_06 AC 87 ms
8,448 KB
testcase_07 AC 5 ms
6,656 KB
testcase_08 AC 14 ms
6,912 KB
testcase_09 AC 242 ms
7,168 KB
testcase_10 AC 308 ms
10,368 KB
testcase_11 AC 303 ms
10,112 KB
testcase_12 AC 317 ms
10,112 KB
testcase_13 AC 319 ms
10,240 KB
testcase_14 AC 297 ms
10,112 KB
testcase_15 AC 120 ms
10,240 KB
testcase_16 AC 220 ms
10,240 KB
testcase_17 AC 118 ms
10,368 KB
testcase_18 AC 219 ms
10,112 KB
testcase_19 AC 212 ms
10,112 KB
testcase_20 AC 118 ms
8,448 KB
testcase_21 AC 142 ms
8,320 KB
testcase_22 AC 293 ms
8,064 KB
testcase_23 AC 352 ms
9,472 KB
testcase_24 AC 353 ms
8,832 KB
testcase_25 AC 95 ms
8,704 KB
testcase_26 AC 77 ms
8,192 KB
testcase_27 AC 244 ms
7,808 KB
testcase_28 AC 218 ms
8,932 KB
testcase_29 AC 366 ms
9,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int N,M;
long A[1<<17];
vector<int>W[1<<17];
bool ok(long c)
{
	long B[1<<17];
	priority_queue<long>P;
	long Ps=0;
	for(int i=0;i<N;i++)
	{
		while(!P.empty()&&-P.top()<=i*c)
		{
			Ps+=P.top();
			P.pop();
		}
		for(int w:W[i])
		{
			long t=w+i*c;
			Ps+=t;
			P.push(-t);
		}
		B[i]=A[i]-(Ps-i*c*P.size());
	}
	while(!P.empty())P.pop();
	Ps=0;
	for(int i=N;i--;)
	{
		while(!P.empty()&&-P.top()<=(N-i-1)*c)
		{
			Ps+=P.top();
			P.pop();
		}
		B[i]-=Ps-(N-i-1)*c*P.size();
		for(int w:W[i])
		{
			long t=w+(N-i-1)*c;
			Ps+=t;
			P.push(-t);
		}
	}
	for(int i=0;i<N;i++)if(B[i]<=0)return false;
	return true;
}
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<M;i++)
	{
		int x,w;cin>>x>>w;
		W[x-1].push_back(w);
	}
	int L=-1,R=1e5;
	if(!ok(R))R=-1;
	while(R-L>1)
	{
		int M=(L+R)/2;
		if(ok(M))R=M;
		else L=M;
	}
	cout<<R<<endl;
}
0