-
Notifications
You must be signed in to change notification settings - Fork 163
提出 #154
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
base: main
Are you sure you want to change the base?
提出 #154
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,21 @@ int A[100000]; | |
|
|
||
| int main(){ | ||
| int i, lb, ub; | ||
| scanf("%d%d", &n, &k); | ||
| scanf("%d %d", &n, &k); | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
|
|
||
|
|
||
| lb = 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 初期値が不適切です. |
||
| ub = n; | ||
| while(ub - lb > 1){ | ||
| int mid = (ub + lb) / 2; | ||
| if(A[mid] >= k){ | ||
| ub = mid; | ||
| }else{ | ||
| lb = mid; | ||
| } | ||
| } | ||
| printf("%d\n", ub); | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,30 @@ int main(){ | |
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
|
|
||
| lb = -1; | ||
| ub = 1; | ||
| for(i = 0; i < n; i++){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 資料のケースでも動いてないかと思います. |
||
| if(ub <= A[i]){ | ||
| ub = A[i] + 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 怪しいです. |
||
| } | ||
| } | ||
| while(ub - lb > 1){ | ||
| int mid = (lb + ub) / 2; | ||
| if(mid == 0){ | ||
| lb = mid; | ||
| break; | ||
| } | ||
| int spear_count = 0; | ||
| for(i = 0; i < n; i++){ | ||
| spear_count = spear_count + A[i] / mid; | ||
| } | ||
| if(spear_count >= k){ | ||
| lb = mid; | ||
| }else{ | ||
| ub = mid; | ||
| } | ||
| } | ||
| printf("%d\n", lb); | ||
|
|
||
| return 0; | ||
| } | ||
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.
初期値が大きすぎて最悪桁あふれします.改善してください.