• D. Yet Another Yet Another Task (区间最值)


    https://codeforces.com/contest/1359/problem/D

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <list>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <iomanip>
    #define pi acos(-1)
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define all(vc) vc.begin() , vc.end()
    #define rep(i,start,end) for(int i=start;i<=end;i++)
    #define per(i,end,start) for(int i=end;i>=start;i--)
    #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define lc now<<1
    #define rc now<<1|1
    ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    using namespace std;
    const int mod = 998244353;
    const int mxn = 1e6 +7;
    const int inf = 1e9;
    int _,n,m,t,k,u,v,w,ans,cnt,ok,lim,len,tmp,last,nx;
    struct node {int u,v,nx,w;}e[mxn];
    string str;
    int a[mxn];
    void solve()
    {
        ans = 0 ;
        for(int i=1;i<=30;i++)
        {
            int nowans = 0 , nowmin = 0 ;
            for(int j=1;j<=n;j++)
            {
                if(a[j]>i){
                    nowans = 0 , nowmin = 0 ; continue;
                }
                nowans += a[j] ;
                nowmin = min( nowmin , nowans  );
                ans = max(nowans-nowmin-i , ans);
            }
        }
        cout<<ans<<endl;
    }
    int main()
    {
        tle;
        while(cin>>n)
        {
            for(int i=1;i<=n;i++) cin>>a[i];
            solve();
        }
    }
    View Code
    所遇皆星河
  • 相关阅读:
    CSS
    CSS
    HTML
    HTML
    HTML
    ubuntu server安装的一些坑
    Haproxy 开启日志记录
    nginx反向代理时保持长连接
    最简单的tomcat安装部署
    nginx的安装部署以及使用
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12990465.html
Copyright © 2020-2023  润新知