結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
nrvft
|
| 提出日時 | 2020-03-07 00:00:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 727 ms / 2,000 ms |
| コード長 | 2,951 bytes |
| コンパイル時間 | 2,317 ms |
| コンパイル使用メモリ | 206,924 KB |
| 最終ジャッジ日時 | 2025-01-09 05:40:49 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
int main() {
init();
ll N,M;cin>>N>>M;
vl A(N);
rep(i, N) cin >> A[i];
vc<pair<ll,ll>> pp(M);
rep(i,M){
ll x, w;
cin >> x >> w;
x--;
pp[i] = {x, w};
}
vl Xcnt(N);
sort(all(pp));
rep(i, M) Xcnt[pp[i].first]++;
//c=0でokなら返す
ll sum = 0;
rep(i,M){
sum += pp[i].second;
}
bool ok0 = true;
rep(i,N){
if(sum>=A[i]){
ok0 = false;
break;
}
}
if(ok0){
cout << 0 << endl;
return 0;
}
//二分探索
ll ng = 0, ok = 1e9;
while(ok-ng>1){
bool isok = true;
ll mid = (ok + ng) / 2;
vvc<pair<ll,ll>> add(N), del(N);
for(auto p:pp){
ll x, w;
tie(x, w) = p;
ll r = w / mid;
add[max(0ll, x - r)].eb(x,w);
del[min(N - 1, x + r)].eb(x,w);
}
// cout << "add" << endl;
// rep(i,N){
// cout << i << endl;
// for (auto p : add[i]) cout << p.first << " " << p.second << " ";
// cout << endl;
// }
// cout << "del" << endl;
// rep(i,N){
// cout << i << endl;
// for (auto p : del[i]) cout << p.first << " " << p.second << " ";
// cout << endl<<endl;
// }
ll cnt = 0, val = 0;
rep(i,N){
val += cnt * mid;
for(auto p:add[i]){
ll x, w;
tie(x, w) = p;
cnt++;
val += w - (x - i) * mid;
}
if(val>=A[i]){
isok = false;
break;
}
for(auto p:del[i]){
ll x, w;
tie(x, w) = p;
cnt++;
val -= w - (i - x) * mid;
}
cnt -= Xcnt[i] * 2;
}
(isok ? ok : ng) = mid;
}
if(ok==1e9){
cout << -1 << endl;
return 0;
}
cout << ok << endl;
}
nrvft