• codeforce 855B


    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
    ",m3);
    26     return 0;
    27 }
    View Code
  • 相关阅读:
    delphi 字符串查找替换函数 转
    Delphi流的操作
    【BZOJ1316】树上的询问 点分治+set
    【BZOJ2406】矩阵 二分+有上下界的可行流
    【BZOJ1853/2393】[Scoi2010]幸运数字/Cirno的完美算数教室 DFS+容斥
    【BZOJ4999】This Problem Is Too Simple! 离线+树状数组+LCA
    【BZOJ2427】[HAOI2010]软件安装 Tarjan+树形背包
    【BZOJ3217】ALOEXT 替罪羊树+Trie树
    【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
    【BZOJ3435】[Wc2014]紫荆花之恋 替罪点分树+SBT
  • 原文地址:https://www.cnblogs.com/zmin/p/7590688.html
Copyright © 2020-2023  润新知