Test instructions: To a sequence, and then to a number p, it is required that p must replace an element in the sequence, and then the sum of the maximal continuous subsequence is obtained.
Idea: The complexity of 1000*1000, O (n*n). is to try each one and then sum it up.
1#include <bits/stdc++.h>2 #defineLL Long Long3 #definePII pair<int,int>4 #defineINF 0x7f7f7f7f5 using namespacestd;6 Const intn= -;7 intA[n];8 9 intMain ()Ten { OneFreopen ("E://input.txt","R", stdin); A intN, p, T; -Cin>>T; - while(t--) the { -scanf"%d%d",&n,&p); - for(intI=0; i<n; i++) scanf ("%d",&a[i]); - +LL Ans=p, sum=0; - for(intI=0; i<n; i++) + { A //cout<<a[i]<<endl; at inttmp=A[i]; -a[i]=p; -sum=0; - for(intj=0; j<n; J + +) - { -sum+=A[j]; in if(Sum>ans) ans=sum; - if(sum<0) sum=0; to } +a[i]=tmp; - } theprintf"%lld\n", ans); * } $ return 0;Panax Notoginseng}
AC Code
HDU 5280 Senior ' s Array (violence, water)