#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. SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configur

    参见:http://msdn.microsoft.com/zh-cn/library/ms191188(SQL.105).aspx Ole Automation Procedures 选项 [本主题为 ...

  2. Ubuntu配置svn

    http://www.cnblogs.com/arrongao/archive/2013/03/30/linux_svn.html

  3. CentOS7 屏幕亮度的命令行管理

    1.安装:yum install xgamma 设置亮度:xgamma -gamma n( 0.1 < n < 10.0 ,可以根据自己的喜好设置 2.shell 系统调节亮度调用的是/s ...

  4. windows Service

    用c#中创建一个windows服务非常简单,与windows服务相关的类都在System.ServiceProcess命名空间下. 每个服务都需要继承自ServiceBase类,并重写相应的启动.暂停 ...

  5. 51nod1072(wythoff 博弈)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1072 题意: 中文题诶~ 思路: 博弈套路是有的, 找np局 ...

  6. ca 自签名证书 并实现HAProxy https功能

    mkdir /etc/ssl/xip.io [root@ha02 haproxy-]# openssl genrsa - Generating RSA bit long modulus ....... ...

  7. SpringBoot实战配置

    http://blog.csdn.net/sun_t89/article/details/51944252 http://www.cnblogs.com/kreo/p/4423362.html

  8. 基于类的命令行notebook的实现

    在看一本书<PYTHON3 面向对象编程> 内容丰富,作作记录. notebook.py __author__ = 'chengang882' import datetime # Stor ...

  9. Power BI FAQ

    关于Power BI,最近一直想写点什么,但是也想不到写什么.直到前几天,有个朋友在qq加我,问了我好几个问题,我发现都是一些很有代表性的问题,所以都记录了下来,特意整理了一下分享出来,希望能帮到更多 ...

  10. linux下将不同线程绑定到不同core和cpu上——pthread_setaffinity_np

    =============================================================== linux下的单进程多线程的程序,要实现每个线程平均分配到多核cpu,主 ...