728x90
https://www.acmicpc.net/problem/13305
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cityCnt = Integer.parseInt(br.readLine().strip());
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
List<Long> roadList = new ArrayList<>();
while (st.hasMoreTokens()) {
roadList.add(Long.parseLong(st.nextToken()));
}
st = new StringTokenizer(br.readLine(), " ");
List<Long> city = new ArrayList<>();
while (st.hasMoreTokens()) {
city.add(Long.parseLong(st.nextToken()));
}
Long result = 0L;
Long pay = city.get(0);
for (int i = 0; i < cityCnt-1; i++) {
result += pay * roadList.get(i);
if (city.get(i+1) < pay)
pay = city.get(i+1);
}
System.out.println(result);
}
}
728x90
'알고리즘 > 백준' 카테고리의 다른 글
[Java] 백준 1931 회의실 배정 - 실버1 (0) | 2023.07.13 |
---|---|
[Java] 백준 16953 A -> B - 실버2 (그리디, bfs) (0) | 2023.07.12 |
[Java] 백준 1213 팰린드롬 만들기 - 실버4 (0) | 2023.07.12 |
[Java] 백준 2217 로프 - 실버4 (0) | 2023.07.12 |
[Java] 백준 2839 설탕 배달 - 실버4 (0) | 2023.07.12 |