diff --git a/HYUNSOO/BOJ/BOJ_13305.java b/HYUNSOO/BOJ/BOJ_13305.java new file mode 100644 index 0000000..3581e90 --- /dev/null +++ b/HYUNSOO/BOJ/BOJ_13305.java @@ -0,0 +1,52 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +class Main { + public static void main(String[] args) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + + int cityNumber = Integer.parseInt(bufferedReader.readLine()); + + int[] nextDistance = new int[cityNumber]; + int[] oilCost = new int[cityNumber]; + + StringTokenizer tokenizer = new StringTokenizer(bufferedReader.readLine()); + for (int i = 0; i < cityNumber-1; i++) { + nextDistance[i] = Integer.parseInt(tokenizer.nextToken()); + } + + tokenizer = new StringTokenizer(bufferedReader.readLine()); + for (int i = 0; i < cityNumber; i++) { + oilCost[i] = Integer.parseInt(tokenizer.nextToken()); + } + + long totalCost = getTotalCost(cityNumber, oilCost, nextDistance); + + System.out.println(totalCost); + } + + private static long getTotalCost(int cityNumber, int[] oilCost, int[] nextDistance) { + long totalCost = 0; + for (int i = 0; i < cityNumber; i++) { + int cOilCost = oilCost[i]; + int nextCity = i+1; + + for (; nextCity < cityNumber; nextCity++) { + if (cOilCost > oilCost[nextCity]) { + break; + } + } + + int cNextDistance = 0; + for (int j = i; j < nextCity; j++) { + cNextDistance += nextDistance[j]; + } + + totalCost += ((long) cOilCost * cNextDistance); + i = nextCity - 1; + } + return totalCost; + } +} diff --git a/HYUNSOO/BOJ/BOJ_1541.java b/HYUNSOO/BOJ/BOJ_1541.java new file mode 100644 index 0000000..8e891b4 --- /dev/null +++ b/HYUNSOO/BOJ/BOJ_1541.java @@ -0,0 +1,49 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +class Main { + public static void main(String[] args) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + String str = bufferedReader.readLine(); + + List numbers = new ArrayList<>(); + List sign = new ArrayList<>(); + + StringBuilder number = new StringBuilder(); + for (char c : str.toCharArray()) { + if (c == '-' || c == '+') { + numbers.add(Integer.parseInt(number.toString())); + sign.add(c); + + number = new StringBuilder(); + continue; + } + number.append(c); + } + numbers.add(Integer.parseInt(number.toString())); + + int result = numbers.get(0); + int sum = 0; + for (int i = 1; i < numbers.size(); i++) { + if (sign.get(i-1) == '-') { + result -= sum; + sum = 0; + sum += numbers.get(i); + + } else if (sign.get(i-1) == '+') { + if (sum == 0) { + result += numbers.get(i); + } else { + sum += numbers.get(i); + + } + } + } + result -= sum; + + System.out.println(result); + } +}