-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
12-mong3125 #41
Merged
Merged
12-mong3125 #41
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package μ΄μ§νμ; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.io.IOException; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ2343_κΈ°νλ μ¨ { | ||
|
||
static int N; | ||
static int M; | ||
static int[] lectures; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
lectures = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
int sum = 0; | ||
int max = 0; | ||
for(int i = 0; i < N; i++) { | ||
lectures[i] = Integer.parseInt(st.nextToken()); | ||
sum += lectures[i]; | ||
max = Math.max(max, lectures[i]); | ||
} | ||
|
||
// λΈλ£¨λ μ΄μ ν¬κΈ°λ maxλΆν° sum μ¬μ΄ μΌκ²μ΄λ€. | ||
int result = minimumBlueray(max, sum); | ||
|
||
System.out.println(result); | ||
} | ||
|
||
public static int minimumBlueray(int start, int end) { | ||
if (start < end) return -1; | ||
|
||
int mid = (start + end) / 2; | ||
|
||
if (can(mid)) { | ||
int more = minimumBlueray(start, mid - 1); | ||
return more != -1 ? more : mid; | ||
} | ||
else return minimumBlueray(mid + 1, end); | ||
} | ||
|
||
public static boolean can(int blueray) { | ||
int count = M; | ||
int i = 0; | ||
int stack = blueray; | ||
while (count > 0) { | ||
while (stack - lectures[i] > 0) { | ||
if (i == N) return true; | ||
stack -= lectures[i]; | ||
i++; | ||
} | ||
|
||
stack = blueray; | ||
count--; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ
can()
ν¨μλ‘mid
μ¬μ΄μ¦λ‘ λ Ήνκ° κ°λ₯νμ§ νλ νλκ±Έλ‘ λ³΄μ λλ€.mid
κ°μ λ΄μstack
μμ κ°μμκ°μ νλμ© λΉΌκ°λ©΄μ λͺ¨λ κ°μκ°M
κ°μ λΈλ£¨λ μ΄μ λ΄κΈΈ μ μλμ§ νλ νλκ²μΌλ‘ μ΄ν΄νλ©΄ λ κΉμ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ€ λ§μ΅λλ€!