1. 程式人生 > >Codeforces 855B Marvolo Gaunt's Ring

Codeforces 855B Marvolo Gaunt's Ring

-i lin cst pri reg [] get max urn

二次聯通門 : Codeforces 855B Marvolo Gaunt‘s Ring

/*
    Codeforces 855B Marvolo Gaunt‘s Ring
    
    SB dp
    然後WA了三發才過
    原因是極大值太小了
    INF = 1e9 = WA
    INF = 1e18 = WA
    INF = 8e18 = AC
*/
#include <cstdio>
#define INF 8e18
#define Max 123123
#define rg register
typedef long long LL; LL f[Max], v[Max];
inline 
void cmax (LL &a, LL b) { if (b > a) a = b; } inline LL max (LL a, LL b) { return a > b ? a : b; } int main (int argc, char *argv[]) { LL N, p, q, r; scanf ("%lld%lld%lld%lld", &N, &p, &q, &r); rg int i, j; f[0] = -INF; LL s = -INF; for (i = 1; i <= N; ++ i) scanf (
"%lld", &v[i]), f[i] = max (f[i - 1], p * v[i]); for (i = 1; i <= N; ++ i) f[i] = max (f[i - 1], f[i] + q * v[i]); for (i = 1; i <= N; ++ i) f[i] = max (f[i - 1], f[i] + r * v[i]), cmax (s, f[i]); printf ("%lld", s); return 0; }

Codeforces 855B Marvolo Gaunt's Ring