B. Marvolo Gaunt's Ring
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly x drops of the potion he made.

Value of x is calculated as maximum of p·ai + q·aj + r·ak for given p, q, r and array a1, a2, ... an such that 1 ≤ i ≤ j ≤ k ≤ n. Help Snape find the value of x. Do note that the value of x may be negative.

Input

First line of input contains 4 integers n, p, q, r ( - 109 ≤ p, q, r ≤ 109, 1 ≤ n ≤ 105).

Next line of input contains n space separated integers a1, a2, ... an ( - 109 ≤ ai ≤ 109).

Output

Output a single integer the maximum value of p·ai + q·aj + r·ak that can be obtained provided 1 ≤ i ≤ j ≤ k ≤ n.

Examples
Input
5 1 2 3
1 2 3 4 5
Output
30
Input
5 1 2 -3
-1 -2 -3 -4 -5
Output
12
Note

In the first sample case, we can take i = j = k = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.

In second sample case, selecting i = j = 1 and k = 5 gives the answer 12.

这题题意是给定p,q,r,要求从数组中选择 i,j,k  (i<=j<=k)

使得 p*i + q*j + r*k 最大,就是道暴力模拟水题,我竟然没有想到T T,直接掉了80分。。。

哇,我真的是个智障。

附ac代码:

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <map>
7 #define ll long long
8 using namespace std;
9 const ll inf = -4*1e18-5;
10
11 int main() {
12 int n;
13 scanf("%d",&n);
14 ll p,q,r;
15 scanf("%lld%lld%lld",&p,&q,&r);
16 ll u,m1,m2,m3;
17 // printf("%lld ",inf);
18 m1 = m2 = m3 =inf;
19 while(n--) {
20 scanf("%lld",&u);
21 m1 = max(m1,u*p);
22 m2 = max(m2,u*q + m1);
23 m3 = max(m3,u*r + m2);
24 }
25 printf("%lld\n",m3);
26 return 0;
27 }

最新文章

  1. 【腾讯GAD暑期训练营游戏程序班】游戏中的特效系统作业说明文档
  2. [转] 理解 Thread.Sleep 函数
  3. 配置ActiveX控件在网页中下载安装
  4. CSS-3 Animation 的使用
  5. 【Oracle 数据迁移】环境oracle 11gR2,exp无法导出空表的表结构【转载】
  6. spring2.5
  7. Android:apk文件结构
  8. 观锁与悲观锁(Hibernate)
  9. 基于visual Studio2013解决面试题之0609寻找链表公共节点
  10. ubuntu14操作系统chrome标签和书签乱码解决
  11. 13、Cocos2dx 3.0游戏开发找小三之3.0中的Director :郝萌主,一统江湖
  12. PL SQL Developer报错框乱码
  13. selenium-确定找到的element唯一(三)
  14. SQL HAVING 子句使用
  15. Elasticsearch数据迁移工具elasticdump工具
  16. C++中的局部变量、全局变量、局部静态变量、全局静态变量的区别
  17. uva-310-L--system-暴力枚举
  18. 如何在CentOS 7.2上创建NFS的Share,然后让Client可以访问
  19. Longest Palindromic Substring leetcode java
  20. python接口自动化发送get请求 详解(一)

热门文章

  1. VGA调试心得
  2. 说说C# 8.0 新增功能Index和Range的^0是什么?
  3. Django Full Coverage
  4. Python虚拟环境配置应用
  5. java-数据类型复习
  6. The OAuth 2.0 Authorization Framework OAuth2.0的核心角色code 扫码登录
  7. IntelliJ Idea 解决 Could not autowire. No beans of &#39;xxxx&#39; type found 的错误提示
  8. 《进击吧!Blazor!》第一章 3.页面制作
  9. 我的刷题单(8/37)(dalao珂来享受切题的快感
  10. 【笔记】学习markdown