-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from AlgoLeadMe/4-wonjunYou
4-wonjunYou
- Loading branch information
Showing
2 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
## ✏️ 기록 | ||
|
||
| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | ||
|:---:|:---------:|:--------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------:| | ||
| 1차시 | 2024.7.17 | 스택 | <a href= "https://school.programmers.co.kr/learn/courses/30/lessons/42584">주식 가격</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/121 | | ||
| 2차시 | 2024.7.20 | 슬라이딩 윈도우 | <a href= "https://www.acmicpc.net/problem/13422">도둑</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/128 | | ||
| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | ||
|:---:|:---------:|:----------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------:| | ||
| 1차시 | 2024.7.17 | 스택 | <a href= "https://school.programmers.co.kr/learn/courses/30/lessons/42584">주식 가격</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/121 | | ||
| 2차시 | 2024.7.20 | 슬라이딩 윈도우 | <a href= "https://www.acmicpc.net/problem/13422">도둑</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/128 | | ||
| 3차시 | 2024.7.24 | 다이나믹 프로그래밍 | <a href= "https://www.acmicpc.net/problem/3687">성냥개비</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/132 | |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
String[] data = reader.readLine().split(" "); | ||
int N = Integer.parseInt(data[0]); | ||
int M = Integer.parseInt(data[1]); | ||
|
||
int[] scores = new int[N + 1]; | ||
|
||
data = reader.readLine().split(" "); | ||
for (int i = 1; i <= N; i++) { | ||
scores[i] = Integer.parseInt(data[i - 1]); | ||
} | ||
|
||
// 세 번째 줄 입력 처리 | ||
data = reader.readLine().split(" "); | ||
int A = Integer.parseInt(data[0]); | ||
int D = Integer.parseInt(data[1]); | ||
|
||
reader.close(); | ||
|
||
int upper = (N + D - 1) / D; // 최대 헌혈 가능 횟수 | ||
|
||
int[][] dp = new int[upper + 1][N + D]; | ||
|
||
for (int i = 1; i <= N; i++) { | ||
for (int j = 0; j <= upper; j++) { | ||
if (j != 0 && dp[j][i - 1] == 0) continue; | ||
|
||
dp[j][i] = Math.max(dp[j][i], dp[j][i - 1] + scores[i]); | ||
|
||
if (j != upper) { | ||
dp[j + 1][i + D - 1] = Math.max(dp[j + 1][i + D - 1], dp[j][i - 1] + A); | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i <= upper; i++) { | ||
int maxScore = 0; | ||
|
||
for (int j = 0; j < dp[i].length; j++) { | ||
maxScore = Math.max(maxScore, dp[i][j]); | ||
} | ||
|
||
if (maxScore >= M) { | ||
System.out.println(i); | ||
return; | ||
} | ||
|
||
} | ||
|
||
System.out.println(-1); | ||
} | ||
|
||
} |