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 ...
随机推荐
- iOS开发——捕获崩溃信息
可通过注册NSUncaughtExceptionHandler捕获异常信息,将拿到的NSException细节写入Crash日志,精准的定位出错程序位置,有需要的,可直接将crash信息直接上传服务器 ...
- Ubuntu上使用过的命令,Linux常用命令,mount 硬盘挂载, ls 列表list命令,cp 复制copy命令,mkdir 创建文件夹 ,nano 编辑器,cat 文档合并,chmod 文件权限,ssh win10连接ubuntu服务器的步骤
man 帮助 > man ls # ubuntu的帮助 tar.gz 压缩解压 > tar -zcvf yzn.tar.gz /home/yzn # 压缩 > tar -zxvf y ...
- linu基础入门(一)
原创作品,允许转载,转载时请务必声明作者信息和本声明. https://www.cnblogs.com/zhu520/p/10730550.html 本人小白,有错指出.谢谢! 一:根据上一步安装与新 ...
- python3+opencv+tkinter开发简单的人脸识别小程序
学校里有门图像处理的课程最终需要提交一个图像处理系统, 正好之前对于opencv有些了解,就简单的写一个人脸识别小程序吧 效果图如下 笔者IDE使用Pycharm,GUI编程直接使用内置的tkinte ...
- FOJ1205 小鼠迷宫问题 (BFD+递推)
FOJ1205 小鼠迷宫问题 (BFD+递推) 小鼠a与小鼠b身处一个m×n的迷宫中,如图所示.每一个方格表示迷宫中的一个房间.这m×n个房间中有一些房间是封闭的,不允许任何人进入.在迷宫中任何位置均 ...
- ArcGIS api for javascript——动态创建图层列表
描述 本例循环地图服务里的所有图层并增加每个图层到一个带checkbox的列表,checkbox能设置图层的显示或隐藏.动态创建列表的优势是所有的图层都会包含在列表中,即使服务器管理员删除或增加了图层 ...
- POJ 3014:Asteroids(二分匹配,匈牙利算法)
id=3041">Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14399 Acce ...
- Android实战简易教程-第二十六枪(基于ViewPager实现微信页面切换效果)
1.头部布局文件top.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- vue21 slot占位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android-Universal-Image-Loader 学习笔记(五)线程池分析
UniveralImageLoader中的线程池 一般情况网络访问就需要App创建一个线程来执行(不然可能出现很臭的ANR),但是这也导致了当网络访问比较多的情况下,线程的数目可 ...