백준 2295 nodejs

윤익·2022년 11월 1일
0

https://www.acmicpc.net/problem/2295

const fs = require('fs')
let U = fs.readFileSync('./dev/stdin').toString().trim().split('\r\n')
// let U = fs.readFileSync('/dev/stdin').toString().trim().split('\n')
const N = +U.shift()
U = U.map(Number).sort((a, b) => b - a) // 내림차순 정렬
const S = new Set()
for (let x = 0; x < N; x++) for (let y = x; y < N; y++) S.add(U[x] + U[y])
// U의 두 수의 합계 Set S 생성
function sol() {
  for (const k of U) for (const z of U) if (S.has(k - z)) return k
} 
// k - z = U[x] + U[y]를 만족하는 가장 큰 k 반환
console.log(sol())
profile
https://nickyoon.tistory.com/ 기술 블로그 이전

0개의 댓글