Language: C

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
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;
        }
    }
    return c;
}
 
main()
{
    scanf("%d%d",&n,&k);
    for(;i<n;scanf("%d",w+i++));
    while(l<r)
    {
        m=(l+r)/2;
        if(f(m)>k)l=m+1;
        else r=m;
    }
    for(m--;;m++)
    {
        if(f(m)<=k)break;
    }
    printf("%d\n",m);
    return 0;
}
 

Compiler output:
main.c:1:1: error: expected identifier or '(' before numeric constant
    1 | 14
      | ^~
main.c:27:1: error: return type defaults to 'int' [-Wimplicit-int]
   27 | f(p)
      | ^
main.c: In function 'f':
main.c:27:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:29:5: error: 'c' undeclared (first use in this function)
   29 |     c=1;g=0;
      |     ^
main.c:29:5: note: each undeclared identifier is reported only once for each function it appears in
main.c:29:9: error: 'g' undeclared (first use in this function)
   29 |     c=1;g=0;
      |         ^
main.c:30:9: error: 'i' undeclared (first use in this function)
   30 |     for(i=0;i<n;)
      |         ^
main.c:30:15: error: 'n' undeclared (first use in this function)
   30 |     for(i=0;i<n;)
      |               ^
main.c:32:14: error: 'w' undeclared (first use in this function)
   32 |         if(g+w[i]<=p)
      |              ^
main.c:39:18: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
   39 |             else exit(k+1);
      |                  ^~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
  +++ |+#include <stdlib.h>
    1 | 14
main.c:39:18: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   39 |             else exit(k+1);
      |                  ^~~~
main.c:39:18: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:39:23: error: 'k' undeclared (first use in this function)
   39 |             else exit(k+1);
      |                       ^
main.c: At top level:
main.c:46:1: error: return type defaults to 'int' [-Wimplicit-int]
   46 | main()
      | ^~~~
main.c: In function 'main':
main.c:48:5: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   48 |     scanf("%d%d",&n,&k);
      |     ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | 14
main.c:48:5: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   48 |     scanf("%d%d",&n,&k);
      |     ^~~~~
main.c:48:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:48:19: error: 'n' undeclared (first use in this function)
   48 |     scanf("%d%d",&n,&k);
      |                   ^
main.c:48:22: error: 'k' undeclared (first use in this function)
   48 |     scanf("%d%d",&n,&k);
      |                      ^
main.c:49:10: error: 'i' undeclared (first use in this function)
   49 |     for(;i<n;scanf("%d",w+i++));
      |          ^
main.c:49:25: error: 'w' undeclared (first use in this function)
   49 |     for(;i<n;scanf("%d",w+i++));
      |                         ^
main.c:50:11: error: 'l' undeclared (first use in this function)
   50 |     while(l<r)
      |           ^
main.c:50:13: error: 'r' undeclared (first use in this function)
   50 |     while(l<r)
      |             ^
main.c:52:9: error: 'm' undeclared (first use in this function)
   52 |         m=(l+r)/2;
      |         ^
main.c:60:5: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   60 |     printf("%d\n",m);
      |     ^~~~~~
main.c:60:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:60:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:60:5: note: include '<stdio.h>' or provide a declaration of 'printf'