Uva507-Jill rides again (maximum continuous sum)

Source: Internet
Author: User

Question: uva507-Jill rides again (maximum continuous sum)


Satisfaction Between each two sites. The sum of the satisfactory routes must be no less than 0. to help jill find out the path she is satisfied with, the request is the longest, and if the length is the same, the site is relatively high.


Code:

#include <stdio.h>#include <string.h>const int N = 20005;int s, b, e;int stop[N];int solve () {int mm = stop[1];int sum = stop[1];int tems = 1;b = e = 1;if (sum < 0) {tems = 2;sum = 0;}for (int i = 2; i < s; i++) {sum += stop[i];if (sum < 0) {tems = i + 1;sum = 0;}else if (sum >= mm) {if ( (sum == mm && i - tems > e - b) || sum > mm) {b = tems;e = i;mm = sum;}}}return mm;}int main () {int t;scanf ("%d", &t);for (int i = 1; i <= t; i++) {scanf("%d", &s);for (int j = 1; j < s; j++)scanf ("%d", &stop[j]);int mm = solve();if (mm < 0)printf ("Route %d has no nice parts\n", i);elseprintf ("The nicest part of route %d is between stops %d and %d\n", i, b, e + 1);}return 0;}


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.