-
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int N, M, aMin, bMin, price, answer; static int[] arr, brr; static int getMin(int[] arr) { int min = arr[0]; for (int value : arr) { if (value < min) { min = value; } } return min; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); N = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken()); arr = new int[M]; brr = new int[M]; for (int i = 0; i < M; i++) { StringTokenizer st2 = new StringTokenizer(br.readLine()); arr[i] = Integer.parseInt(st2.nextToken()); brr[i] = Integer.parseInt(st2.nextToken()); } //// aMin = getMin(arr); bMin = getMin(brr); if (aMin < bMin*6) { // 셋트값이 가성비 좋을때 price = aMin; } else { // 그냥 무조건 낱개가 더 쌀때 price = bMin; } // if (N <= 6) { if (aMin < bMin*N) { answer = aMin; } else { answer = bMin*N; } } if (N > 6) { if (price == aMin) { // 패키지 가성비가 좋을때 answer += price * (N / 6); int remain = N % 6; if (aMin >= bMin * remain) { answer += bMin * remain; } else { answer += price; } } else { // min == bMin answer += price * N; } } // System.out.println(answer); } }
- 맞췄다가 넘 지저분해보여서 다른사람 꺼 보고 코드작성하는 법 참조해서 다시 작성함