细心题

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
typedef long long ll;
const int maxn=1e5+5;
int n;
ll g,p;
int a[maxn];
ll dp[maxn],sum[maxn];
bool ok1(ll m)
{
if(m>=g)return true;
int tmp=min(ll(n),p);
for(int i=0;i<tmp;++i)
{
m=m+a[i]<=0?0:m+a[i];
if(m>=g)return true;
}
return false;
}
bool ok2(ll m)
{
for(int i=0;i<n;++i)
{
m=m+a[i]<=0?0:m+a[i];
if(m>=g)return true;
}
ll gain,gg=0;
if(sum[n-1]<=0)
{
int tmp=p<2*n?p-n:n;
gain=dp[tmp-1];
}
else
{
if(p<2*n)gain=dp[p-n-1];
else
{
int tmp=p%n?p%n+n:n;
if(((g-m)/sum[n-1])<=((p-n-tmp)/n))return true;
gain=(p-n-tmp)/n*sum[n-1];
gg=max(dp[tmp%n-1]+sum[n-1],dp[n-1]);
}
}
if(m+gain>=g-gg)return true;
return false;
}
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("1.txt","w",stdout);
int T;scanf("%d",&T);
for(int Case=1;Case<=T;++Case)
{
scanf("%d%lld%lld",&n,&g,&p);
for(int i=0;i<n;++i)scanf("%d",a+i);
sum[0]=a[0];dp[0]=a[0]>0?a[0]:0;
for(int i=1;i<n;++i)
{
sum[i]=sum[i-1]+a[i];
dp[i]=sum[i]>dp[i-1]?sum[i]:dp[i-1];
}
if(p<=n)
{
ll l=0,m,r=g;
while(l<r)
{
m=(l+r)/2;
if(ok1(m))r=m;
else l=m+1;
}
printf("Case #%d: %lld\n",Case,l);
}
else
{
ll l=0,m,r=g;
while(l<r)
{
m=(l+r)/2;
if(ok2(m))r=m;
else l=m+1;
}
printf("Case #%d: %lld\n",Case,l);
}
}
//freopen("CON","w",stdout);
//system("start 1.txt");
}

UVALive 7501 Business Cycle的更多相关文章

  1. UVALive 7501 Business Cycle(二分)题解

    题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...

  2. 2015 ACM/ICPC EC-Final

    A. Boxes and Balls 二分找到最大的不超过$n$的$\frac{x(x+1)}{2}$形式的数即可. #include <bits/stdc++.h> using name ...

  3. Machine and Deep Learning with Python

    Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...

  4. ORGANISING THE TEST CASES

    ORGANISING THE TEST CASES -Test note of “Essential Software Test Design” 2015-09-24 目录 22.1 Test Cas ...

  5. AIMR 固定收益推荐读物

    目录 AIMR Suggested Fixed-Income Readings I. Perspectives on Interest Rates and Pricing of Traditional ...

  6. UVALive - 5135 - Mining Your Own Business(双连通分量+思维)

    Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...

  7. UVALive - 5135 Mining Your Own Business

    刘汝佳白书上面的一道题目:题意是给定一个联通分量,求出割顶以及双连通分量的个数,并且要求出安放安全井的种类数,也就是每个双连通分量中结点数(除开 割顶)个数相乘,对于有2个及以上割顶的双连通分量可以不 ...

  8. UVALive 5135 Mining Your Own Business 双连通分量 2011final

    题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太平井逃脱, ...

  9. Business Cards UVALive - 4384(画图看图。。)

    只能由三种情况 都横着放  都竖着放  横和竖交错放 那就去判断好了... 具体看代码 #include <iostream> #include <cstdio> #inclu ...

随机推荐

  1. STM32F103ZET6的中断管理

    1.STM32的中断 STM32的中断管理是属于内核部分的,所以中断管理的寄存器也是属于内核组,不属于芯片外设,在查看相关资料的时候,需要查看相对应的内核手册. STM32F103ZET6是Corte ...

  2. Http协议中Cookie使用详细介绍

    Cookie总是保存在客户端中,按在客户端中的存储位置,可分为内存Cookie和硬盘Cookie.内存Cookie由浏览器维护,保存在内存中,浏览器关闭后就消失了,其存在时间是短暂的.硬盘Cookie ...

  3. SignalR新手系列教程详解总结(转)

    SignalR新手系列教程详解总结 GlobalHost.ConnectionManager.GetHubContext<TodoListHub>() .Clients.Clients(l ...

  4. VSCode——自定义VSCode背景图片

    本文转载自https://blog.csdn.net/yukinoai/article/details/84564949 1.以管理员身份运行VS Code,安装background插件 2.打开se ...

  5. MySQL入门,第五部分,表结构的修改

    ALTER TABLE <基本表名> [ ADD <新列名> <列数据类型> [列完整性约束] DROP COLUMN <列名> MODIFY < ...

  6. 30.2 案例:ArrayList本身数据可以重复,写出去重的方法

    package day30_HashSet; /* * ArrayList特点(实现List接口) 有序.可以重复.可以使用索引 *使用ArrayList实现数据去重 * */ import java ...

  7. Python设计模式(1)-简单工厂模式

    为操作数据库设计增删改查操作 # coding=utf-8class DbManager: def __init__(self): pass def operate_db(self): pass cl ...

  8. floyd三重循环最外层为什么一定是K

    Floyd算法为什么把k放在最外层? - 知乎 https://www.zhihu.com/question/30955032高票答案: 简单地总结一下:K没放在最外面一定是错的,但是在某些数据比较水 ...

  9. Centos7_搭建暗网网站

    Tor运行原理 请求方需要使用:洋葱浏览器(Tor Browser)来对暗网网站进行访问 响应放需要使用:Tor协议的的Hidden_service 搭建步骤 更新YUM源: rpm -Uvh htt ...

  10. 选择IT行业的自我心得,希望能帮助到各位!(六)

    在这个社会,想做大事的人很多,但是很多事情也挺难做的,为什么说复杂的事情简单做,简单的事情重复做,这样一个人才能获得更多的优越品质,为啥说改变,人还是挺难过的,都知道本性难移,想改挺难得.在这个社会千 ...