【链接】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. 跟我一起了解koa之koa-generator(一)

    cnpm install -g koa-generator koa2 -e koa2-learn cd koa2-learn/ cnpm install 使用如下运行 DEBUG=koa2-learn ...

  2. 使用git命令将本地项目推送到远程仓库

    将本地项目推送到远程仓库 这里先放一张图, 有助于理解git命令 1. 在GitHub上新建一个仓库 注意不要勾选自动生成README.md文件, 否则会产生某些问题, README.md文件到时可以 ...

  3. Yaf--个人封装yaf的框架+swoole+elasticsearch(Window+linux版)

    这是基于c写底层的yaf框架集成PDO+predis+读写分离+composer+全局异常处理+多模块开发+Log日志记录简单容易上手的框架 注意:window版没有swoole和Smarty主要用作 ...

  4. vim中利用swp文件进行恢复

    经常电脑因为没电或者强行关闭vim,会导致原文件没有保存, 这种情况下vim会自动保存一个.swp文件,需要恢复时, 使用vim -r filename 期中-r意思为recovery 恢复之后最好删 ...

  5. 阅读jeecms源码总结

    转载:https://blog.csdn.net/a382064640?t=1   Jeecsm使用框架包括:springMVC,HIbernate(数据持久层框架),Quartz(作业调度框架),a ...

  6. 取消 ios 上下滑动

  7. java求1000以内的水仙花数

    水仙花数是指一个 n 位数 ( n>=3 ),它的每个位上的数字的 n 次幂之和等于它本身.(例如:1^3 + 5^3 + 3^3 = 153) 三位的水仙花数共有4个,分别为:153.370. ...

  8. spring boot 源码解析11-ConfigurationClassPostProcessor类加载解析

    前言 ConfigurationClassPostProcessor实现了BeanDefinitionRegistryPostProcessor接口,该类会在AbstractApplicationCo ...

  9. phonegap geolocation android 问题

    很纠结的 phonegap 使用定位的时候 android 获取地址异常的慢,为什么呢? 经过分析 如果android 只开启gprs 上网功能 可以立即获取到经纬度 如果只开启wifi 根本就获取不 ...

  10. Javascript-简单的倒计时跳转页面

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...