1. 程式人生 > >51 nod 1049 最大字段和(一維的)

51 nod 1049 最大字段和(一維的)

long main color col def opened nbsp pre CI

技術分享圖片
 1 #include <iostream>
 2 using namespace std;
 3 #define ll long long
 4 
 5 int main()
 6 {
 7     int n;
 8     cin>>n;
 9     ll x;
10     ll sum=0;
11     ll maxn=0;
12     for(int i=0;i<n;i++){
13         cin>>x;
14         sum+=x;
15         if(sum<=0){
16             sum=0
; 17 } 18 maxn=max(maxn,sum); 19 } 20 cout<<maxn<<endl; 21 return 0; 22 }
View Code

51 nod 1049 最大字段和(一維的)