백준 1246 실버4 좀 도와주세요ㅠㅠ
-
게시물 수정 , 삭제는 로그인 필요
이거 어디가 잘못된건가요? ㅠㅠ 하루종일 생각해봐도 모르겠네요..
문제: https://www.acmicpc.net/problem/1246
제 풀이:
const solution = (N, M, array) => {
array.sort((a,b) => b - a);
let maxPrice = -Infinity;
let price = 0;
for(let i=0; i<M; i++) {
if(N <= 0) break;
else {
const tempMax = array[i] * (i + 1);
if(tempMax >= maxPrice) {
N--;
maxPrice = tempMax;
price = array[i];
}
}
}
return [price, maxPrice].join(' ');
}
const input = [first, ...rest] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');
const [N, M] = first.split(' ').map(Number);
const array = rest.map(Number);
console.log(solution(N, M, array));
이거 어디가 잘못된건가요? ㅠㅠ 하루종일 생각해봐도 모르겠네요..
문제: https://www.acmicpc.net/problem/1246
제 풀이:
const solution = (N, M, array) => {
array.sort((a,b) => b - a);
let maxPrice = -Infinity;
let price = 0;
for(let i=0; i<M; i++) {
if(N <= 0) break;
else {
const tempMax = array[i] * (i + 1);
if(tempMax >= maxPrice) {
N--;
maxPrice = tempMax;
price = array[i];
}
}
}
return [price, maxPrice].join(' ');
}
const input = [first, ...rest] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');
const [N, M] = first.split(' ').map(Number);
const array = rest.map(Number);
console.log(solution(N, M, array));
#백준 1246 #백준 1246 파이썬