codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

855B.md (1709B)


      1 Source: https://codeforces.com/problemset/problem/855/B
      2 
      3 B. Marvolo Gaunt's Ring
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 Value of *x* is calculated as maximum of *p*·*a**i* + *q*·*a**j* + *r*·*a**k* for given *p*, *q*, *r* and array *a*1, *a*2, ... *a**n* such that 1 ≤ *i* ≤ *j* ≤ *k* ≤ *n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
     24 
     25 Input
     26 
     27 First line of input contains 4 integers *n*, *p*, *q*, *r* ( - 109 ≤ *p*, *q*, *r* ≤ 109, 1 ≤ *n* ≤ 105).
     28 
     29 Next line of input contains *n* space separated integers *a*1, *a*2, ... *a**n* ( - 109 ≤ *a**i* ≤ 109).
     30 
     31 Output
     32 
     33 Output a single integer the maximum value of *p*·*a**i* + *q*·*a**j* + *r*·*a**k* that can be obtained provided 1 ≤ *i* ≤ *j* ≤ *k* ≤ *n*.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 5 1 2 3  
     41 1 2 3 4 5
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 30
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 5 1 2 -3  
     54 -1 -2 -3 -4 -5
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 12
     61 ```
     62 
     63 Note
     64 
     65 In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
     66 
     67 In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.