# 42. 小明的幸运数

42

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
let input = [];
rl.on('line', function(num) {
    input.push(num);
});
rl.on('close', () => {
    let n = parseInt(input[0]);
    let lucky = parseInt(input[1]);
    if (n < 1 || n > 100 || lucky < -100 || luck > 100) {
        console.log('12345');
        return;
    }

    let p = 0;
    let mp = 0;
    let cmds = input[2].split(' ').map(Number);
    for(let i=0; i<n; i++) {
        let cmd = cmds[i];
        if (cmd < -100 || cmd > 100) {
            console.log('12345');
            return;
        }
        if (cmd === lucky) {
            if (cmd > 0) {
                p += cmd + 1;
            } else if (cmd < 0) {
                p += cmd - 1;
            }
        } else {
            p += cmd;
        }
        mp = Math.max(mp, p);
    }
    console.log(mp);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39