티스토리 뷰
https://www.acmicpc.net/problem/16937
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split('\n').map(v=>v.split(' ').map(Number).sort((a,b)=>b-a))
const [H,W] = input[0];
const [N] = input[1]
const stickers = input.slice(2).sort((a,b)=>b[0]*b[1]-a[0]*a[0])
let answer = 0;
for(let i = 0; i<stickers.length-1;i++){
for(let j = i+1; j<stickers.length; j++){
if(check(stickers[i],stickers[j])){
const S = stickers[i][0]*stickers[i][1] + stickers[j][0]*stickers[j][1]
if(answer<S) answer = S
}
}
}
console.log(answer)
function check(arr1,arr2){
const [ax,ay] = arr1; //큰거 가로
const [cx,cy] = arr2; // 작은 거 가로
const [by,bx] = arr1; // 큰거 세로
const [dy,dx] = arr2; // 작은 거 세로
//가로로 붙이기
if(ax + cx <= H && Math.max(ay,cy) <= W){
return true;
}
if(ax + dx <= H && Math.max(ay,dy) <= W){
return true;
}
if(bx + cx <= H && Math.max(by,cy) <= W){
return true;
}
if(bx + dx <= H && Math.max(by,dy) <= W){
return true;
}
// 세로로 붙이기
if(ax + cx <= W && Math.max(ay,cy) <= H){
return true;
}
if(ax + dx <= W && Math.max(ay,dy) <= H){
return true;
}
if(bx + cx <= W && Math.max(by,cy) <= H){
return true;
}
if(bx + dx <= W && Math.max(by,dy) <= H){
return true;
}
return false;
}
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js)백준 16943번: 숫자 재배치 (0) | 2022.01.11 |
---|---|
Node.js)백준 2210번: 숫자판 점프 (0) | 2022.01.10 |
Node.js)백준 16922번: 로마 숫자 만들기 (0) | 2022.01.08 |
Node.js)백준 2422번: 한윤정이 이탈리아에 가서 아이스크림을 사먹는데 (0) | 2022.01.08 |
Node.js)백준 16917번: 양념 반 후라이드 반 (0) | 2022.01.08 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 면접비
- 개발자면접
- 동적프로그래밍
- 은둔청년체험
- 면접질문
- node.js
- 투포인터 연습
- 다이나믹프로그래밍
- create databases;
- BFS
- 서버개발
- 투포인터
- create db
- 다이나밍프로그래밍
- 롱베케이션
- 그래프
- 로드나인
- MySQL
- MOD
- 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 |
글 보관함