티스토리 뷰
https://www.acmicpc.net/problem/3273
3273번: 두 수의 합
n개의 서로 다른 양의 정수 a1, a2, ..., an으로 이루어진 수열이 있다. ai의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, ai + aj = x (1 ≤ i < j ≤ n)을 만족하는
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n");
const N = +input.shift()
const target = +input.pop();
const nums = input[0].split(' ').map((v, i) => +v).sort((a, b) => a - b)
const kill = nums.length;
let start = 0;
let end = kill - 1;
let answer = 0;
while (start != end) {
if (nums[start] + nums[end] == target) {
answer++;
start++;
} else if (nums[start] + nums[end] > target) {
end--;
} else {
start++;
}
}
console.log(answer)
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 1806번: 부분합 (0) | 2021.09.23 |
---|---|
Node.js) 백준 2470번: 두 용액 (0) | 2021.09.23 |
Node.js)백준 1158번: 요세푸스 문제 (0) | 2021.09.23 |
Node.js) 백준 15829번: Hashing (0) | 2021.09.23 |
Node.js) 백준 9020번: 골드바흐의 추측 (0) | 2021.09.21 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 로드나인
- BFS
- 면접질문
- 그래프
- 최소공통조상
- 개발자면접
- DB 생성
- 동적프로그래밍
- 은둔청년체험
- create databases;
- node.js
- MySQL
- MOD
- 서버점검
- 투포인터
- 롱베케이션
- 서버개발
- 투포인터 연습
- 면접비
- 다이나밍프로그래밍
- create db
- 다이나믹프로그래밍
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함