[백준] P1049

동민·2021년 3월 11일
0
import java.util.Scanner;

public class P1049 {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int line = sc.nextInt(), n = sc.nextInt(), packageMin = Integer.MAX_VALUE, eaMin = Integer.MAX_VALUE, answer = 0, temp, min = Integer.MAX_VALUE;

		for (int i = 0; i < n; i++) {
			packageMin = Math.min(packageMin, sc.nextInt());
			eaMin = Math.min(eaMin, sc.nextInt());
		}
		
		for(int i = 0; i <= line / 6 + 1; i++) {
			temp = line;
			answer = packageMin * i;
			temp -= 6 * i;
			temp = temp < 0 ? 0 : temp;
			answer += eaMin * temp;
			min = Math.min(answer, min);
		}
		
		System.out.println(min);
		sc.close();
	}
}
profile
BE Developer

0개의 댓글