Uva-1619-feel Good

Source: Internet
Author: User
Tags integer numbers

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

60 3 5

Enumerate each value as the interval minimum to find the maximum interval, and then enumerate each case to find the maximum value.

AC Code:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring > #include <string> #include <sstream> #include <vector> #include <set> #include <map># Include <algorithm> #include <stack> #include <queue> #include <bitset> #include <cassert  > #include <cmath> #include <functional>using namespace std;typedef long long ll;const int MAXN = 100005;int N, A[maxn], L[MAXN], r[maxn];//l[i] indicates the position of I to the left of the first element of the I element//r[i] indicates that I right is less than the position of the first element of the I element ll SUM[MAXN];  Sum[i] represents the first and stack<int> q;void init () {sum[0] = 0;for (int i = 1; I <= n; i++) {cin >> a[i];sum[i] = sum[i -1] + a[i];} A[0] = a[n + 1] = -0x3f3f3f3f;while (!q.empty ()) {Q.pop ();} Q.push (0); for (int i = 1; I <= n; i++) {while (A[q.top ()] >= a[i]) {Q.pop ();} L[i] = Q.top (); Q.push (i);} while (!q.empty ()) {Q.pop ();} Q.push (n + 1), for (int i = n, i; i--) {while (A[q.top ()] >= a[i]) {Q.pop ();} R[i] = Q.top (); Q.push (i);}} int main () {Ios::sync_with_stdio (false), int kase = 0;while (cin >> N) {if (kase++) {cout << Endl;} Init (); LL ans = 0;int L, r;for (int i = 1; I <= n; i++) {LL t = a[i] * (Sum[r[i]-1]-sum[l[i]]); if (T > ans) {ans = t;l = L[i] + 1;r = r[i]-1;} else if (t = = ans && r[i]-l[i]-1 < r-l + 1) {L = L[i] + 1;r = r[i]-1;}} if (ans = = 0) {//special case cout << "0\n1 1\n";} else {cout << ans << endl << l << ' << r << Endl;}} return 0;}



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

Uva-1619-feel Good

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.