-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1049.java
More file actions
30 lines (27 loc) · 929 Bytes
/
BOJ1049.java
File metadata and controls
30 lines (27 loc) · 929 Bytes
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
package ¹éÁØ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class BOJ1049 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int min = Integer.MAX_VALUE;
int[] one = new int[M];
int[] six = new int[M];
for(int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
six[i] = Integer.parseInt(st.nextToken());
one[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(six);
Arrays.sort(one);
min = Math.min(((N/6)+1)*six[0], N*one[0]);
min = Math.min(min, (N/6)*six[0] + (N%6)*one[0]);
System.out.print(min);
}
}