結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-07 00:47:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 449 ms / 2,000 ms |
| コード長 | 931 bytes |
| コンパイル時間 | 779 ms |
| コンパイル使用メモリ | 78,108 KB |
| 実行使用メモリ | 10,280 KB |
| 最終ジャッジ日時 | 2024-10-14 10:55:34 |
| 合計ジャッジ時間 | 7,768 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main()
| ^~~~
ソースコード
#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;
}