-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotel.java
More file actions
56 lines (55 loc) · 1.62 KB
/
Hotel.java
File metadata and controls
56 lines (55 loc) · 1.62 KB
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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* @백준 1106번
* @author MoonDooo
*/
public class Hotel {
public static void main(String[] args) {
try {
new MinCostForAd();
}catch(IOException e) {
e.printStackTrace();
}
}
}
class MinCostForAd{
private int cityNum;
private int targetCustomerNum;
private int[] targetCustomer;
private int result;
public MinCostForAd() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
targetCustomerNum = Integer.parseInt(st.nextToken());
targetCustomer = new int[targetCustomerNum+101];
Arrays.fill(targetCustomer, Integer.MAX_VALUE);
cityNum = Integer.parseInt(st.nextToken());
targetCustomer[0] = 0;
for(int i = 0; i<cityNum; i++) {
st = new StringTokenizer(br.readLine());
int cost = Integer.parseInt(st.nextToken());
int people = Integer.parseInt(st.nextToken());
for(int j = people; j < targetCustomerNum+101; j++ ) {
if(targetCustomer[j-people]!=Integer.MAX_VALUE) {
targetCustomer[j] = Math.min(targetCustomer[j], targetCustomer[j-people]+cost);
}
}
}
result = Integer.MAX_VALUE;
for(int i = targetCustomerNum; i<targetCustomerNum+101; i++) {
result = Math.min(targetCustomer[i], result);
}
bw.write(result+"");
bw.flush();
bw.close();
br.close();
}
}