-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP14585.js
39 lines (38 loc) · 1.37 KB
/
P14585.js
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
const readline = require('readline')
const interface = readline.createInterface(process.stdin)
interface.once('line', line => {
const candy_count = Number(line.split(' ')[1])
const baskets = new Set()
interface.on('line', line => {
let [x, y] = line.split(' ').map(Number)
baskets.add(y * 301 + x)
}).on('close', () => {
let max_candy = Array.from({ length: 301 * 301 })
max_candy[0] = 0
for (let x = 1; x < 301; ++x) {
max_candy[x] = max_candy[x - 1]
if (baskets.has(x)) {
max_candy[x] += Math.max(0, candy_count - x)
}
}
for (let y = 1; y < 301; ++y) {
max_candy[y * 301] = max_candy[y * 301 - 301]
if (baskets.has(y * 301)) {
max_candy[y * 301] += Math.max(0, candy_count - y)
}
}
let max = 0
for (let y = 1; y < 301; ++y) {
for (let x = 1; x < 301; ++x) {
max_candy[y * 301 + x] = Math.max(max_candy[y * 301 - 301 + x], max_candy[y * 301 + x - 1])
if (baskets.has(y * 301 + x)) {
max_candy[y * 301 + x] += Math.max(0, candy_count - x - y)
}
if (max_candy[y * 301 + x] > max) {
max = max_candy[y * 301 + x]
}
}
}
console.log(max)
})
})