Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,28 @@ int main(){
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}

lb = 0;
ub = 0;
for(i = 0; i < n ;i++){
ub = ub + A[i];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初期値が大きすぎて最悪桁あふれします.改善してください.

}
while(ub - lb > 1){
int mid = (lb + ub) / 2;
int real_bags = 0;
for(i = 0; i < n; i++){
if(A[i] % mid == 0){
real_bags = real_bags + A[i] / mid;
}else{
real_bags = real_bags + A[i] / mid + 1;
}
}
if(real_bags <= k){
ub = mid;
}else{
lb = mid;
}
}
printf("%d\n", ub);

return 0;
}
15 changes: 12 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Choose a reason for hiding this comment

The 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;
}
25 changes: 24 additions & 1 deletion src/spear.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

資料のケースでも動いてないかと思います.

if(ub <= A[i]){
ub = A[i] + 1;

Choose a reason for hiding this comment

The 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;
}
36 changes: 35 additions & 1 deletion src/works.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,41 @@ int main(){
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}

lb = 0;
ub = 0;
for(i = 0; i < n; i++){
ub = ub + A[i];
if(lb < A[i]){
lb = A[i];
}
}
lb = lb - 1;
while(ub - lb > 1){
int mid = (lb + ub) / 2;
int completed_work = 0;
for(i = 0; i < k; i++){
int works = 0;
for(int j = completed_work; j < n; j++){
works = works + A[j];
if(works > mid){
completed_work = j;
break;
}
if(j == n - 1){
completed_work = n;
break;
}
}
if(completed_work == n){
ub = mid;
break;
}
}
if(completed_work < n){
lb = mid;
}
}
printf("%d\n", ub);

return 0;
}