View Code of Problem 19

#include <iostream>
#include<string.h>
#include<algorithm>
const int maxn =1010;
using namespace std;
 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
     	int A[maxn];
		int dp[maxn]; 
    	int n;
    	while(cin>>n){
		
    	if(n==0){
    		break;
		}
    	for(int i=0;i<n;i++){
    		scanf("%d",&A[i]);
		}
		dp[0]=A[0];
		
		for(int i=1;i<n;i++){
			dp[i]=max(A[i],dp[i-1]+A[i]);
		}
		
		sort(dp,dp+n);
		
		cout<<dp[n-1]<<endl;
	
}
	
	        	
		return 0;
         }

Double click to view unformatted code.


Back to problem 19