import java.util.*;
public class problem142 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int [] n = new int [size - 1];
int [] m = new int [size];
int count = 0;
for(int i = 0; i < n.length; i++){
n[i] = in.nextInt(); // 거리
}
for(int i = 0; i < m.length; i++){
m[i] = in.nextInt(); // 가격
}
// 주유 최소 비용을 담는다.
int min = m[0];
for(int i = 0; i < n.length; i++){
// 현재 주유 가격 보다, 다음의 주유 가격이 더 쌀 경우 min 갱신
if(m[i] < min){
min = m[i];
}
count += min * n[i];
}
System.out.print(count);
}
}
import java.util.*;
public class problem143 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String st = in.next();
char [] ch = st.toCharArray();
StringBuilder sb = new StringBuilder();
int reverse = 0;
Arrays.sort(ch);
// 역순으로 담아준다.
for(int i = ch.length - 1 ; i >= 0; i--){
reverse += ch[i] - '0';
sb.append(ch[i]);
}
// 0으로 시작하거나, 3의 배수가 아니라면 (30의 배수 = 3의배수)
if(ch[0] != '0' || reverse % 3 != 0){
System.out.print(-1);
}else {
System.out.print(sb.toString());
}
}
}
import java.util.*;
public class problem144 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long size = in.nextLong();
// 우선 순위 큐 : 일반적이 FIFO (선입선출)를 가지면서,
// 우선순위라는 조건을 걸수있다.
PriorityQueue<Long> pq = new PriorityQueue<>();
for(int i = 0; i < size; i++){
long n = in.nextLong();
pq.add(n);
}
// 10 20 40
long sum = 0;
while(pq.size() > 1){
long n = pq.poll(); // 먼저 입력된 값을 꺼낸다.
long m = pq.poll();
sum += n+m;
// 더한 값을 큐에 다시 더해준다.
pq.add(n+m);
}
System.out.print(sum);
}
}
import java.util.Arrays;
import java.util.Scanner;
public class problem145 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = in.nextInt();
}
Arrays.sort(arr);
long sum = 0;
int index = 0;
int [] reverse = new int [arr.length];
// 최대값 저장을 위해 역순
for (int j = arr.length - 1; j >= 0; j--) {
reverse[index] = arr[j];
index++;
}
for(int k = 0; k < size; k++){
if(reverse[k] - k <= 0){
break;
}
sum += reverse[k] - k;
}
System.out.print(sum);
}
}
import java.util.Arrays;
import java.util.Scanner;
public class problem146 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int n = in.nextInt();
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = in.nextInt();
}
Arrays.sort(arr);
int tape = 0;
int match = 0;
int count = 0;
for (int i = 0; i < size; i++) {
match = arr[i];
// 테이프 길이가 2이면, 구멍이 2개 1,2가 입력되어도
// 테이프 1개로 커버가된다.
if (match > tape) {
// 0.5(좌) + 0.5(우)
tape = arr[i] + n - 1;
count++;
}
}
System.out.print(count);
}
}
import java.util.Scanner;
public class problem147 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int count = 0;
while (n != 0) {
// 최소한의 갯수로 할경우 최대값 (5)의 갯수가 최대가되어야된다.
if (n % 5 == 0) {
count += n / 5;
break;
}
// 5로 나눠지지 않을경우 2를 계속 빼준다.
n -= 2;
count++;
}
if (n < 0) {
System.out.print(-1);
} else {
System.out.print(count);
}
}
}
프로그래머스 SQL GROUP BY (SW 마에스트로 2차 테스트 준비)
SELECT FOOD_TYPE, REST_ID, REST_NAME, FAVORITES
FROM REST_INFO
## IN 절에는 WHERE절의 파라미터랑 형식이 같아야된다.
WHERE (FOOD_TYPE, FAVORITES) IN (SELECT FOOD_TYPE, MAX(FAVORITES)
FROM REST_INFO
GROUP BY FOOD_TYPE)
ORDER BY FOOD_TYPE DESC;