6 条题解

  • 1
    @ 2024-7-24 15:15:27
    #include<bits/stdc++.h>
    using namespace std;
    const int INF=0x3f3f3f;
    
    int n,a,cnt = -INF,sum;
    
    int main(){
    
        cin>>n;
        for(int i = 1;i<=n;i++){
            cin>>a;
            if(sum>0)
                sum += a;
            else
                sum = a;
                cnt = max(sum,cnt);
        }
        cout<<cnt;
    }
    
    • 1
      @ 2024-5-27 22:46:39

      最简代码

      #include<bits/stdc++.h>
      using namespace std;
      
      const int N=1e6+10;
      long long s[N],a[N],n,maxx;
      
      int main(){
      	cin>>n;
      	s[0]=0;
      	for(int i=1;i<=n;i++){
      		cin>>a[i];
      		s[i]=max(s[i-1]+a[i],a[i]);
      		maxx=max(maxx,s[i]);
      	}
      	cout<<maxx;
      	return 0;
      }
      
      • -1
        @ 2024-7-24 15:16:23

        双指针外挂提交

        #include<iostream>
        using namespace std;
        int num[200005], dp[200005];
        long long n,ans=-1000,cnt;
        int main(){
        	cin>>n;
        	for(int i=1;i<=n;i++){
        		cin>>dp[i];
        		if(cnt>0){
        			cnt+=dp[i];
        		}
        		else{
        			cnt=dp[i];
        		
        		}
        			ans=max(ans,cnt);
        	}
        	cout<<ans;
        
        	
        	 
        
        return 0;
        }
        
        • -1
          @ 2024-5-28 16:35:15
          #include<bits/stdc++.h>
          using namespace std;
          const int N=1e6+10;
          long long s[N],a[N],n,maxx;
          int main(){
          cin>>n;
          s[0]=0;
          for(int i=1;i<=n;i++){
          cin>>a[i];
          s[i]=max(s[i-1]+a[i],a[i]);
          maxx=max(maxx,s[i]);
          }
          cout<<maxx;
          return 0;
          }
          

          复制👍

          • -1
            @ 2024-5-25 19:43:37
            #include<iostream>
            using namespace std;
            int num[200005], dp[200005];
            int main(){
            int a, ans = -1e9;
            cin >> a;
            for(int i = 1; i <= a; i++){
            cin >> num[i];
            }
            for(int i = 1; i <= a; i++){
            dp[i] = max(dp[i-1] + num[i], num[i]);
            ans = max(ans, dp[i]);
            }
            cout << ans << endl;
            return 0;
            }
            

            直接完成题目并提交

          • -1
            @ 2021-11-6 23:32:23
            #include<iostream>
            using namespace std;
            int num[200005], dp[200005];
            int main(){
            int a, ans = -1e9;
            cin >> a;
            for(int i = 1; i <= a; i++){
            cin >> num[i]; //键入数组
            }
            for(int i = 1; i <= a; i++){
            dp[i] = max(dp[i-1] + num[i], num[i]);
            ans = max(ans, dp[i]);
            }
            cout << ans << endl;
            return 0;
            }
            
          • 1

          信息

          ID
          1408
          时间
          1000ms
          内存
          128MiB
          难度
          5
          标签
          递交数
          235
          已通过
          89
          上传者