POJ——T 2796 Feel Good
http://poj.org/problem?id=2796
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 15375 | Accepted: 4252 | |
Case Time Limit: 1000MS | Special Judge |
Description
A new idea Bill has recently developed assigns a non-negative integer value to each day of human life.
Bill calls this value the emotional value of the day. The greater the emotional value is, the better the daywas. Bill suggests that the value of some period of human life is proportional to the sum of the emotional values of the days in the given period, multiplied by the smallest emotional value of the day in it. This schema reflects that good on average period can be greatly spoiled by one very bad day.
Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.
Input
Output
Sample Input
6
3 1 6 4 5 2
Sample Output
60
3 5
Source
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; #define LL long long
const int N(+);
int ans_l,ans_r,l[N],r[N];
LL n,ans_val=-,sum[N],val[N]; inline void read(LL &x)
{
x=; LL ch=getchar();
for(;ch>''||ch<'';) ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=ch-''+x*;
} int main()
{
read(n);
for(int i=;i<=n;i++)
{
read(val[i]),l[i]=r[i]=i;
sum[i]=sum[i-]+val[i];
}
for(int i=;i<=n;i++)
for(;l[i]>&&val[l[i]-]>=val[i];)
l[i]=l[l[i]-];
for(int i=n-;i>=;i--)
for(;r[i]<n&&val[r[i]+]>=val[i];)
r[i]=r[r[i]+];
for(int i=;i<=n;i++)
{
LL tmp=val[i]*(sum[r[i]]-sum[l[i]-]);
if(tmp>ans_val)
{
ans_l=l[i];
ans_r=r[i];
ans_val=tmp;
}
}
printf("%I64d\n%d %d",ans_val,ans_l,ans_r);
return ;
}
POJ——T 2796 Feel Good的更多相关文章
- 【POJ】2796:Feel Good【单调栈】
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18449 Accepted: 5125 Case T ...
- [poj 2796]单调栈
题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include ...
- POJ 2796:Feel Good(单调栈)
http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://ww ...
- POJ 2796 Feel Good 【单调栈】
传送门:http://poj.org/problem?id=2796 题意:给你一串数字,需要你求出(某个子区间乘以这段区间中的最小值)所得到的最大值 例子: 6 3 1 6 4 5 2 当L=3,R ...
- POJ 2796[UVA 1619] Feel Good
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16786 Accepted: 4627 Case T ...
- poj 2796 Feel Good单调栈
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20408 Accepted: 5632 Case T ...
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- Poj 2796 单调栈
关于单调栈的性质,和单调队列基本相同,只不过单调栈只使用数组的尾部, 类似于栈. Accepted Code: /******************************************* ...
- POJ 2796 Feel Good(单调栈)
传送门 Description Bill is developing a new mathematical theory for human emotions. His recent investig ...
随机推荐
- tab.py
vim tab.py #!/usr/bin/env python # #Tab import sys import readline import rlcompleter import atexit ...
- 【Appium】每次启动是提示安装setting和unlock app的解决办法
进入appium安装目录,C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android,编辑android.js文件,注释 ...
- WHU 1548 Home 2-SAT
---恢复内容开始--- 题意: N个人想回家在至少一个时刻.至多两个时刻.并且,他们每个人都能独自回家. 定义:ai表示第i个人回家的时间, xij = abs(ai - aj) (i != j). ...
- UVALive 6486 Skyscrapers 简单动态规划
题意: 有N个格子排成一排,在每个格子里填上1到N的数(每个只能填一次),分别代表每个格子的高度.现在给你两个数left和right,分别表示从左往右看,和从右往左看,能看到的格子数.问有多少种情况. ...
- fork函数详解
一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同, ...
- POJ——T 2449 Remmarguts' Date
http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30754 ...
- BitSet的使用
有些程序须要处理二进制有序集,标准库提供了bitset 类型,其实,bitset 是一个二进制容器.容器中每个元素都是一位二进制码,或为 0,或为 1. bitset除了能够訪问指定下标的bit位以外 ...
- 智课雅思词汇---七、cur是什么意思
智课雅思词汇---七.cur是什么意思 一.总结 一句话总结:词根:cur, curs ( cor, cour, cours, coars) = to run 1.cub是什么意思? 词根:cumb, ...
- centos7 安装好python3 yum报错
解决方法: 修改两个地方 vi /usr/bin/yum 将最前面的改为#! /usr/bin/python2 vi /usr/libexec/urlgrabber-ext-down #! /usr/ ...
- JS实现PC端全兼容复制
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...