#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
struct node {
int num;
int pos;
};
int main() {
// freopen("input", "r", stdin);
int n;
int a[maxn], s[maxn];
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++)
cin >> a[i];
s[1] = a[1];
for (int i = 2; i <= n; i++)
s[i] = s[i - 1] + a[i];
stack<node> aa, b; int fro[maxn], beh[maxn];
// aa.push((node){a[1], 1});
// b.push((node){a[n], n});
fro[1] = 1;
beh[n] = n;
for (int i = 1; i <= n; i++) {
node x;
if (!aa.empty())
x = aa.top();
else
x = (node){0, 0};
while (x.num >= a[i] && x.pos != i && !aa.empty()) {
aa.pop();
if (!aa.empty())
x = aa.top();
else
x = (node){0, 0};
}
aa.push((node){a[i], i});
if (x.pos != 0)
fro[i] = x.pos + 1;
else
fro[i] = 1;
}
for (int i = n; i >= 1; i--) {
node x;
if (!b.empty())
x = b.top();
else
x = (node){0, 0};
while (x.num >= a[i] && x.pos != i && !b.empty()) {
b.pop();
if (!b.empty())
x = b.top();
else
x = (node){0, 0};
}
b.push((node){a[i], i});
if (x.pos != 0)
beh[i] = x.pos - 1;
else
beh[i] = n;
}
long long ans = 0;
int L;
int R;
for (int i = 1; i <= n; i++) {
long long x = a[i] * (s[beh[i]] - s[fro[i]] + a[fro[i]]);
if (x > ans) {
ans = x;
L = fro[i];
R = beh[i];
}
}
cout << ans << endl << L << ' ' << R << endl;
}
}

[UVa 1619]Feel Good的更多相关文章

  1. UVA 1619 Feel Good(DP)

    Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...

  2. POJ 2796[UVA 1619] Feel Good

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16786   Accepted: 4627 Case T ...

  3. uva 1619 - Feel Good || poj 2796 单调栈

    1619 - Feel Good Time limit: 3.000 seconds   Bill is developing a new mathematical theory for human ...

  4. UVA 1619/POJ2796 滑窗算法/维护一个单调栈

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12409   Accepted: 3484 Case T ...

  5. UVA 1619 Feel Good 感觉不错 (扫描法)

    Feel Good Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Bill is deve ...

  6. UVA - 1619 Feel Good(扫描法)

    题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...

  7. POJ 2796 / UVA 1619 Feel Good 扫描法

    Feel Good   Description Bill is developing a new mathematical theory for human emotions. His recent ...

  8. 【习题 8-18 UVA - 1619】Feel Good

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用单调队列求出l[i]和r[i] 分别表示i的左边最近的大于a[i]的数的位置以及i右边最近的大于a[i]的数的位置. 则l[i]+ ...

  9. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

随机推荐

  1. bzoj3551 Peaks加强版

    这个题--感觉离线和在线的代码难度差不多(pb_ds不要说话). 离线的话,就是把所有询问按照w排个序,然后一边Kruskal+平衡树启发式合并一边回答询问就好了. 在线也不难写.首先Kruskal重 ...

  2. C#导出涉及行列合并的复杂的Excel数据

    一.导出数据格式 二.实现代码 /// <summary> /// 导出经费统计excel表格 /// </summary> /// <param name=" ...

  3. HDU 5102 The K-th Distance(模拟)

    题意:输入一棵树,输出前k小的点对最短距离dis(i,j)的和. 模拟,官方题解说得很清楚了.不重复了. http://bestcoder.hdu.edu.cn/ 需要注意的是,复杂度要O(n+k), ...

  4. 【python】isinstance可以接收多个类型,hasattr,getattr,setattr

    来源:廖雪峰 可以判断一个变量是否是某些类型中的一种,比如下面的代码就可以判断是否是str或者unicode: >>> isinstance('a', (str, unicode)) ...

  5. http升https笔记

    证书申请的: 1.lets encrypt 国际公益项目发展很快的,不过在国内暂时有些支持度还不够高,如微信安卓版就不认lets encrypt的证书.跳转进去一直处于空白页状态 2.沃通证书  国内 ...

  6. Asp.Net MVC4 + Oracle + EasyUI 学习 第二章

    Asp.Net MVC4 + Oracle + EasyUI 第二章 --使用Ajax提升网站性能 本文链接:http://www.cnblogs.com/likeli/p/4236723.html ...

  7. 用C#通过正则表达式截取字符串中符合条件的子字符串

    仅仅作为简单的记录,不多说直接上代码(仅测试使用): private void Test() { Regex ConnoteA = new Regex("^[a-zA-Z]\\d{8}$&q ...

  8. hdu 5073

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5073 思路:一开始忘了排序,wa了好几发...选择区间长度为N - K的连续的数, 然后其余的K个数都 ...

  9. Android_ListView简单例子

    ListView是Android软件开发中非常重要组件之一,基本上是个软件基本都会使用ListView ,今天我通过一个demo来教大家怎么样使用ListView组件 activity_main.xm ...

  10. poj2631 求树的直径裸题

    题目链接:http://poj.org/problem?id=2631 题意:给出一棵树的两边结点以及权重,就这条路上的最长路. 思路:求实求树的直径. 这里给出树的直径的证明: 主要是利用了反证法: ...