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
17 changes: 0 additions & 17 deletions src/apple.c

This file was deleted.

15 changes: 12 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ int main(){
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}



lb=-1;
ub=n;
while(ub-lb>1){
int mid =(lb +ub/2);

Choose a reason for hiding this comment

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

正しくないです.

if(A[mid]>=k){
ub=mid;
}
else {
lb=mid;
}
}
printf("%d\n", ub);
return 0;
}
24 changes: 21 additions & 3 deletions src/spear.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@ int n;
int k;
int A[100000];

int p(int x){
int i,sum;
sum=0;
for (i=0;i<n;i++){
sum +=A[i]/x;
}
return sum >= k;
}

int main(){
int i, lb, ub;
scanf("%d%d", &n, &k);
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}


lb=0;
ub=1000000000;

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);

Choose a reason for hiding this comment

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

ここもです.

if(p(mid)){
ub=mid;
}
else {
lb=mid;
}
}
printf("%d\n", ub);
return 0;
}
}
31 changes: 29 additions & 2 deletions src/works.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,41 @@ int n;
int k;
int A[100000];

int p(int x){
int i,j,sum;
sum=0;
j=1;
for(i=0;i<n;i++){
if(A[i]>x)return 0;
if(j+A[i]<=x){
j+=A[i];
}
else{
j++;
sum=A[i];
}
}
return j<=k;
}


int main(){
int i, lb, ub;
scanf("%d%d", &n, &k);
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}


lb=0;
ub=1000000000;
while(ub-lb>1){
int mid =(lb +ub/2);

Choose a reason for hiding this comment

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

ここもです.

if(p(mid)){
ub=mid;
}
else {
lb=mid;
}
}
printf("%d\n", ub);
return 0;
}