zoukankan      html  css  js  c++  java
  • UVALive 4869 Profits DP

    G - Profits
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    Description

    Download as PDF

    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$ le$N$ le$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$ le$P$ le$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==0)
                break;
            ll sum=0;
            ll ans=0;
            ll a;
            ll k=0;
            ll kiss=-maxn;
            int flag=0;
            for(int i=0;i<n;i++)
            {
                cin>>a;
                if(a>0)
                {
                    flag=1;
                }
                else
                {
                    kiss=max(kiss,a);
                }
                sum+=a;
                sum=max(sum,k);
                ans=max(ans,sum);
            }
            if(flag==0)
                cout<<kiss<<endl;
            else
                cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    C#面向对象之封装。
    python 数据处理学习pandas之DataFrame
    有用的vscode快捷键大全+自定义快捷键
    angular中控制器之间传递参数的方式
    angular.module 详解
    如何让类数组也使用数组的方法比如:forEach()
    CSS之flex兼容
    JavaScript中捕获/阻止捕获、冒泡/阻止冒泡
    Vue2.0 探索之路——生命周期和钩子函数的一些理解
    React 生命周期
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4238208.html
Copyright © 2011-2022 走看看