【链接】h在这里写链接


【题意】


给你n个数字;
让你在其中找出三个数字i,j,k(i<=j<=k);
使得p*a[i]+q*a[j]+r*a[k]最大;

【题解】


/*

    有一个要求i<=j<=k;

    也就是说系数之间的下标是有关系的。

    枚举第一个位置的下标i;

        则第二个人j

        i<=j<n

        枚举中间那个人的位置在哪。

    求出前i个位置,第一个人能获得的最大值是多少

    求出后n-i个位置,第三个人能获得的最大值是多少

*/

【错的次数】


1

【反思】


一开始并没有注意到顺序的作用。
hack点是:很多人的初始化不够小.
1 1e9 1e9 1e9
-1e9
这组数据过不了

【代码】

#include <bits/stdc++.h>
#define LL long long
using namespace std; const int N = 1e5; int n;
LL pre[N+10],after[N+10];//前缀最大,后缀最大
LL a[N+10],p,q,r; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d%lld%lld%lld", &n, &p, &q, &r);
for (int i = 1;i <= n;i++)
scanf("%lld",&a[i]);
pre[1] = p*a[1];
for (int i = 2;i <= n;i++) pre[i] = max(pre[i-1],p*a[i]);
after[n] = r*a[n];
for (int i = n-1;i >= 1;i--) after[i] = max(after[i+1],r*a[i]);
LL ans = pre[1]+after[1]+q*a[1];
for (int i = 2;i <= n;i++)
ans = max(ans,pre[i]+after[i]+q*a[i]);
printf("%lld\n",ans);
return 0;
}

【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring的更多相关文章

  1. 【CF Manthan, Codefest 17 A】Tom Riddle's Diary

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] /* Be careful. 二重循环枚举 */ [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/st ...

  2. 【codeforces Manthan, Codefest 17 C】Helga Hufflepuff's Cup

    [链接]h在这里写链接 [题意]     k是最高级别的分数,最高界别的分数最多只能有x个.     1<=k<=m;     和k相邻的点的分数只能小于k;     n个点的树,问你每个 ...

  3. 【ST】【CF855B】 Marvolo Gaunt's Ring

    传送门 Description 给定三个数 \(p~,~q~,~r~\),以及一个数组 \(a\), 找出三个数 \(i~,~j~,~k\) ,其中 \(i~\leq~j~\leq~k\) 最大化 \ ...

  4. Manthan, Codefest 17

    A. Tom Riddle's Diary time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. Codeforces 855B:Marvolo Gaunt's Ring(枚举,前后缀)

    B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaun ...

  6. Codeforces 855B - Marvolo Gaunt's Ring

    855B - Marvolo Gaunt's Ring 思路:①枚举a[j],a[i]和a[k]分别用前缀最小值最大值和后缀最小值和后缀最大值确定. ②dp,dp[i][j]表示到第j为止,前i+1个 ...

  7. Marvolo Gaunt's Ring(巧妙利用前后缀进行模拟)

    Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as h ...

  8. B. Marvolo Gaunt's Ring 前缀后缀

    B. Marvolo Gaunt's Ring 这种一般只有三个的都可以处理前缀和后缀,再枚举中间这个值. 这个和之前写过的C. Four Segments 前缀后缀 处理方式很像. #include ...

  9. 【CF contest/792/problem/E】

    E. Colored Balls time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. centos7.5安装公版mysql5.7.25

    ######### 卸载原来系统安装的包 # yum remove -y java cvs libselinux-devel postgresql mysql ecj jna sinjdoc 依赖包安 ...

  2. jdk不同版本的垃圾收集器

  3. #include <filename.h> 和 #include“filename.h” 有什么区别

    对于#include <filename.h> ,编译器从标准库路径开始搜索filename.h,对于#include “filename.h” ,编译器从用户的工作路径开始搜索filen ...

  4. js匿名函数与闭包作用

    http://www.jb51.net/article/79238.htm 1 闭包允许内层函数引用父函数中的变量,但是该变量是最终值 当mouseover事件调用监听函数时,首先在匿名函数( fun ...

  5. webpack 4.0尝鲜

    发布不久得webpack 4.0据说速度快了68% - 98%,然后还支持没配置文件,所以看起来很牛逼得样子 所以尝试一发 webpack和webpack-cli分离 现在执行webpack命令 必须 ...

  6. volatile和指令重排序

    volatile 的作用 1 精致指令重排序 2 多线程访问同一个变量的时候,每次都是取最新的,而不会使用当前cpu缓存的那一份.

  7. JDBC中DAO+service设计思想

    一.DAO设计思想 a) Data access Object(数据访问对象):前人总结出的一种固定模式的设计思想. 高可读性. 高复用性. 高扩展性. b) JDBC代码实现的增删改查操作是有复用需 ...

  8. TZ_14_Feign的客户端和Feign的负载均衡

    1.作用:Feign可以把Rest的请求进行隐藏,伪装成类似SpringMVC的Controller一样.你不用再自己拼接url,拼接参数等等操作,一切都交给Feign去做. 2.导入起步坐标 < ...

  9. jdbc原始连接

    public class JdbcInstrt { public static void main(String[] args) { Connection conn = null; PreparedS ...

  10. mysql_example

    package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysq ...