HDU Max Sum plus Plus (max and sub-sequence enhanced)

Source: Internet
Author: User

Max Sum plus Plus

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 17906 Accepted Submission (s): 5864


Problem Descriptionnow I Think you have got a AC in IGNATIUS.L ' s "Max Sum" problem. To is a brave acmer, we always challenge ourselves to more difficult problems. Now you is faced with a more difficult problem.

Given a consecutive number sequence S 1+ t 2+ t 3+ t 4... S x, ... S N(1≤x≤n≤1,000,000, -32768≤s x≤32767). We define a function sum (i, j) = S I+ ... + S J(1≤i≤j≤n).

Now given a integer m (M > 0), your task is to find m pairs of I and J which make sum (i 1J 1) + SUM (i 2J 2) + SUM (i 3J 3) + ... + sum (i mJ m) Maximal (i x≤i y≤j xOr I x≤j y≤j xis not allowed).

But I ' m lazy, I don't want to the write a Special-judge module, so you don ' t has to output m pairs of I and j, just output th e maximal summation of sum (i xJ x) (1≤x≤m) instead. ^_^

Inputeach test case would begin with a integers m and n, followed by n integers S 1, S 2, S 3... S N.
Process to the end of file. Outputoutput the maximal summation described above in one line. Sample INPUT1 3 1 2 6-1 4-2 3-2 3 Sample Output68
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <iostream>5 #defineINF 9999999996 //using namespace std;7 Const intMAX =1000005;8 intMaxintAintb)9 {Ten     returnA>b?a:b; One } A intA[max]; - intLeft[max]; - intRight[max]; the intMain () - { -     intn,m,i,j; -      while(SCANF ("%d%d", &m,&n)! =EOF) +     { -Memset (A,0,sizeof(a)); +Memset (left,0,sizeof(left)); AMemset (right,0,sizeof(right)); at          for(i=1; i<=n;i++) -scanf"%d",&a[i]); -         Long Longcount; -          for(i=1; i<=m;i++) -         { -count=-inf; in              for(j=i;j<=n;j++) -             { toLeft[j]=max (left[j-1],right[j-1])+A[j]; +right[j-1]=count; -                 if(left[j]>count) theCount=Left[j]; *             } $         }Panax Notoginsengprintf"%i64d\n", count); -     } the     return 0; +}
View Code

HDU Max Sum plus Plus (max and sub-sequence enhanced)

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.