Bestcoder 47# A

Source: Internet
Author: User

Senior ' s ArrayTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 514 Accepted Submission (s): 199


Problem Descriptionone Day, Xuejiejie gets an array A . Among all non-empty intervals of A , she wants to find the most beautiful one. She defines the beauty as the sum of the interval. The beauty of the interval--- [L,R] is calculated by this formula:beauty (l,r) = A[L]+A[L+1]+... ..... ..+A[R] . The most beautiful interval are the one with maximum beauty.

But as are known to all, Xuejiejie are used to pursuing perfection. She wants to get a more beautiful interval. So she asks Mini-sun. Mini-sun is a magician, but he is busy reviewing calculus. So he tells Xuejiejie this he can just help she change one value of the element of A To P . Xuejiejie plans to come to see him in tomorrow morning.

Unluckily, Xuejiejie oversleeps. Now the decision which one should is changed (you must change one element).
Inputin the first line there are an integer T , indicates the number of test cases.

The first line contains integers n and P . n means the number of elements of the array. P means the value Mini-sun can change to.

The next line contains the original array.

1≤n≤ , ? ten 9 ≤A[I],P ≤ ten 9 。
Outputfor each test case, output one integer which means the most beautiful interval ' s beauty after your change.
Sample Input
23 51-1 23-21-1 2

Sample Output
82

Sourcebestcoder Round #47 ($)
Recommendhujie | We have carefully selected several similar problems for you:5283 5282 5281 5279 5278

Test instructions: gives you a value that changes the values of an element in a number (a[i] = p) To change the maximum substring of the array and must be changed

Idea: Data comparison pit if not __int64 will be heck off

#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;__int64 A[1005];__int64 Sum[1005];__int64 ssum[1005];int Main () {    __int64  t;    scanf ("%i64d", &t);    while (t--)    {        __int64 n,p;        scanf ("%i64d%i64d", &n,&p);        A[0] = 0;        Sum[0] = 0;        __int64 mx=-999999999;        for (__int64 i = 0; i < n; i++)            scanf ("%i64d", &a[i]);        for (__int64 i = 0; i < n; i++)        {            __int64 tp = a[i];            A[i] = p;             for (__int64 j = 0;j < n;j++)            {                if (j)                sum[j] = A[j] > sum[j-1]+a[j]? a[j]: sum[j-1]+a[j];                else                    Sum[j]=a[j];                if (sum[j]>mx)                    mx=sum[j];//                cout<<sum[j]<<endl;            }            A[i] = TP;        }        printf ("%i64d\n", Mx);}    }



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bestcoder 47# A

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.