http://www.lydsy.com/JudgeOnline/problem.php?id=4590

二分

这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发

最近是怎么了啊啊啊O(≧口≦)O

#include<cstdio>
#include<iostream> using namespace std; int n,m; int x[]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} int check(long long k)
{
long long now=;
int sum=;
for(int i=;i<=n;++i)
{
now+=x[i];
if(now>=k) sum++,now=;
else if(now<) now=;
}
return sum;
} int main()
{
freopen("autoac.in","r",stdin);
freopen("autoac.out","w",stdout);
read(n); read(m);
for(int i=;i<=n;++i) read(x[i]);
long long l=,r=1LL*n*1e9,tmp=-,mid;
int t;
while(l<=r)
{
mid=l+r>>;
t=check(mid);
if(t==m) tmp=mid,r=mid-;
else if(t>m) l=mid+;
else r=mid-;
}
if(tmp==-)
{
printf("-1");
return ;
}
cout<<tmp<<' ';
l=tmp,r=1LL*n*1e9;
while(l<=r)
{
mid=l+r>>;
t=check(mid);
if(t==m) tmp=mid,l=mid+;
else if(t>m) l=mid+;
else r=mid-;
}
cout<<tmp;
return ;
}

最新文章

  1. JavaScript - 基于CSS3动画的实现
  2. 本周psp
  3. Intellij Idea 14 使用jetty-maven-plugin配置运行web工程
  4. WordPress登陆页和后台面空白解决方法
  5. 过渡transitioin
  6. Visual C#编写3D游戏框架示例
  7. Hibernate中的多对多映射
  8. Unity3D研究院编辑器之脚本设置ToolBar
  9. poj3519
  10. 并发队列之:BlockingQueue和ConcurrentLinkedQueue
  11. github进行修改
  12. html 时间单位
  13. Match类解析
  14. MyBatis的三层级联和二层缓存
  15. 20180726 - Windows 10 Pro 下远程桌面连接提示“出现身份验证错误”
  16. Spring Cloud 微服务笔记(七) Zuul入门
  17. delphi 鼠标拖动
  18. 百万级开源MQTT消息服务器 搭建
  19. POI解析Excel代码
  20. SSH报错

热门文章

  1. git笔记:通过给grunt-inline打tag看tag操作
  2. Loadrunner 面试常见问题
  3. git常用命令学习总结
  4. 1092. To Buy or Not to Buy (20)-map
  5. SCRUM 12.17
  6. “北航Clubs” Beta版本开发目标
  7. Docker打DB2 9.7镜像采坑相关
  8. 第一个Sprint计划
  9. Visual Studio 2015的安装和简单的测试
  10. beta圆桌 SUM UP