B. Marvolo Gaunt's Ring 前缀后缀
这种一般只有三个的都可以处理前缀和后缀,再枚举中间这个值。
这个和之前写过的C. Four Segments 前缀后缀 处理方式很像。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <iostream>
#include <string>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn = 1e5 + ;
typedef long long ll;
ll a[maxn], pre[maxn], endss[maxn];
int main()
{
ll n, p, q, r;
cin >> n >> p >> q >> r;
for (int i = ; i <= n + ; i++) endss[i] = pre[i] = -inf64;
for (int i = ; i <= n; i++) scanf("%lld", &a[i]);
for (int i = ; i <= n; i++) {
pre[i] = max(pre[i - ], a[i] * p);
}
for (int i = n; i >= ; i--) {
endss[i] = max(endss[i + ], a[i] * r);
}
ll ans = -inf64;
for (int i = ; i <= n; i++) {
ans = max(ans, pre[i] + endss[i] + q * a[i]);
// printf("i=%d pre[%d]=%lld endss[%d]=%lld ans=%lld\n", i, i, pre[i], i, endss[i], ans);
}
printf("%lld\n", ans);
return ;
}
B. Marvolo Gaunt's Ring 前缀后缀的更多相关文章
- Marvolo Gaunt's Ring(巧妙利用前后缀进行模拟)
Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as h ...
- Codeforces 855B:Marvolo Gaunt's Ring(枚举,前后缀)
B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaun ...
- Codeforces 855B - Marvolo Gaunt's Ring
855B - Marvolo Gaunt's Ring 思路:①枚举a[j],a[i]和a[k]分别用前缀最小值最大值和后缀最小值和后缀最大值确定. ②dp,dp[i][j]表示到第j为止,前i+1个 ...
- 【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring
[链接]h在这里写链接 [题意] 给你n个数字; 让你在其中找出三个数字i,j,k(i<=j<=k); 使得p*a[i]+q*a[j]+r*a[k]最大; [题解] /* 有一个要 ...
- 【ST】【CF855B】 Marvolo Gaunt's Ring
传送门 Description 给定三个数 \(p~,~q~,~r~\),以及一个数组 \(a\), 找出三个数 \(i~,~j~,~k\) ,其中 \(i~\leq~j~\leq~k\) 最大化 \ ...
- CodeForces - 855B ring 前缀和
邓布利多教授正在帮助哈利摧毁魂器.当他怀疑一个魂器出现在那里时,他去了冈特沙克.他看到Marvolo Gaunt的戒指,并将其确定为魂器.虽然他摧毁了它,但仍然受到诅咒的影响.斯内普教授正在帮助邓布利 ...
- POJ 2752 (KMP 所有可能长度的前缀后缀) Seek the Name, Seek the Fame
题意: 求一个字符串的相同前缀后缀的所有可能的长度,这里该字符串其本身也算自己的前缀和后缀. 分析: 我们知道next数组的性质是,该字符之前的字符串的最大相同前缀后缀. 既然知道了最大的,即next ...
- hdoj 2594 Simpsons’ Hidden Talents 【KMP】【求串的最长公共前缀后缀】
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- 1280 前缀后缀集合(map)
1280 前缀后缀集合 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个数组包含N个正整数,其中有些是重复的.一个前缀后缀集是满足 ...
随机推荐
- 一个不错的spring 学习博客
http://www.iteye.com/blogs/subjects/spring-tittle-tattle
- undefined 和 not defined
概念上的解释: undefined是javascript语言中定义的五个原始类中的一个,换句话说,undefined并不是程序报错,而是程序允许的一个值. not defined是javascript ...
- Pytest系列(21)- allure的特性,@allure.description()、@allure.title()的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面介绍了两种allure的 ...
- Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(十)之Inner Classes
The inner class is a valuable feature because it allows you to group classes that logically belong t ...
- DataGridView行号发生变化 使用的事件
DataGridView并没有这么专门为行号发生变化时触发的事件,我们只能用SelectionChanged和CurrentCellChanged做些设置后实现. 1.使用SelectionChang ...
- mysql中show status介绍一
公司产品运用到mysql集群,集群遇到问题时,需要查看集群状态,使用到命令show status,今天趁机将show status中的各个变量的含义研究一下. 状态名 作用域 详细解释 Aborted ...
- 判断一个字符串是否是合法IP地址
# -*- coding: utf-8 -*- """ @File:test06_判断ip地址是否合法.py @E-mail:364942727@qq.com @Time ...
- Linux学习笔记(五)搜索命令
搜索命令 whereis which locate find whereis 英文原意:locate the binary,source,and manual page files for a com ...
- 测评软件Lemon教程
Lemon 信息技术测评软件 目录 下载与安装 编译器配置 添加样例和选手 完成测评 1.下载与安装 万恶的 伟大的百度网盘: 链接: https://pan.baidu.com/s/1BfMhs_z ...
- ado.net 面向对象
面向对象:就是一个大的转换器,建立起一条通道通往数据库然后通过通道将所需(方法)数据从转换器往返于外部界面端 1 首先在项目里创建文件夹: 右击项目———添加个文件夹App_Cod 2 ...