HDU 5783 Divide The Sequence (series division)

Source: Internet
Author: User

HDU 5783 Divide The Sequence (series division)

Time Limit: 5 000/ - xx MS (java/others) Memory limit:65536/65536 K (java/others)

problem Description-topic descriptionAlice has a sequence A, She wants to split a into as much as possible continuous subsequences, satisfying the for EAC H subsequence, every its prefix sum are not small than 0.
Alice has a series A, she wants to split a into as many substrings as possible, and any prefix and each substring is greater than 0.
CN Input-EnterThe input consists of multiple test cases.
Each test case is begin with a integer n
The next line contains n integers a1,a2? an.
1≤n≤1e6
? 10000≤a[i]≤10000
You can assume this there is at least one solution.
multiple sets of test cases. The first behavior of each set of test cases is an integer n. The next line has n integers a1,a2? An.  1≤n≤1e6? 10000≤a[i]≤10000 You may think that there is no solution. 
CN
output-Outputsfor each test case, output an integer indicates the maximum number of sequence division.
For each set of test cases, output the maximum number of divisions for this sequence.
CN 

Sample Input-Enter sample

61 2 3 4 5 641 2-3 050 0 0 0 0

Sample output-export example

625

Exercises

Greedy, at the beginning of the wrong topic, has not thought out solution, wasted a lot of time ...
All prefixes of a substring 1 2 3 are

11 21 2 3


Obviously if there is a negative number, you need the positive number to make up, anyway, can not meet the conditions.
The practice is to scan from the back forward, record the temporary post N and, >=0 is emptied, dividing the number +1.
The limit data should be 5e5 * 10000 = 5E9, the pure int will be super, need __int64.

Code C + +

1#include <cstdio>2__int64 data[1000001];3 intMain () {4 __int64 N, I, opt, tmp;5      while(~SCANF ("%i64d", &N)) {6          for(i = opt = TMP =0; I < n; ++i) scanf ("%i64d", Data +i);7          for(I. ~i;--i) {8TMP + =Data[i];9             if(TMP >=0) TMP =0, ++opt;Ten         } Oneprintf"%i64d\n", opt); A     } -     return 0; -}



HDU 5783 Divide The Sequence (series division)

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.