結果
問題 |
No.1008 Bench Craftsman
|
ユーザー |
|
提出日時 | 2020-04-03 20:03:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,268 bytes |
コンパイル時間 | 1,562 ms |
コンパイル使用メモリ | 169,220 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-03 01:14:41 |
合計ジャッジ時間 | 5,876 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 22 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; typedef pair<int,int> P; const ll INF = 1e18; const int MOD = 1000000007; int main(){ int n,m; cin >> n >> m; vector<ll> a(n); vector<ll> weight(n); vector<ll> cen(n); rep(i,n) cin >> a[i]; ll sum_weight = 0; rep(i,m){ ll x,w; cin >> x >> w; --x; cen[x] ++; weight[0] += abs(x); sum_weight += w; } ll cnt = cen[0]; for(int i=1;i<n;i++){ weight[i] = weight[i-1] + 2*cnt - m; cnt += cen[i]; } bool ok = true; ll ans = 0; rep(i,n){ if(sum_weight - a[i] < 0) continue; if(weight[i] == 0){ if(sum_weight - a[i] <= 0) continue; else{ ok = false; break; } } ans = max(ans,(sum_weight-a[i]+weight[i]-1)/weight[i]); } if(ok) cout << ans << endl; else cout << -1 << endl; return 0; }