4 solutions

  • 0
    @ 2025-4-19 19:54:30
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    int a[N],f[N];
    int main(){
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    	}
    	for(int i=1;i<=n;i++)
    	{	if(f[i-1]>0)
    		{
    			f[i]=f[i-1]+a[i];
    		}
    		else
    		{
    			f[i]=a[i];
    		}
    	}
    	int res=-2147483648;
    	for(int i=1;i<=n;i++)
    	{
    		res=max(res,f[i]);
    	}
    	cout<<res;
    	return 0;
    }
    
    

    Information

    ID
    2140
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    36
    Accepted
    18
    Uploaded By