javascript sort + pre max sum 876ms
\nconst maxTwoEvents = (a) => {\n    let d = [], res = 0, maxPreSum = 0;\n    for (const [start, end, sum] of a) {\n        d.push([start, sum, 1]);\n        d.
```\nconst maxTwoEvents = (a) => {\n    let d = [], res = 0, maxPreSum = 0;\n    for (const [start, end, sum] of a) {\n        d.push([start, sum, 1]);\n        d.push([end, sum, -1])\n    }\n    d.sort((x, y) => {\n        if (x[0] != y[0]) return x[0] - y[0];\n        return y[2] - x[2];\n    });\n    for (const [, sum, flag] of d) {\n        if (flag == -1) {\n            maxPreSum = Math.max(maxPreSum, sum);\n        } else {\n            res = Math.max(res, maxPreSum + sum);\n        }\n    }\n    return res;\n};\n```
['Sorting', 'JavaScript']