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(1
N
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 + ...
随机推荐
- jdbc一次性采集mysql和oracle的海量数据,5000W+为例
最近做的采集工具遇到采集一天数据(超过5000W行数据)的情况, 采集mysql的时候直接采用流式读取的方式可以一次全部都读取出来,速度的话取决于网络速度 stmt = conn.createStat ...
- 经典面试题:js继承方式下
上一篇讲解了构造函数的继承方式,今天来讲非构造函数的继承模式. 一.object()方法 json格式的发明人Douglas Crockford,提出了一个object()函数,可以做到这一点. fu ...
- LeetCode282. Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add bin ...
- 微信小程序蓝牙模块
蓝牙部分知识 关于Service: 每个设备包含有多个Service,每个Service对应一个uuid 关于Characteristic 每个Service包含多个Characteristic,每个 ...
- hdu 1398 整数划分变形 (母函数)
有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数 比如10全14 + 6个 14+4+1+19+1 求(1 ...
- mysql千万级表关联优化
MYSQL一次千万级连表查询优化(一) 概述: 交代一下背景,这算是一次项目经验吧,属于公司一个已上线平台的功能,这算是离职人员挖下的坑,随着数据越来越多,原本的SQL查询变得越来越慢,用户体验特别差 ...
- HBase(二)CentOS7.5搭建HBase1.2.6HA集群
一.安装前提 1.HBase 依赖于 HDFS 做底层的数据存储 2.HBase 依赖于 MapReduce 做数据计算 3.HBase 依赖于 ZooKeeper 做服务协调 4.HBase源码是j ...
- USACO 6.5 All Latin Squares
All Latin Squares A square arrangement of numbers 1 2 3 4 5 2 1 4 5 3 3 4 5 1 2 4 5 2 3 1 5 3 1 2 4 ...
- 更快的速度、更好的服务——易普优APS云排程
众所周知软件执行效率受制于硬件性能,市面上的APS产品多为单机版本,企业要应用好APS,保证紧急插单.计划下发全程无忧,用户电脑硬件性能是不容忽视的一大瓶颈.APS的直接用户是车间管理人员.计划员,而 ...
- jdk与eclipse不匹配的各种问题。。。