diff --git a/src/apple.c b/src/apple.c deleted file mode 100644 index 766d543..0000000 --- a/src/apple.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -int n; -int k; -int A[100000]; - - -int main(){ - int i, lb, ub; - scanf("%d%d", &n, &k); - for(i = 0; i < n; i++){ - scanf("%d", &A[i]); - } - - - return 0; -} diff --git a/src/array.c b/src/array.c index 13ed925..9a89b69 100644 --- a/src/array.c +++ b/src/array.c @@ -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); + if(A[mid]>=k){ + ub=mid; + } + else { + lb=mid; + } + } + printf("%d\n", ub); return 0; } diff --git a/src/spear.c b/src/spear.c index 766d543..badfdd0 100644 --- a/src/spear.c +++ b/src/spear.c @@ -4,6 +4,14 @@ int n; int k; int A[100000]; +int p(int x){ + int i,sum; + sum=0; + for (i=0;i= k; +} int main(){ int i, lb, ub; @@ -11,7 +19,17 @@ int main(){ for(i = 0; i < n; i++){ scanf("%d", &A[i]); } - - + lb=0; + ub=1000000000; + while(ub-lb>1){ + int mid =(lb +ub/2); + if(p(mid)){ + ub=mid; + } + else { + lb=mid; + } + } + printf("%d\n", ub); return 0; -} +} \ No newline at end of file diff --git a/src/works.c b/src/works.c index 766d543..ca14b02 100644 --- a/src/works.c +++ b/src/works.c @@ -4,6 +4,23 @@ int n; int k; int A[100000]; +int p(int x){ + int i,j,sum; + sum=0; + j=1; + for(i=0;ix)return 0; + if(j+A[i]<=x){ + j+=A[i]; + } + else{ + j++; + sum=A[i]; + } + } + return j<=k; +} + int main(){ int i, lb, ub; @@ -11,7 +28,17 @@ int main(){ for(i = 0; i < n; i++){ scanf("%d", &A[i]); } - - + lb=0; + ub=1000000000; + while(ub-lb>1){ + int mid =(lb +ub/2); + if(p(mid)){ + ub=mid; + } + else { + lb=mid; + } + } + printf("%d\n", ub); return 0; }