Language: C

w[100000],c,n,k,g,i,l,m,r=1e9;
f(p)
{
    c=1;g=0;
    for(i=0;i<n;)
    {
        if(g+w[i]<=p)
        {
            g+=w[i++];
        }
        else
        {
            if(g>0)c++;
            else exit(k+1); 
            g=0;
        }
    }
    exit(c);
}

main()
{
    scanf("%d%d",&n,&k);
    for(;i<n;scanf("%d",w+i++));
    while(l<r)
    {
        m=(l+r)/2;f(m)>k?l=m+1:r=m;
    }
    for(m--;;m++)
    {
        if(f(m)<=k)break;
    }
    printf("%d\n",m);
    exit(0);
}

Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'w' [-Wimplicit-int]
main.c:1:11: error: type defaults to 'int' in declaration of 'c' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |           ^
main.c:1:13: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |             ^
main.c:1:15: error: type defaults to 'int' in declaration of 'k' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |               ^
main.c:1:17: error: type defaults to 'int' in declaration of 'g' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |                 ^
main.c:1:19: error: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |                   ^
main.c:1:21: error: type defaults to 'int' in declaration of 'l' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |                     ^
main.c:1:23: error: type defaults to 'int' in declaration of 'm' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |                       ^
main.c:1:25: error: type defaults to 'int' in declaration of 'r' [-Wimplicit-int]
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
      |                         ^
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
    2 | f(p)
      | ^
main.c: In function 'f':
main.c:2:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:14:18: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
   14 |             else exit(k+1);
      |                  ^~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
  +++ |+#include <stdlib.h>
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
main.c:14:18: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   14 |             else exit(k+1);
      |                  ^~~~
main.c:14:18: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:18:5: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   18 |     exit(c);
      |     ^~~~
main.c:18:5: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c: At top level:
main.c:21:1: error: return type defaults to 'int' [-Wimplicit-int]
   21 | main()
      | ^~~~
main.c: In function 'main':
main.c:23:5: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   23 |     scanf("%d%d",&n,&k);
      |     ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | w[100000],c,n,k,g,i,l,m,r=1e9;
main.c:23:5: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   23 |     scanf("%d%d",&n,&k);
      |     ^~~~~
main.c:23:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:27:33: error: lvalue required as left operand of assignment
   27 |         m=(l+r)/2;f(m)>k?l=m+1:r=m;
      |                                 ^
main.c:33:5: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   33 |     printf("%d\n",m);
      |     ^~~~~~
main.c:33:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:33:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:33:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:34:5: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   34 |     exit(0);
      |     ^~~~
main.c:34:5: note: include '<stdlib.h>' or provide a declaration of 'exit'