Home 백준 기타줄 (1049)
Post
Cancel

백준 기타줄 (1049)

백준 기타줄 (1049)

스크린샷 2022-02-04 오후 4 36 26

  • 우선순위 큐 두개를 만들어 패키지 최소 가격과, 낱개 최소 가격을 구한다.
  • Min(패키지 가격 * (기타줄 개수 / 6) , 단품가격 * 필요한 기타줄 개수)
  • 7개 이상일 경우 패키지 + 단품 섞어서 살 수 있으므로 주의
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.*;  
import java.util.PriorityQueue;  
import java.util.StringTokenizer;  
  
class FastScanner {  
    BufferedReader br;  
    StringTokenizer st;  
  
    public FastScanner() {  
        br = new BufferedReader(new InputStreamReader(System.in));  
    }  
  
    String next() {  
        while (st == null || !st.hasMoreElements()) {  
            try {  
                st = new StringTokenizer(br.readLine());  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return st.nextToken();  
    }  
  
    int nextInt() {  
        return Integer.parseInt(next());  
    }  
  
    long nextLong() {  
        return Long.parseLong(next());  
    }  
}  
  
public class Main {  
    public static void main(String args[]) throws IOException{  
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));  
        FastScanner sc = new FastScanner();  
  
        PriorityQueue<Integer> pack = new PriorityQueue<Integer>();  
        PriorityQueue<Integer> unit = new PriorityQueue<Integer>();  
  
        int N = sc.nextInt();   // 사야하는 기타 줄 수  
	    int M = sc.nextInt();   // 브랜드 수  
  
	    for(int i=0; i<M; i++){  
            pack.add(sc.nextInt());  
            unit.add(sc.nextInt());  
        }  
  
        int ans = 0;  
        int packMin = pack.peek();  
        int unitMin = unit.peek();  
  
        int needPack = N / 6;  
        int needUni = N % 6;  
  
        ans += (packMin < unitMin * 6) ? (packMin * needPack) : (unitMin * 6 * needPack);  
        ans += (packMin > unitMin * needUni) ? (needUni * unitMin) : (packMin);  
  
        bw.write(Integer.toString(ans) + "\n");  
        bw.close();  
    }  
}
This post is licensed under CC BY 4.0 by the author.