Created
July 5, 2023 12:55
-
-
Save dkwktm45/36b68617365e581310940e79c8ccd595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.StringTokenizer; | |
public class Boj13305 { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
StringTokenizer st; | |
int n = Integer.parseInt(br.readLine()); | |
int[] lengthArr = new int[n - 1]; | |
ArrayList<Long> cityArr = new ArrayList<>(); | |
st = new StringTokenizer(br.readLine()); | |
for (int i = 0; i < n - 1; i++) lengthArr[i] = Integer.parseInt(st.nextToken()); | |
st = new StringTokenizer(br.readLine()); | |
long price = Integer.parseInt(st.nextToken()); | |
cityArr.add(price); | |
for (int i = 1; i < n; i++) { | |
price = Integer.parseInt(st.nextToken()); | |
if (cityArr.get(i - 1) < price) { | |
cityArr.add(cityArr.get(i - 1)); | |
} else { | |
cityArr.add(price); | |
} | |
} | |
System.out.println(minPrice(cityArr, lengthArr)); | |
} | |
private static long minPrice(ArrayList<Long> cityArr, int[] lengthArr) { | |
long price = 0; | |
for (int i = 0; i < lengthArr.length; i++) { | |
price += cityArr.get(i) * lengthArr[i]; | |
} | |
return price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment