zoukankan      html  css  js  c++  java
  • 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
    所遇皆星河
  • 相关阅读:
    java控制台输入
    冒泡排序
    选择排序
    Json数组去重
    HTTP状态码详解
    根据json对象的值替换json数组里的值
    用户中心页面
    正则表达式
    vue-router如何根据不同的用户给不同的权限
    vue2.0+element+node+webpack搭建的一个简单的后台管理界面
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12990465.html
Copyright © 2011-2022 走看看