Feel good
| Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
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<tex2html_verbatim_mark>-the number of days of Bill's life He is planning to investigate (1n100000) <tex2html_verbatim_mark>. The rest of the file contains n<tex2html_verbatim_mark> integer numbers a1, a2, ..., an<tex2html_verbatim_mark> ranging from 0 to 106<tex2html_verbatim_mark>-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<tex2html_verbatim_mark> R<tex2html_ Verbatim_mark> such that the period from l<tex2html_verbatim_mark>-th to R< Tex2html_verbatim_mark>-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
60 3 5
For a minimum-value AI, the selected interval should be as large as possible until the selection is not guaranteed to stop when the AI is the minimum value.
Maintain a forward-extending maximum position during the scanning process, and when extending, pay attention to transitivity, and if the previous element is smaller than it, then the previous element can extend to the position,
The current element can also be extended to, and then the chain is similar to that of a linked list to go forward. Looking backwards is similar. Interval and with a prefix and to handle.
#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e5+5; typedefLong Longll;intA[maxn],l[maxn],r[maxn],n;ll SUM[MAXN];intMain () {intR0; sum[0] =0; a[0] = -1; while(~SCANF ("%d",&N)) { if(t++) Putchar ('\ n'); A[n+1] = -1; for(inti =1; I <= N; i++) scanf ("%d", A+i), sum[i] = sum[i-1]+a[i],l[i]=r[i]=i; for(inti =1; I <= N; i++){ while(a[i]<=a[l[i]-1]) L[i] = l[l[i]-1]; } for(inti = n; I >=1; i--){ while(a[i]<=a[r[i]+1]) R[i] = r[r[i]+1]; } ll Max= (LL) a[1]*a[1]; intL =1, R =1; for(inti =1; I <= N; i++) {ll tmp= (sum[r[i]]-sum[l[i]-1])*A[i]; if(tmp > Max | | (tmp = = Max && r-l > R[i]-L[i])) {Max=tmp; L= L[i]; R =R[i]; }} printf ("%lld\n%d%d\n", Max,l,r); } return 0;}
UVA 1619 Feel Good Feel Good (scanning method)