Codeforces Round #613 (Div. 2) B. Just Eat It!

Posted c4lnn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #613 (Div. 2) B. Just Eat It!相关的知识,希望对你有一定的参考价值。

Link
题意:
求最大区间和所在区间是不是 (1 sim n)
思路:
(dp[i]) 是以 (i) 为右端的最大区间和
(dp[i]=max(dp[i-1]+a[i],a[i]))
代码:

#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N=1e5+5;;
 
int n;
ll a[N];
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    int T;cin>>T;
    while(T--)
    {
        cin>>n;
        ll sum=0;
        ll dp=0;
        int dp_l,dp_r;
        ll maxn=INT_MIN;
        int maxn_l,maxn_r;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            sum+=a[i];
            if(dp<=0) dp=a[i],dp_l=dp_r=i;
            else dp+=a[i],dp_r=i;
            if(maxn<dp) maxn=dp,maxn_l=dp_l,maxn_r=dp_r;
        }
        if(sum>maxn||(sum==maxn&&maxn_l==1&&maxn_r==n)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

以上是关于Codeforces Round #613 (Div. 2) B. Just Eat It!的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #613 (Div. 2)

Codeforces Round #613 (Div. 2) B. Just Eat It!

Codeforces Round #613 (Div. 2)D(贪心,分治)

Codeforces Round #613 (Div. 2) D. Dr. Evil Underscores

Codeforces Round #613 (Div. 2) B. Just Eat It!

Codeforces Round #613 (Div. 2) D - Dr. Evil Underscores(思维,位运算)