Bill is developing a new mathematical theory for human emotions. His recent investigations is dedicated to studying what good or bad days influent people ' s memories about some period of l Ife.
A new Idea Bill had recently developed assigns a non-negative integer value to each of the human life. Bill calls this value, the emotional value of the day. The greater the emotional value is, the better of the day was. Bill suggests the value of some period of human life are proportional to the sum of the emotional values of n the given period, multiplied by the smallest emotional value of the th in it. This schema reflects, good on average period can is greatly spoiled by one very bad day.
Now Bill was planning to investigate he own life and find the period of the had value. Help him.
Input
The input would contain several test cases, each of the them as described below. Consecutive test cases is separated by a single blank line.
The first line of the input file contains n -the number of days of Bill's life he was planning to investigate (1 n100000) . The rest of the file contains n integer numbers a1, a2,..., an ranging from 0 To 106 -The emotional values of the days. Numbers is separated by spaces and/or line breaks.
Output
For each test case, the output must follow the description below. The outputs of the consecutive cases would be separated to a blank line.
On the first line of the output file print the greatest value of some period of Bill ' s life.
On the second, line print, numbers l and R such, the period from L -th to R -th Day of Bill's life (inclusive) had the greatest possible value. If there is multiple periods with the greatest possible value and then print the shortest one. If there is still several possibilities, print the one that occurs first.
Sample Input
6 3 1 6 4 5 2
Sample Output
603 5
Test instructions: Select a continuous number of days to find the smallest value in the interval * The maximum value of the interval value:
PS: Let's go to POJ. UVA, this problem is a dead man.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Limits.h>typedef Long long ll;using namespace Std;const int maxn=1000010;int L[MAXN],R[MAXN]; LL Sum[maxn],dp[maxn];int Main () {int n; int cas=0; while (~SCANF ("%d", &n)) {memset (sum,0,sizeof (sum)); if (CAS) puts (""); cas++; for (int i=1;i<=n;i++) {scanf ("%lld", &dp[i]); Sum[i]=sum[i-1]+dp[i]; L[i]=r[i]=i; }//cout<< "23333" <<endl; for (int i=1;i<=n;i++) {if (dp[i]>0) {while (Dp[l[i]-1]>=dp[i]) L[I]=L[L[I]-1]; }}//cout<< "Hahahah" <<endl; for (int i=n;i>=1;i--) {if (dp[i]>0) {while (Dp[r[i]+1]>=dp[i]) R[I]=R[R[I]+1]; }}//cout<< "111" <<endl; LL ans=0,temp; int ll=1,rr=1; for (int i=1;i<=n;i++) {//cout<< "Fuck" <<endl; if (dp[i]>0) {temp=dp[i]* (sum[r[i]]-sum[l[i]-1]); if (Temp>ans) {ans=temp; Ll=l[i]; Rr=r[i]; } else if (Temp==ans) {if (RR-LL==R[I]-L[I]&&L[I]<LL) {Ll=l[i]; Rr=r[i]; }}}} printf ("%lld\n%d%d\n", ANS,LL,RR); } return 0;}
UVA 1619 Feel Good (DP)