UVALive 4869 Profits DP
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description

Your friends have just opened a new business, and you want to see how well they are doing. The business has been running for a number of days, and your friends have recorded their net profit on each day. You want to find the largest total profit that your friends have made during any consecutive time span of at least one day. For example, if your friends' profits looked like this:
Day 1: -3
Day 2: 4
Day 3: 9
Day 4: -2
Day 5: -5
Day 6: 8
Their maximum profit over any span would be 14, from days 2 to 6.
Input
There will be several test cases in the input. Each test case will begin with an integer N(1N
250, 000) on its own line, indicating the number of days. On each of the next N lines will be a single integer P(- 100
P
100), indicating the profit for that day. The days are specified in order. The input will end with a line with a single 0.
Output
For each test case, output a single integer, representing the maximum
profit over any non-empty span of time. Print each integer on its own
line with no spaces. Do not print any blank lines between answers.
Sample Input
6
-3
4
9
-2
-5
8
2
-100
-19
0
Sample Output
14
-19
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大 int main()
{
sspeed;
int n;
while(cin>>n)
{
if(n==)
break;
ll sum=;
ll ans=;
ll a;
ll k=;
ll kiss=-maxn;
int flag=;
for(int i=;i<n;i++)
{
cin>>a;
if(a>)
{
flag=;
}
else
{
kiss=max(kiss,a);
}
sum+=a;
sum=max(sum,k);
ans=max(ans,sum);
}
if(flag==)
cout<<kiss<<endl;
else
cout<<ans<<endl;
}
return ;
}
UVALive 4869 Profits DP的更多相关文章
- UVALive 4764 简单dp水题(也可以暴力求解)
B - Bing it Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status ...
- UVALive 6908---Electric Bike(DP或记录型深搜)
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 4490 压缩DP
转载自http://blog.csdn.net/zstu_zlj/article/details/9903589 没有接触过压缩DP.位运算也不太熟.所以理解了思路还是不懂代码.
- Remember the Word UVALive - 3942(dp+trie)
题意: 给S个不同的单词和一个长字符串 问将其分解为若干个单词有多少种方法(单词可重复使用) 解析: dp[i]表示在这个字符串中以某个位置i为起点的 的一段子字符串 则这个子字符串若存在某个前缀恰好 ...
- UVALive - 7061 区间DP初步
题意:杀一只狼i会收到a[i]+b[i当前左边]+b[i当前右边]的攻击,求杀死所有狼的最小代价 #include<iostream> #include<algorithm> ...
- uvalive 6938 区间dp
看到n范围和给的区间看着就像区间dp 然后怎么cmp感觉都没法进行区间合并 n的300误导了下 没有注意离散化之后对时间可以dp 然而这个dp感觉不太经得起证明的样子... dp[i][j] -> ...
- UvaLive 5811 概率DP
题意 : 有54张牌 问抽多少张牌能使每种花色都至少是给定的数字 两张王牌可以被选择为任何花色 高放学长真是太腻害辣! 设置dp[][][][][x][y] 前四维代表四种真的花色的数量 后两维xy代 ...
- UVALive 5983 MAGRID DP
题意:在一个n*m的网格上,从(0,0)走到(n-1,m-1),每次只能向右或者向下走一格.一个人最初有一个生命值x,走到每一个格生命值会 变为x + s[i][j],(s[i][j]可为负,0,正) ...
- UVALive - 3942 (DP + Trie树)
给出一个长度不超过300000的字符串 S,然后给出 n 个长度不超过100的字符串. 如果字符串可以多次使用,用这 n 个字符串组成 S 的方法数是多少? 比如样例中,abcd = a + b + ...
随机推荐
- Linux内核触摸屏驱动--多点触摸 【转】
转自:http://blog.chinaunix.net/uid-24227137-id-3127126.html 简介 为了使用功能强大的多点触控设备,就需要一种方案去上报用户层所需的详细的手指 ...
- Microsoft.AspNet.SignalR使用cookie丢失
public void SendGroupMessage(string roomId, string message, string status) { // 调用房间内所有客户端的sendMessa ...
- C# LINQ语句
1.select 和 selectMany SelectMany() 将中间数组序列串联为一个最终结果值,其中包含每个中间数组中的每个值 2.join语句 from x in xx join d in ...
- maven学习--生命周期
clean --清理项目 default --构建项目(最核心) ===========compile , test , package , install site --生成项目站点
- java 内部类可以被覆盖吗
如果创建了一个内部类,然后继承其外围类并重新定义内部类时,"覆盖"内部类就好像是其外围类的一个方法,并不起作用, 这两个内部类是完全独立的两个实体,各自在自己的命名空间内 //: ...
- JS中给函数参数添加默认值
最近在Codewars上面看到一道很好的题目,要求用JS写一个函数defaultArguments,用来给指定的函数的某些参数添加默认值.举例来说就是: // foo函数有一个参数,名为x var f ...
- 黑马程序员_java基础笔记(11)...反射
—————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流! —————————— 1,字节码.2,Constructor类.3,Field类.4,Method类.5 ...
- nginx卸载与安装
1.卸载 在前面曾经安装过一次,这一次卸载再重新安装. 直接删除文件夹 2.更新软件源 3.依赖包安装 4.下载源码包并解压 5.增加用户组 6.安装 三个步骤 ./configure make ma ...
- C# 中从网络上下载文件保存到本地文件
下面是C#中常用的从Internet上下载文件保存到本地的一些方法,没有太多的技巧. 1.通过 WebClient 类下载文件 WebClient webClient = new WebClien ...
- Linux 的文件权限与目录配置
用户和用户组 文件所有者 (owner) 用户组概念 (group) 其他人概念 (others) Linux文件权限概念 1. Linux文件属性 要了解Linux文件属性,那么有个重要的命令必须提 ...