G - Profits

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(1N250, 000) on its own line, indicating the number of days. On each of the next N lines will be a single integer P(- 100P100), 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的更多相关文章

  1. UVALive 4764 简单dp水题(也可以暴力求解)

    B - Bing it Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status ...

  2. UVALive 6908---Electric Bike(DP或记录型深搜)

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. UVALive 4490 压缩DP

    转载自http://blog.csdn.net/zstu_zlj/article/details/9903589 没有接触过压缩DP.位运算也不太熟.所以理解了思路还是不懂代码.

  4. Remember the Word UVALive - 3942(dp+trie)

    题意: 给S个不同的单词和一个长字符串 问将其分解为若干个单词有多少种方法(单词可重复使用) 解析: dp[i]表示在这个字符串中以某个位置i为起点的 的一段子字符串 则这个子字符串若存在某个前缀恰好 ...

  5. UVALive - 7061 区间DP初步

    题意:杀一只狼i会收到a[i]+b[i当前左边]+b[i当前右边]的攻击,求杀死所有狼的最小代价 #include<iostream> #include<algorithm> ...

  6. uvalive 6938 区间dp

    看到n范围和给的区间看着就像区间dp 然后怎么cmp感觉都没法进行区间合并 n的300误导了下 没有注意离散化之后对时间可以dp 然而这个dp感觉不太经得起证明的样子... dp[i][j] -> ...

  7. UvaLive 5811 概率DP

    题意 : 有54张牌 问抽多少张牌能使每种花色都至少是给定的数字 两张王牌可以被选择为任何花色 高放学长真是太腻害辣! 设置dp[][][][][x][y] 前四维代表四种真的花色的数量 后两维xy代 ...

  8. UVALive 5983 MAGRID DP

    题意:在一个n*m的网格上,从(0,0)走到(n-1,m-1),每次只能向右或者向下走一格.一个人最初有一个生命值x,走到每一个格生命值会 变为x + s[i][j],(s[i][j]可为负,0,正) ...

  9. UVALive - 3942 (DP + Trie树)

    给出一个长度不超过300000的字符串 S,然后给出 n 个长度不超过100的字符串. 如果字符串可以多次使用,用这 n 个字符串组成 S 的方法数是多少? 比如样例中,abcd = a + b + ...

随机推荐

  1. MySQL 5.6 GTID Replication【转】

    一. MySQL 5.6引入了GTID的概念,那么GTID是何方神圣?其实也不复杂,就是一个全局事务标示符.使用GTID时,每次事务提交都会在binlog里生成1个唯一的标示符,它由UUID和事务ID ...

  2. centos 升级linux内核

    =============================================== 2018/1/14_第1次修改                       ccb_warlock == ...

  3. ubuntu 16.04 网卡配置 虚拟机上网

    看所有网卡(包括未启动的) ifconfig -a 或者 ip link 查看当前网卡配置,打开配置文件/etc/network/interfaces 设置静态IP(dhcp 为动态获取,static ...

  4. Python3 出现'ascii' codec can't encode characters问题

    当使用urllib.request.urlopen打开包含中文的链接时报错: from urllib import request url = 'https://baike.baidu.com/ite ...

  5. css文字环绕图片--遇到的问题及解决方法

    一.前言 需要实现一个文字环绕图片的效果,心想so easy嘛. 1)代码部分 <style> .img-left { border: 3px solid #005588; width:3 ...

  6. python类、类继承

    yield: 简单地讲,yield 的作用就是把一个函数变成一个 generator,带有 yield 的函数不再是一个普通函数,Python 解释器会将其视为一个 generator,调用 fab( ...

  7. Tetris:pygame实现

    网上搜到一个Pygame写的俄罗斯方块(tetris),大部分看懂的前提下增加了注释,Fedora19下运行OK的 主程序: #coding:utf8 #! /usr/bin/env python # ...

  8. 树莓派3B更换源为阿里源

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #科大源 sudo nano /etc/apt/sources.list deb htt ...

  9. Elasticsearch 6.x 的分页查询数据

    { , "query": { "match" : { "person_name" : "张老师" }}, , ], &q ...

  10. 【AtCoder】AGC023 A-F题解

    可以说是第一场AGC了,做了三道题之后还有30min,杠了一下D题发现杠不出来,三题滚粗了 rating起步1300+,感觉还是很菜... 只有三题水平显然以后还会疯狂--啊(CF的惨痛经历) 改题的 ...