C language · and maximum sub-sequences

Source: Internet
Author: User

Algorithm increase and maximum sub-sequence time limit: 1.0s memory limit: 512.0MBProblem description for a given integer sequence a of length n, the definition of its "subsequence" is: a non-empty contiguous element (integer). The task you want to accomplish is to find a subsequence in all possible sub-sequences, and the maximum of all the elements in that subsequence (as compared to all other subsequence sequences). The program requires you to output this maximum value. Input format the first line of the input file contains an integer n, the second line contains n integers, indicating a.
1 <= N <= 100000
-10000 <= A[i] <= 10000 output format output contains only an integer that represents the answer you have calculated. Sample input
53-2 3-5 4

Sample output


1#include <stdio.h>2 intMain () {3     intN;4     intmaxsum=0;5     intsum=0;6scanf"%d",&n);7     intA[n];8      for(intI=0; i<n;i++){9scanf"%d",&a[i]);Ten     } One      for(intI=0; i<n;i++){ Asum+=A[i]; -         if(sum>maxsum) { -Maxsum =sum; the}Else{ -sum=0; -         } -     } +printf"%d", maxsum); -     return 0; +}

C language · and maximum sub-sequences

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.