|
| 1 | +import java.io.*; |
| 2 | + |
| 3 | +public class YJ_1535 { |
| 4 | + public static void main(String[] args) throws IOException { |
| 5 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 6 | + int N = Integer.parseInt(br.readLine()); |
| 7 | + |
| 8 | + String[] s = br.readLine().split("\\s"); |
| 9 | + String[] h = br.readLine().split("\\s"); |
| 10 | + int[] exhaustion = new int[N+1]; |
| 11 | + int[] happy = new int[N+1]; |
| 12 | + |
| 13 | + for(int i=1; i<N+1; i++){ |
| 14 | + exhaustion[i] = Integer.parseInt(s[i-1]); |
| 15 | + happy[i] = Integer.parseInt(h[i-1]); |
| 16 | + } |
| 17 | + |
| 18 | + final int MAX_STAMINA = 100; |
| 19 | + int[] dp = new int[MAX_STAMINA+1]; //dp[์ฒด๋ ฅ]= ์ต๋ ๊ธฐ์จ |
| 20 | + for(int i = 1; i < N+1; i++){ |
| 21 | + for(int stamina=MAX_STAMINA; stamina > 0; stamina--) { //๋ค์์ ๋ถํฐ ํน์ ์ฒด๋ ฅ์ ๋ํ ๊ธฐ์จ์ ๊ฐฑ์ ํ๋ฉด์ ๋ฐ๋ณต |
| 22 | + int total = stamina-exhaustion[i]; //ํ์ฌ ์ฒด๋ ฅ์์ ์ฒด๋ ฅ์๋ชจ๋ฅผ ๋นผ์ ํ์ฌ ์ํ์์ ๊ฐ๋ฅํ ์ํฉ์ ๊ณ ๋ ค |
| 23 | + if (total > 0) { |
| 24 | + dp[stamina] = Math.max(dp[stamina], dp[total] + happy[i]); //"์ด๋ฏธ ๊ฐฑ์ ๋ ๊ธฐ์จ" vs "ํ์ฌ ์ฒด๋ ฅ์๋ชจ๋ฅผ ํฌํจํ๊ธฐ ์ํด ์ด์ ์ํ์ ๊ธฐ์จ + ํ์ฌ ๊ธฐ์จ"์ ๋น๊ตํ๊ธฐ |
| 25 | + //System.out.printf("dp[%d] = Math.max(dp[%d], dp[%d]+happy[%d])\n", stamina, stamina, total , i); |
| 26 | + //System.out.printf("%d = Math.max(%d, %d)\n\n", dp[stamina], dp[stamina], dp[total] + happy[i]); |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + System.out.println(dp[MAX_STAMINA]); //์ต๋์ฒด๋ ฅ์ธ dp[100]์ ํญ์ ์ต๋๊ธฐ์จ ๊ฐ์ด ๋ณด์ฅ๋๋ค |
| 32 | + } |
| 33 | +} |
0 commit comments