結果
問題 |
No.1008 Bench Craftsman
|
ユーザー |
|
提出日時 | 2020-03-06 23:17:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,267 bytes |
コンパイル時間 | 4,762 ms |
コンパイル使用メモリ | 197,440 KB |
最終ジャッジ日時 | 2025-01-09 05:34:53 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 12 |
コンパイルメッセージ
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]+=c; sum[x[j]+OFFSET]-=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]-=c; sum[x[j]+w[j]/c+OFFSET]+=c; sum[x[j]+w[j]/c+OFFSET-1]-=w[j]%c; sum[x[j]+w[j]/c+OFFSET]+=w[j]%c; } rep(_,2) rep(i,(int)sum.size()-1) sum[i+1]+=sum[i]; //printf("lo = %d, mi = %d, hi = %d\n",lo,mi,hi); //for(int d=-7;d<20;d++) printf("%lld ",sum[x[0]+d+OFFSET]); puts(""); puts(""); 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; }