| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 76792 | 周梓易 | 吃巧克力 | C++ | Time Limit Exceeded | 1000 MS | 252 KB | 1332 | 2024-06-02 17:53:58 |
#include<iostream> #include<cstring> #include<cstdio> #define LL long long #define mid ((l+r)>>1) using namespace std; const LL N = 50005; LL n,m,a[N],ans[N],l,r,anst; inline LL read() { char c=getchar(); LL ans=0,w=1; while((c<'0'||c>'9')&&c!='-') c=getchar(); if(c=='-') { w=-1; c=getchar(); } while(c>='0'&&c<='9') { ans=ans*10+c-'0'; c=getchar(); } return ans*w; } bool check(LL u) { LL tot=0,last=0,cnt=0,ansp=0; while(tot<m) { last=last/2; ansp=0; while(ansp+last<u) { ++cnt; ansp+=a[cnt]; if(cnt>=n) break; } last=ansp+last; if(last>=u) ++tot; else break; // if(cnt>=n) break; 直接break 会导致接下来一直减半,但还是满足条件的情况漏掉 }// 还好这样的点只有一个 if(tot>=m) return true; return false; } void print(LL u) { LL tot=0,last=0,cnt=0,ansp=0; while(tot<m) { last=last>>1; ansp=0; while(ansp+last<u) ansp+=a[++cnt],printf("%lld\n",tot+1); last=ansp+last; ++tot; } if(cnt<n)// 大坑点 有意思么 for(LL i=cnt+1;i<=n;i++)// printf("%lld\n",m);// return ; } int main() { n=read(); m=read(); for(LL i=1;i<=n;i++) a[i]=read(),r+=a[i]; while(l<=r) { if(check(mid)) { anst=mid, l=mid+1; } else r=mid-1; } printf("%lld\n",anst); print(anst); return 0; }