Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=5280
Senior ' s arraydescription
One 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).
Input
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\leq N\leq 1000$, $-10^9\leq a[i], P\leq 10^9$.
Output
For each test case, the output one integer which means the most beautiful interval ' s beauty after your change.
2
3 5
1-1 2
3-2
1-1 2
Sample Output
8
2
Data is only 1000 direct violence.
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <map>8 usingStd::max;9 usingstd::cin;Ten usingstd::cout; One usingStd::endl; A usingStd::find; - usingStd::sort; - usingStd::map; the usingstd::p air; - usingstd::vector; - usingStd::multimap; - #definePB (E) push_back (e) + #defineSZ (c) (int) (c). Size () - #defineMP (A, b) Make_pair (A, B) + #defineAll (c) (c). Begin (), (c). End () A #defineITER (c) Decltype ((c). Begin ()) at #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 1; I <= (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - Const intN =1010; - Const intINF =0x7fffffff; intypedefLong Longll; - ll P, ans, arr[n], sum[n]; to intMain () { + #ifdef LOCAL -Freopen ("In.txt","R", stdin); theFreopen ("OUT.txt","w+", stdout); * #endif $ intt, N;Panax Notoginsengscanf"%d", &t); - while(t--) { theAns =-INF; +scanf"%d%lld", &n, &p); ARep (i, N) scanf ("%lld", &arr[i]); the Rep (i, N) { +ll tmp = Arr[i]; Arr[i] =p; - Rep (j, N) { $SUM[J] = sum[j-1] >0? Sum[j-1] +Arr[j]: arr[j]; $Ans =Max (ans, sum[j]); - } -Arr[i] =tmp; the } -printf"%lld\n", ans);Wuyi } the return 0; -}View Code
Hdu 5280 Senior ' s Array