Language: C


i=0;
j=0;
scanf("%lld %lld %lld",&n,&m,&k); 

long long int a[n],b[m],sum;
sum=0;
 
 for(l=0;l<n;l++)
 {
 scanf("%lld",&a[l]);
 }

 for(l=0;l<m;l++)
 {
 scanf("%lld",&b[l]);
 }
  
  while(i<n && j<m && sum<k)
 { 
     if(a[i]<b[j] && sum+a[i]<=k){
       ans++;
       sum=sum+a[i];
       i++;
       
       }
  else if(a[i]>b[j] && sum+b[j]<=k){
       ans++;
        sum=sum+b[j];
       j++;
       }
  else if(a[i]==b[j] && sum+a[i]<=k && i<n-1 && j<n-1)
    {
    if(a[i+1]<b[i+1]){
      sum=sum+a[i];
      i++;
      ans++;
     }
    else {
     sum=sum+a[i];
     j++;
     ans++;
     }
    }
  
  else if(a[i]==b[j] && sum+a[i]<=k && i<n-1 && j==m-1)
  {
  sum=sum+a[i];
   i++;
   ans++;
  }
    
   else if(a[i]==b[j] && sum+a[i]<=k && j<m-1 && i==n-1)
  {
  sum=sum+a[j];
   j++;
   ans++;
  } 
  
  else{break;}
  }
  
if(i<n && j<n) printf("%lld",ans);
else if(i<n) {
  while(i<n && sum+a[i]<=k){
  sum=sum+a[i];
  ans++;
  i++;
  }
 printf("%lld",ans);
 }

else {
  while(j<n && sum+b[j]<=k){
  sum=sum+b[j];
  ans++;
  j++;
  }
  printf("%lld",ans);
 }

return 0;
}

Compiler output:
main.c:2:1: warning: data definition has no type or storage class
    2 | i=0;
      | ^
main.c:2:1: error: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
main.c:3:1: warning: data definition has no type or storage class
    3 | j=0;
      | ^
main.c:3:1: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
main.c:4:7: error: expected declaration specifiers or '...' before string constant
    4 | scanf("%lld %lld %lld",&n,&m,&k);
      |       ^~~~~~~~~~~~~~~~
main.c:4:24: error: expected declaration specifiers or '...' before '&' token
    4 | scanf("%lld %lld %lld",&n,&m,&k);
      |                        ^
main.c:4:27: error: expected declaration specifiers or '...' before '&' token
    4 | scanf("%lld %lld %lld",&n,&m,&k);
      |                           ^
main.c:4:30: error: expected declaration specifiers or '...' before '&' token
    4 | scanf("%lld %lld %lld",&n,&m,&k);
      |                              ^
main.c:6:17: error: 'n' undeclared here (not in a function)
    6 | long long int a[n],b[m],sum;
      |                 ^
main.c:6:22: error: 'm' undeclared here (not in a function)
    6 | long long int a[n],b[m],sum;
      |                      ^
main.c:7:1: warning: data definition has no type or storage class
    7 | sum=0;
      | ^~~
main.c:7:1: error: type defaults to 'int' in declaration of 'sum' [-Wimplicit-int]
main.c:7:1: error: conflicting types for 'sum'; have 'int'
main.c:6:25: note: previous declaration of 'sum' with type 'long long int'
    6 | long long int a[n],b[m],sum;
      |                         ^~~
main.c:9:2: error: expected identifier or '(' before 'for'
    9 |  for(l=0;l<n;l++)
      |  ^~~
main.c:9:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
    9 |  for(l=0;l<n;l++)
      |           ^
main.c:9:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
    9 |  for(l=0;l<n;l++)
      |               ^~
main.c:14:2: error: expected identifier or '(' before 'for'
   14 |  for(l=0;l<m;l++)
      |  ^~~
main.c:14:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   14 |  for(l=0;l<m;l++)
      |           ^
main.c:14:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
   14 |  for(l=0;l<m;l++)
      |               ^~
main.c:19:3: error: expected identifier or '(' before 'while'
   19 |   while(i<n && j<m && sum<k)
      |   ^~~~~
main.c:63:1: error: expected identifier or '(' before 'if'
   63 | if(i<n && j<n) printf("%lld",ans);
      | ^~
main.c:64:1: error: expected identifier or '(' before 'else'
   64 | else if(i<n) {
      | ^~~~
main.c:73:1: error: expected identifier or '(' before 'else'
   73 | else {
      | ^~~~
main.c:82:1: error: expected identifier or '(' before 'return'
   82 | return 0;
      | ^~~~~~
main.c:83:1: error: expected identifier or '(' before '}' token
   83 | }
      | ^