結果
問題 |
No.1008 Bench Craftsman
|
ユーザー |
|
提出日時 | 2020-03-06 23:52:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 185 ms / 2,000 ms |
コード長 | 1,146 bytes |
コンパイル時間 | 2,246 ms |
コンパイル使用メモリ | 198,272 KB |
最終ジャッジ日時 | 2025-01-09 05:39:54 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int n,m; scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | rep(i,n) scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:14:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | rep(j,m) scanf("%d%lld",&x[j],&w[j]), x[j]--; | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ int n,m; scanf("%d%d",&n,&m); vector<lint> a(n); rep(i,n) scanf("%lld",&a[i]); vector<int> x(m); vector<lint> w(m); rep(j,m) scanf("%d%lld",&x[j],&w[j]), x[j]--; vector<lint> wsum(n); rep(j,m) wsum[x[j]]+=w[j]; rep(i,n) if(wsum[i]>=a[i]) return puts("-1"),0; if(accumulate(w.begin(),w.end(),0LL)<*min_element(a.begin(),a.end())) return puts("0"),0; const int OFFSET=2e5; vector<lint> sum(n+2*OFFSET); int lo=0,hi=1e5; while(hi-lo>1){ int mi=(lo+hi)/2; int c=mi; fill(sum.begin(),sum.end(),0LL); rep(j,m){ // left sum[x[j]-w[j]/c+OFFSET+1]+=c; sum[x[j]+OFFSET+1]-=c; sum[x[j]-w[j]/c+OFFSET]+=w[j]%c; sum[x[j]-w[j]/c+OFFSET+1]-=w[j]%c; // right sum[x[j]+OFFSET+1]-=c; sum[x[j]+w[j]/c+OFFSET+1]+=c; sum[x[j]+w[j]/c+OFFSET+1]-=w[j]%c; sum[x[j]+w[j]/c+OFFSET+2]+=w[j]%c; } rep(_,2) rep(i,(int)sum.size()-1) sum[i+1]+=sum[i]; bool ok=true; rep(i,n) if(sum[i+OFFSET]>=a[i]) { ok=false; break; } if(ok) hi=mi; else lo=mi; } printf("%d\n",hi); return 0; }