criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,K,L,tmp;
  L=0;
  cin >> N >> K;
  int l[N];
  for(int i=0;i<=N;i++){
  cin >> N[0];
  }

  for(i=0; i<N; ++i) {
    for (j=i+1; j<N; ++j) {
      if (l[i] < l[j]) {
        tmp =  l[i];
        l[i] = l[j];
        l[j] = tmp;
      }
    }
  }

  for(int i=0;i<K;i++){
  L=L+N[i];
  }

  cout << L << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:11: error: invalid types 'int[int]' for array subscript
   10 |   cin >> N[0];
      |           ^
a.cc:13:7: error: 'i' was not declared in this scope
   13 |   for(i=0; i<N; ++i) {
      |       ^
a.cc:14:10: error: 'j' was not declared in this scope
   14 |     for (j=i+1; j<N; ++j) {
      |          ^
a.cc:24:8: error: invalid types 'int[int]' for array subscript
   24 |   L=L+N[i];
      |        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main{
  int N,K,L,tmp;
  L=0;
  cin >> N >> K;
  int l[N];
  for(int i=0;i<=N;i++){
  cin >> N[0];
  }

  for(i=0; i<N; ++i) {
    for (j=i+1; j<N; ++j) {
      if (l[i] < l[j]) {
        tmp =  l[i];
        l[i] = l[j];
        l[j] = tmp;
      }
    }
  }

  for(int i=0;i<K;i++){
  L=L+N[i];
  }

  cout << L << endl;

  return 0;
}

Compiler output:
a.cc:4:5: error: cannot declare '::main' to be a global variable
    4 | int main{
      |     ^~~~
a.cc:5:3: error: expected primary-expression before 'int'
    5 |   int N,K,L,tmp;
      |   ^~~
a.cc:5:3: error: expected '}' before 'int'
a.cc:4:9: note: to match this '{'
    4 | int main{
      |         ^
a.cc:6:3: error: 'L' does not name a type
    6 |   L=0;
      |   ^
a.cc:7:3: error: 'cin' does not name a type
    7 |   cin >> N >> K;
      |   ^~~
a.cc:8:9: error: 'N' was not declared in this scope
    8 |   int l[N];
      |         ^
a.cc:9:3: error: expected unqualified-id before 'for'
    9 |   for(int i=0;i<=N;i++){
      |   ^~~
a.cc:9:15: error: 'i' does not name a type
    9 |   for(int i=0;i<=N;i++){
      |               ^
a.cc:9:20: error: 'i' does not name a type
    9 |   for(int i=0;i<=N;i++){
      |                    ^
a.cc:13:3: error: expected unqualified-id before 'for'
   13 |   for(i=0; i<N; ++i) {
      |   ^~~
a.cc:13:12: error: 'i' does not name a type
   13 |   for(i=0; i<N; ++i) {
      |            ^
a.cc:13:17: error: expected unqualified-id before '++' token
   13 |   for(i=0; i<N; ++i) {
      |                 ^~
a.cc:23:3: error: expected unqualified-id before 'for'
   23 |   for(int i=0;i<K;i++){
      |   ^~~
a.cc:23:15: error: 'i' does not name a type
   23 |   for(int i=0;i<K;i++){
      |               ^
a.cc:23:19: error: 'i' does not name a type
   23 |   for(int i=0;i<K;i++){
      |                   ^
a.cc:27:3: error: 'cout' does not name a type
   27 |   cout << L << endl;
      |   ^~~~
a.cc:29:3: error: expected unqualified-id before 'return'
   29 |   return 0;
      |   ^~~~~~
a.cc:30:1: error: expected declaration before '}' token
   30 | }
      | ^
Language: C

#include <iostream>

using namespace std;

int main(){

  int k,i,j,n,l[100];

    cin >> n >> k;
    for(i=0;i<n;i++)cin >> l[i];
    for(i=0;i<n;i++){
        for(j=0;j<n-i;j++){
            if(l[j]<l[j+1]) swap(l[j],l[j+1]);
        }
    }

    //for(int i=0;i<n;i++)cout << l[i] << endl;

    int sum=0;
   // cout << sum << endl;
    for(i=0;i<k;i++)sum+=l[i];

    cout << sum << endl;

return 0;
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int N,K;
cin>>N>>K;
vector<int> Stick(N);
for(int i = 0; i < N; i++)
{
cin>>Stick[i];
}
sort(Stick.rbegin(),Stick.rend());
long long ans = 0;
for(inti i = 0; i < K; i++)
{
ans+=Stick[i];
}
cout<<ans;
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: 'inti' was not declared in this scope; did you mean 'int'?
   16 | for(inti i = 0; i < K; i++)
      |     ^~~~
      |     int
a.cc:16:17: error: 'i' was not declared in this scope
   16 | for(inti i = 0; i < K; i++)
      |                 ^
Language: Java

import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] lengths = new int[n];
		
		for (int i = 0; i < n; i++) {
			lengths[i] = sc.nextInt();
		}
		
		sc.close();
		
		// now we need a way of sorting through all of the sticks
		int ans = 0;
		
		for (int i = 0; i < k; i++) {
			int temp = 0;
			for (int j = 0; j < n; j++) {
				if (lengths[j] >= lengths[temp]) {
					temp = j;
					// we also need a way of removing the maximum here
				}
			}
			ans += lengths[temp];
			lengths[temp] = 0;
		}
		
		System.out.println(ans);
	}

}


Compiler output:
Main.java:3: error: class B is public, should be declared in a file named B.java
public class B {
       ^
1 error
Language: C++


#include <iostream>
#include <vector>

#define loop(i, num) for (int i = 0; i < num; i++)

using namespace std;

int main() {
    
    int a, b, ans = 0;
    
    cin >> a >> b;
    
    vector<int> n(a);
    
    loop (i, a)  cin >> n[i];
    
    sort(n.begin(), n.end());
    
    loop (i, b)  ans += n[a - i - 1];
    
    cout << ans << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   19 |     sort(n.begin(), n.end());
      |     ^~~~
      |     short
Language: C

#include <stdio.h>
int main(void)
{
    int n,k,l,i,j,tot[5],sum=0,x;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&l);
        tot[i]=l;
    }
    for(i=0;i<n-1;i++)
        for(j=n-1;j>=i;j--)
            if(tot[i]>tot[i-1])
            {
                x=tot[j];
                tot[j]=tot[j-1];
                tot[j-1]=x;
            }
    for(i=0;i<k;i++)
        sum+=tot[i];
    printf("\n%d",sum);
    return 0;


Compiler output:
main.c: In function 'main':
main.c:22:5: error: expected declaration or statement at end of input
   22 |     return 0;
      |     ^~~~~~
Language: C

#include<bits/stdc++.h>
using namespace std;
int ara[1000];
int main()
{
    int i,j,k,l,n,t,df,v;
    while(scanf("%d %d",&n,&k)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&ara[i]);
        }
        sort(ara,ara+n);
        int sum=0;
        for(i=n;i>n-k;i--)
        {
            sum+=ara[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}



Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,k;
  int ans = 0;

  cin >> n >> k;
  vector<int> l(n);
  
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }
  
  sort(l.begin(),l.end(),greater<int>();
  
  for(int j = 0; j < k; j++){
    ans += l[j];
  }
  cout << ans << endl;
  
  return 0;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:15:40: error: expected ')' before ';' token
   15 |   sort(l.begin(),l.end(),greater<int>();
      |       ~                                ^
      |                                        )
Language: C++

#include<iostream>
#include<vector>
using namespace std;

int main() {
    int N,K,l;

    cin >> N >> K;
    int ls[N];
    for(int i=0; i<N; ++i) {
        cin >> ls[i];
    }
    sort(ls, ls+N);

    int sum_num = 0;
    for(int i=N-1; i > N-K-1; --i) {
        //cout << ls[i] << " ";
        sum_num += ls[i];
    }
    cout << sum_num << endl;
    //cout << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |     sort(ls, ls+N);
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[55]
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int sum=0;
    sort(arr,arr+n);
    for(int i=0;i<k;i++){
        sum+=arr[i];
    }
    cout<<sum;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: expected initializer before 'for'
   13 |     for(int i=0;i<n;i++){
      |     ^~~
a.cc:13:17: error: 'i' was not declared in this scope
   13 |     for(int i=0;i<n;i++){
      |                 ^
a.cc:17:10: error: 'arr' was not declared in this scope
   17 |     sort(arr,arr+n);
      |          ^~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[55]
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int sum=0;
    sort(arr,arr+n)
    for(int i=0;i<k;i++){
        sum+=arr[i];
    }
    cout<<sum;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: expected initializer before 'for'
   13 |     for(int i=0;i<n;i++){
      |     ^~~
a.cc:13:17: error: 'i' was not declared in this scope
   13 |     for(int i=0;i<n;i++){
      |                 ^
a.cc:17:10: error: 'arr' was not declared in this scope
   17 |     sort(arr,arr+n)
      |          ^~~
Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;
typedef pair<int, pair<int, int>> Trio;
typedef pair<int, int> Pair;
 
int main(void) {
	int n,k,ma=0
	cin >>n>>k;
	vector<int> l(n);
	for(int i=0;i<n;i++){
	cin >>l[i];
	}
	sort(l.begin(),l.end(),greater<int>());
	for(int i=0;i<k;i++){
	ma+=l[i];
	}
	cout <<ma<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:9: error: expected ',' or ';' before 'cin'
   21 |         cin >>n>>k;
      |         ^~~
Language: C++

#include<iostream>
#include<algorithm>
using nemspace std;
int main(){
 int n,k;cin >> n >> k;
 int a[100000];
 for(int i=0; i<n; i++)cin >> a[i];
 sort(a,a+n);
 itn ans=0;
 for(int i=0; i<k; i++)ans+=a[i];
 cout << ans << endl;
 return 0;
}

Compiler output:
a.cc:3:7: error: expected nested-name-specifier before 'nemspace'
    3 | using nemspace std;
      |       ^~~~~~~~
a.cc: In function 'int main()':
a.cc:5:10: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    5 |  int n,k;cin >> n >> k;
      |          ^~~
      |          std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:8:2: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
    8 |  sort(a,a+n);
      |  ^~~~
      |  std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:2:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:9:2: error: 'itn' was not declared in this scope; did you mean 'int'?
    9 |  itn ans=0;
      |  ^~~
      |  int
a.cc:10:24: error: 'ans' was not declared in this scope; did you mean 'abs'?
   10 |  for(int i=0; i<k; i++)ans+=a[i];
      |                        ^~~
      |                        abs
a.cc:11:2: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   11 |  cout << ans << endl;
      |  ^~~~
      |  std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:11:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
   11 |  cout << ans << endl;
      |          ^~~
      |          abs
a.cc:11:17: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   11 |  cout << ans << endl;
      |                 ^~~~
      |                 std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int sum = 0;
    for(int i=0; i<k; i++) sum += a[i];
    cout << sum << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:5: error: 'vector' was not declared in this scope
   14 |     vector<int> a(n);
      |     ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | 
a.cc:14:12: error: expected primary-expression before 'int'
   14 |     vector<int> a(n);
      |            ^~~
a.cc:15:35: error: 'a' was not declared in this scope
   15 |     for(int i=0; i<n; i++) cin >> a[i];
      |                                   ^
a.cc:17:10: error: 'a' was not declared in this scope
   17 |     sort(a.begin(), a.end(), greater<int>());
      |          ^
Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    sort(a.begin(), a.end());

    int sum = 0;
    for(int i=k; i>0; i--) sum += a[i];
    cout << sum << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:5: error: 'vector' was not declared in this scope
   14 |     vector<int> a(n);
      |     ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | 
a.cc:14:12: error: expected primary-expression before 'int'
   14 |     vector<int> a(n);
      |            ^~~
a.cc:15:35: error: 'a' was not declared in this scope
   15 |     for(int i=0; i<n; i++) cin >> a[i];
      |                                   ^
a.cc:17:10: error: 'a' was not declared in this scope
   17 |     sort(a.begin(), a.end());
      |          ^
Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    sort(a.begin(), a.end());

    int sum = 0;
    for(int i=k; i>0; i--) sum += a[i];
    cout << sum << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:5: error: 'vector' was not declared in this scope
   14 |     vector<int> a(n);
      |     ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | 
a.cc:14:12: error: expected primary-expression before 'int'
   14 |     vector<int> a(n);
      |            ^~~
a.cc:15:35: error: 'a' was not declared in this scope
   15 |     for(int i=0; i<n; i++) cin >> a[i];
      |                                   ^
a.cc:17:10: error: 'a' was not declared in this scope
   17 |     sort(a.begin(), a.end());
      |          ^
Language: C++


#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n,k,ans=0;
    cin >> n >> k;
    vector<int> l(n,0);
    for(int i = 0;i < n;i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end(), greater<int>());
    for(int i = 0;i < k;i++){
        ans += l[i];
    }
    cout << ans << endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |     sort(l.begin(), l.end(), greater<int>());
      |     ^~~~
      |     short
Language: C

    #include<stdio.h>
     
    int main(){
      int N, K, i, j, t, sum;
      int l[51];
      
      scanf("%d %d",&N,&K);
     
      for(i = 0; i < N; i++){
        scanf("%d", &l[i]);
      }
     
      for(i = 0; i < K; i++){
        for(j = 0; j < N; j++){
          if(l[t] < l[j]){
    	
    	temp = j;
          
          }
        }
        
        sum += l[t];
        l[t] = 0;
      
      }
      
      printf("%d",sum);
      return 0;
    }

Compiler output:
main.c: In function 'main':
main.c:17:9: error: 'temp' undeclared (first use in this function)
   17 |         temp = j;
      |         ^~~~
main.c:17:9: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char const *argv[])
{
	int N, K;
	cin >> N >> K;
	vector<int> nums(N);
	for(int i = 0; i < N; i++){
		cin >> nums[i];
	}
	
	sort(nums.begin() , nums.end());

	int res = 0;
	for(int i = N - K; i < N; i++){
		res += nums[i];
	}

	cout << res << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:14:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |         sort(nums.begin() , nums.end());
      |         ^~~~
      |         short
Language: C++

#include <iostream>
using namespace std;
typedef long long ll;
int n, k;
int arr[51];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i =0 ; i < n; i ++){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int ret =0 ;
    for(int i = n - 1; i >= 0; i --){
        if(k == 0)break;
        k --;
        ret += arr[i];
    }
    cout << ret << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:12:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   12 |     sort(arr, arr + n);
      |     ^~~~
      |     short
Language: C

#include<iostream>
using namespace std;

void insort(int n, int a[])
{
        int max;
        for(int i = 0; i < n - 1; i++) {
                max = i;
                for(int j = i; j < n; j++)
                        if(a[j] > a[max])
                                max = j;
                swap(a[i], a[max]);
        }
}

int main(){
    int N,K;
    int l[50];
    cin >> N >> K;
    for(int i=0; i < N;i++){
         cin >> l[i];
    }
    insort(N,l);
        int ans = 0;
        for(int i = 0; i<K;i++){
                ans = ans + l[i];
        }
        cout << ans << endl;

}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
int selection(int A[],int n)
{
	for(int i = 0;i<n;i++)
	{
		int minv = i;
		for(int j = i;j<n;j++)
		{
			if(A[j]<A[minj])
			{
				minj = j;
			}
		}
		int tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
	}
}
int main()
{
	int A[50];
	int n;
	int k;
	std::cin >> n;
	std::cin >> k;
	for(int i = 0;i<n;i++)
	{
		std::cin >> A[i];
	}
	selection(A,n);
	int ret= 0;
	for(int i = 0;i<k;i++)
	{
		ret += A[n-(k+1)];
	} 
	std::cout << ret << std::endl;
	return 0;
}

Compiler output:
a.cc: In function 'int selection(int*, int)':
a.cc:9:35: error: 'minj' was not declared in this scope; did you mean 'minv'?
    9 |                         if(A[j]<A[minj])
      |                                   ^~~~
      |                                   minv
a.cc:15:26: error: 'minj' was not declared in this scope; did you mean 'minv'?
   15 |                 A[i] = A[minj];
      |                          ^~~~
      |                          minv
a.cc:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
   18 | }
      | ^
Language: Java

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
        Integer[] l = new Integer[n];
        for (int i=0; i < n; i++) {
        	l[i] = scan.nextInt();
        }
        Arrays.sort(l,Collections.reverseOrder());
        for (int j = 0; j < k; j++) {
        	int sum += l[j];
        }
        System.out.println(sum);
    }
}

Compiler output:
Main.java:15: error: ';' expected
        	int sum += l[j];
        	       ^
Main.java:15: error: not a statement
        	int sum += l[j];
        	            ^
2 errors
Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int a,b;
    cin >> a >> b ;
    int c[a] = {0};
    for(int i = 0;i < a;i++){
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    int sum = 0;
    for(int i=a-1;i>=a-b;i--){
        sum+=c[i];
        }
    cout << sum << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:12: error: request for member 'begin' in 'c', which is of non-class type 'int [a]'
   12 |     sort(c.begin(), c.end());
      |            ^~~~~
a.cc:12:23: error: request for member 'end' in 'c', which is of non-class type 'int [a]'
   12 |     sort(c.begin(), c.end());
      |                       ^~~
Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int a,b;
    cin >> a >> b ;
    int c[a] = {0};
    for(int i = 0;i < a;i++){
        cin >> c[i];
    }
    sort(c.end(), c.begin());
    int sum = 0;
    for(int i=a-1;i>=a-b;i--){
        sum+=c[i];
        }
    cout << sum << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:12: error: request for member 'end' in 'c', which is of non-class type 'int [a]'
   12 |     sort(c.end(), c.begin());
      |            ^~~
a.cc:12:21: error: request for member 'begin' in 'c', which is of non-class type 'int [a]'
   12 |     sort(c.end(), c.begin());
      |                     ^~~~~
Language: Java

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList ar = new ArrayList();
		for(int i = 0; i < n; i++){
		    ar.add(sc.nextInt());
		}
		Collections.sort(ar);
		int ret = 0;
		for (int i = 0; i < k ; i++){
		    ret += ar.get(ar.size()-i);
		} 
		
	    System.out.println(ret);
    }
}


Compiler output:
Main.java:17: error: bad operand types for binary operator '+'
		    ret += ar.get(ar.size()-i);
		        ^
  first type:  int
  second type: Object
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
Language: C

#include<stdio.h>
#include<stdlib.h>
/* ソート関数 */
/*int compare_int( const void * a , const void * b ) {
  // 引数はvoid*型と規定されているのでint型にcastする 
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}
*/

int main(void){
	int n;
	int k,i,j;
	int l[50];
	int max = 0;
	
	scanf("%d %d",&n,&k);
	for(i = 0;i<n;i++) scanf("%d",&l[i]);
	
	//qsort(l,50,sizeof(l),compare_int);
	
	for(int i = 1;i<n;i++){	
		int j = i;
		while(j>=1 && l[j-1] > l[j]){
			int temp = l[j];
			l[j] = l[j-1];
			l[j-1] = temp;
			j--;
		}
	}

	for(j = n:j>n-k-1;j--){
		max+=l[j];
	}
	printf("%d\n",max);
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:38:18: error: expected ';' before ':' token
   38 |         for(j = n:j>n-k-1;j--){
      |                  ^
      |                  ;
main.c:38:30: error: expected ';' before ')' token
   38 |         for(j = n:j>n-k-1;j--){
      |                              ^
      |                              ;
Language: C

#include<stdio.h>
#include<stdlib.h>
/* ソート関数 */
int compare_int( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}


int main(void){
	int n;
	int k,i,j;
	int l[50];
	int max = 0;
	
	scanf("%d %d",&n,&k);
	for(i = 0;i<n;i++) scanf("%d",&l[i]);
	
	qsort(l,50,sizeof(l),compare_int);
	
	/*for(int i = 1;i<n;i++){	
		int j = i;
		while(j>=1 && l[j-1] > l[j]){
			int temp = l[j];
			l[j] = l[j-1];
			l[j-1] = temp;
			j--;
		}
	}*/

	for(j = n:j>n-k-1;j--){
		max+=l[j];
	}
	printf("%d\n",max);
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:38:18: error: expected ';' before ':' token
   38 |         for(j = n:j>n-k-1;j--){
      |                  ^
      |                  ;
main.c:38:30: error: expected ';' before ')' token
   38 |         for(j = n:j>n-k-1;j--){
      |                              ^
      |                              ;
Language: C++

#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	vector<int> l(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(), greater<int>());

	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += l[i];
	}
	cout << sum << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |         sort(l.begin(), l.end(), greater<int>());
      |         ^~~~
      |         short
Language: C++

#include <iostream>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int l[N];
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }
    sort(l, l + N);
    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += l[N - 1 -i];
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   11 |     sort(l, l + N);
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <algorithm>
using namespace std;

bool cmp(int x,int y)
{
	return (x>y);
}

int main()
{
	int k,n,sum,tab[100];
	cin>>n>>k;
	for (i=1;i<=n;i++)
	 cin>>tab[i];
	sort(tab+1,tab+n+1,cmp);
	sum=0;
	for (i=1;i<=k;i++)
	 sum+=tab[i];
	cout<<sum<<"\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:14: error: 'i' was not declared in this scope
   14 |         for (i=1;i<=n;i++)
      |              ^
a.cc:18:14: error: 'i' was not declared in this scope
   18 |         for (i=1;i<=k;i++)
      |              ^
Language: C++

#include <iostream>
#include <aglorithm>
using namespace std;

bool cmp(int x,int y)
{
	return (x>y);
}

int main()
{
	int k,n,sum,tab[100];
	cin>>n>>k;
	for (i=1;i<=n;i++)
	 cin>>tab[i];
	sort(tab+1,tab+n+1,cmp);
	sum=0;
	for (i=1;i<=k;i++)
	 sum+=tab[i];
	cout<<sum<<"\n";
}

Compiler output:
a.cc:2:10: fatal error: aglorithm: No such file or directory
    2 | #include <aglorithm>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> Ls(N);
    for (auto & e : Ls) cin >> e;
    sort(Ls.begin(), Ls.end());
    int cum = accumulate(Ls.rbegin(), Ls.rbegin() + K, 0);
    cout << cum << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:15: error: 'accumulate' was not declared in this scope
   12 |     int cum = accumulate(Ls.rbegin(), Ls.rbegin() + K, 0);
      |               ^~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,i,sum=0;
 cin>>n;
int a[n];
for(i=0;i<n;i++)
 cin>>a[i];
sort(a,a+n);
for(i=n-1;i>=n-k;i--)
 sum+=a[i];
cout<<sum;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:16: error: 'k' was not declared in this scope
   10 | for(i=n-1;i>=n-k;i--)
      |                ^
Language: C++

#include <stdio.h>
#include <stdlib.h>

#define IN(a) int a;scanf("%d",&a);
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STRS(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define RANGE(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RANGE3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXI(a,b) if(a<b)a=b;
#define MINI(a,b) if(a>b)a=b;

int main(void){
	int n, k;
	int l[60], size = 0;
	int ans = 0;
	scanf("%d%d", &n, &k);
	REP(i, n) l[i] = 0;

	scanf("%d", l);
	FOR(i, 1, n){
		scanf("%d", l + i);
		int j = i;
		while(l[j] > l[(j - 1)/2]){
			int tmp = l[j];
			l[j] = l[(j - 1)/2];
			l[(j - 1)/2] = tmp;
			j = (j - 1)/2;
		}
	}

	REP(i, k){
		ans += l[0];
		l[0] = l[n - i - 1];
		int j = 0;
		while(l[j] < max(l[j * 2 + 1], l[j * 2 + 2])){
			int tmp = l[j];
			l[j] = max(l[j * 2 + 1], l[j * 2 + 2]);
			(l[j * 2 + 1] > l[j * 2 + 2] ? l[j * 2 + 1] : l[j * 2 + 2]) = tmp;
			j = j * 2 + 1 + (l[j * 2 + 1] < l[j * 2 + 2]);
		}
	}

	printf("%d\n", ans);

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:30: error: 'max' was not declared in this scope
   42 |                 while(l[j] < max(l[j * 2 + 1], l[j * 2 + 2])){
      |                              ^~~
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n.k,l[i],ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
			cin>>l[i];
		}
		sort(l,l+n);
		for(int j=0;j<n-k+1;i++){
			ans+=l[i];
		}
		cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:14: error: expected initializer before '.' token
    6 |         int n.k,l[i],ans=0;
      |              ^
a.cc:7:14: error: 'n' was not declared in this scope
    7 |         cin>>n>>k;
      |              ^
a.cc:7:17: error: 'k' was not declared in this scope
    7 |         cin>>n>>k;
      |                 ^
a.cc:9:30: error: 'l' was not declared in this scope
    9 |                         cin>>l[i];
      |                              ^
a.cc:11:22: error: 'l' was not declared in this scope
   11 |                 sort(l,l+n);
      |                      ^
a.cc:12:37: error: 'i' was not declared in this scope
   12 |                 for(int j=0;j<n-k+1;i++){
      |                                     ^
a.cc:13:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   13 |                         ans+=l[i];
      |                         ^~~
      |                         abs
a.cc:15:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   15 |                 cout<<ans<<endl;
      |                       ^~~
      |                       abs
Language: C

#include<stdio.h>
int main(void)
{
  int K,N,hebi,i,I[51];
  scanf("%d %d",&N,&K);

  for(i=1; i<=N; i++){
    scanf("%d",I[i]);
  }

  for(i=1; i<=K; i++){
    hebi=hebi+I[]

Compiler output:
main.c: In function 'main':
main.c:12:17: error: expected expression before ']' token
   12 |     hebi=hebi+I[]
      |                 ^
main.c:12:17: error: expected declaration or statement at end of input
main.c:12:17: error: expected declaration or statement at end of input
Language: C++

#include <iostream>
#include <map>
using namespace std;

int main(){
  int n,k,l,counter=0,ans=0;
  map<int,int> mp;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> l;
    mp[-1*l]=l;
  }
  for(auto itr=mp.begin(),itr!=mp.end(),itr++){
    ans+=itr->second;
    k++;
    if(counter==k){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:30: error: expected ';' before '!=' token
   13 |   for(auto itr=mp.begin(),itr!=mp.end(),itr++){
      |                              ^~
      |                              ;
a.cc:13:30: error: expected primary-expression before '!=' token
   13 |   for(auto itr=mp.begin(),itr!=mp.end(),itr++){
      |                              ^~
a.cc:13:46: error: expected ';' before ')' token
   13 |   for(auto itr=mp.begin(),itr!=mp.end(),itr++){
      |                                              ^
      |                                              ;
Language: C++

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
#define lowbit(x) ((x)&(-x))
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a>b?b:a)
#define INF 0x3f3f3f3f
#define sz size()
#define pb push_back
#define ph push
#define mem(x, y) memset(x, y, sizeof(x));
#define mem0(x) mem(x,0)
#define mem1(x) mem(x,-1)
#define memINF(x) mem(x,INF)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=a;i>(b);--i)
using namespace std;
typedef long long ll;
 
int const Max_N = 1e6+5;
ll a[Max_N];
ll sum[Max_N]；
int main()
{
 	int N;
	cin >> N;
	rep(i,1,N+1)
	{
		cin >> a[i];
		sum[i] += sum[i-1] + a[i];
	}
 
 
	ll ans = 1e18;
	rep(i,1,N)
	{
	//	cout << sum[i] << endl;
	//	cout << sum[N] - 2*sum[i] << endl;
		ans = min(ans,abs(sum[N] - 2*sum[i]));
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:30:1: error: extended character   is not valid in an identifier
   30 |  
      | ^
a.cc:43:1: error: extended character   is not valid in an identifier
   43 |  
      | ^
a.cc:44:1: error: extended character   is not valid in an identifier
   44 |  
      | ^
a.cc:30:1: error: '\U000000a0' does not name a type
   30 |  
      | ^
a.cc:32:6: error: 'Max_N' was not declared in this scope; did you mean 'Max'?
   32 | ll a[Max_N];
      |      ^~~~~
      |      Max
a.cc:33:8: error: 'Max_N' was not declared in this scope; did you mean 'Max'?
   33 | ll sum[Max_N]；
      |        ^~~~~
      |        Max
a.cc:33:14: error: expected initializer before '\U0000ff1b'
   33 | ll sum[Max_N]；
      |              ^~
Language: C++

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
#define lowbit(x) ((x)&(-x))
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a>b?b:a)
#define INF 0x3f3f3f3f
#define sz size()
#define pb push_back
#define ph push
#define mem(x, y) memset(x, y, sizeof(x));
#define mem0(x) mem(x,0)
#define mem1(x) mem(x,-1)
#define memINF(x) mem(x,INF)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=a;i>(b);--i)
using namespace std;
typedef long long ll;
 
int const Max_N = 1e6+5;
ll a[Max_N];
ll sum[Max_N] = {0};
int main()
{
 	int N;
	cin >> N;
	rep(i,1,N+1)
	{
		cin >> a[i];
		sum[i] += sum[i-1] + a[i];
	}
 
 
	ll ans = 1e18;
	rep(i,1,N)
	{
	//	cout << sum[i] << endl;
	//	cout << sum[N] - 2*sum[i] << endl;
		ans = min(ans,abs(sum[N] - 2*sum[i]));
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:30:1: error: extended character   is not valid in an identifier
   30 |  
      | ^
a.cc:43:1: error: extended character   is not valid in an identifier
   43 |  
      | ^
a.cc:44:1: error: extended character   is not valid in an identifier
   44 |  
      | ^
a.cc:30:1: error: '\U000000a0' does not name a type
   30 |  
      | ^
a.cc:32:6: error: 'Max_N' was not declared in this scope; did you mean 'Max'?
   32 | ll a[Max_N];
      |      ^~~~~
      |      Max
a.cc:33:8: error: 'Max_N' was not declared in this scope; did you mean 'Max'?
   33 | ll sum[Max_N] = {0};
      |        ^~~~~
      |        Max
a.cc: In function 'int main()':
a.cc:40:24: error: 'a' was not declared in this scope
   40 |                 cin >> a[i];
      |                        ^
a.cc:41:17: error: 'sum' was not declared in this scope
   41 |                 sum[i] += sum[i-1] + a[i];
      |                 ^~~
a.cc:43:1: error: '\U000000a0' was not declared in this scope
   43 |  
      | ^
a.cc:50:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   50 |                 ans = min(ans,abs(sum[N] - 2*sum[i]));
      |                 ^~~
      |                 abs
a.cc:50:35: error: 'sum' was not declared in this scope
   50 |                 ans = min(ans,abs(sum[N] - 2*sum[i]));
      |                                   ^~~
a.cc:52:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |         cout << ans << endl;
      |                 ^~~
      |                 abs
Language: C++


#include <iostream>
#include <vector>
#include <algorithm>    //ソート用

using namespace std;

int main(void){
    
    int n,k;
    cin >> n >> k;
    vector<int> l(n); //vectorの大きさをnに設定
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
//    for(int &val : l){
//        cin >> val;
//    }
    
    sort(l.begin(),l.end());    //C++ではソート用の関数が用意されていることが多いため、ソート関数を実装する必要はない
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += 1[n-1-i];
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:17: error: invalid types 'int[int]' for array subscript
   23 |         ans += 1[n-1-i];
      |                 ^
Language: C++


#include <iostream>
#include <vector>
#include <algorithm>    //ソート用

using namespace std;

int main(void){
    
    int n,k;
    cin >> n >> k;
    vector<int> l(n); //vectorの大きさをnに設定
   for(int i = 0; i < n; i++){
        cin >> l[i];
    }

    
    sort(l.begin(),l.end());    //C++ではソート用の関数が用意されていることが多いため、ソート関数を実装する必要はない
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += 1[n-1-i];
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: invalid types 'int[int]' for array subscript
   21 |         ans += 1[n-1-i];
      |                 ^
Language: C++


#include <iostream>
#include <vector>
#include <algorithm>    //ソート用

using namespace std;

int main(void){
    
    int n,k;
    cin >> n >> k;
    vector<int> l(n); //vectorの大きさをnに設定
//    for(int i = 0; i < n; i++){
//        cin >> l[i];
//    }
    for(int &val : l){
        cin >> val;
    }
    
    sort(l.begin(),l.end());    //C++ではソート用の関数が用意されていることが多いため、ソート関数を実装する必要はない
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += 1[n-1-i];
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:17: error: invalid types 'int[int]' for array subscript
   23 |         ans += 1[n-1-i];
      |                 ^
Language: C++

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;
    ll ans=0,id;
    int N,M;
    ll A,B,C,W;
    int a[100010];
    bool f=false;
    ll sum=0;
    string S;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,N)cin>>a[i];
    sort(a,a+N);
    REP(i,K){
        ans+=a[N-i-1];
    }
    cout<<ans;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:11: error: 'K' was not declared in this scope
   43 |     REP(i,K){
      |           ^
a.cc:14:34: note: in definition of macro 'REP'
   14 | #define REP(i,n) for (int i=0;i<(n);i++)
      |                                  ^
Language: C++

#include<cstdio>

int main(){
	int max = 0;
	int n, k;
	int l[50];
	scanf("%d%d,&n,&k);
	
	for(int i = 0; i < n; i++){
		scanf("%d", &l[i]);
		if(max < l[i]){
			max = l[i];
		}
	}
	int sum = 0, ans = 0;
	sum += max;
	for(i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(n * max > ans && sum + l[i] + l[j] > ans){
				ans = sum + l[i] + l[j];
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Compiler output:
a.cc:7:15: warning: missing terminating " character
    7 |         scanf("%d%d,&n,&k);
      |               ^
a.cc:7:15: error: missing terminating " character
    7 |         scanf("%d%d,&n,&k);
      |               ^~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:9:9: error: expected primary-expression before 'for'
    9 |         for(int i = 0; i < n; i++){
      |         ^~~
a.cc:9:24: error: 'i' was not declared in this scope
    9 |         for(int i = 0; i < n; i++){
      |                        ^
Language: C++

#include <stdio.h>

int main(void)
{
	int i,j,cng,ans;
	int N,K;
	int l[50];
	
	scanf("%d %d",&N,&K);
	
	for(i=0;i<N;i++){
		scanf("%d",&l[N]);
		
	}
	
	for(i=0;i<N;i++){
		for(j=0;j<N;i++){
			if(l[i]< l[j]){
				
				cng =l[i];
				l[i] = l[j];
				l[j] = cng;
			}
		}
	}
	
	ans =0;
	for(i=0;i<K;i++){
		ans = ans +l[K];
	}
	
	printf("%d",ans);
	
	return 0;


Compiler output:
a.cc: In function 'int main()':
a.cc:34:18: error: expected '}' at end of input
   34 |         return 0;
      |                  ^
a.cc:4:1: note: to match this '{'
    4 | {
      | ^
Language: C

#include<stdio.h>
 
int N, K;
int Snake[1000000];
 
int main(void){
int i, j, c, sum;
scanf("%d %d", &N, &K);
 
 
for(i = 0; i < N; i++){
scanf("%d", &Snake[i]);
}
 
for( i = 0; i < N-1; i++){
for(j = i + 1; j < N; j++){
if(Snake[i] <= Snake[j] ){ 
c = Snake[j]; 
Snake[i] = Snake[j]; 
Snake[j] = c;
}
}}
 
sum = 0;
for(i = 0; i < K; i++){
sum += Snake[i];
}
printf("%d". sum);
return 0;
}

Compiler output:
main.c: In function 'main':
main.c:28:12: error: request for member 'sum' in something not a structure or union
   28 | printf("%d". sum);
      |            ^
Language: C

#include<stdio.h>

int N, K;
int Snake[100000];

int main(void){
int i, j, c, sum;
scanf("%d %d", &N, &K);
for(i = 0; i < N; i++){
scanf("%d", &Snake[i];
}

for( i = 0; i < N-1; i++){
for(j = i + 1; j < N; j++){
if(Snake[i] <= Snake[j] ){ c = Snake[j]; Snake[i] = Snake[j]; Snake[j] = c;
}
}}

sum = 0;
for(i = 0; i < K; i++){
sum += Snake[i];
}
return 0;
}



Compiler output:
main.c: In function 'main':
main.c:10:22: error: expected ')' before ';' token
   10 | scanf("%d", &Snake[i];
      |      ~               ^
      |                      )
main.c:10:23: error: expected ';' before '}' token
   10 | scanf("%d", &Snake[i];
      |                       ^
      |                       ;
   11 | }
      | ~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int arr[100];

int main() {

	int n,k,ans=0;

	cin>>n>>k;

	for(int i=0;i<n;++i) cin>>a[i];

	sort(a,a+n);

	reverse(a,a+n);

	for(int i=0;i<k;++i) ans+=a[i];

	cout<<ans<<'\n';



}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:35: error: 'a' was not declared in this scope
   12 |         for(int i=0;i<n;++i) cin>>a[i];
      |                                   ^
a.cc:14:14: error: 'a' was not declared in this scope
   14 |         sort(a,a+n);
      |              ^
Language: C

#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100];
int main()
{
	int N,K;
	while(~scanf("%d%d",&N,&K))
	{
		int sum=0;
		for(int i=1;i<=N;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+N+1);
	    for(int i=N-K+1;i<=N;i++)
		{
			sum=sum+a[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}



Compiler output:
main.c:2:9: fatal error: algorithm: No such file or directory
    2 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

#include<cstdio>
#include<bits/stdc++.h>
#include<cstring>
#include<algorithm>
 #include<iostream>
bool cmp(int a,int b)
{

	return a>b;
}

int main()
{
int a[55];
int x,y;
while(scanf("%d%d",&x,&y)!=EOF)
{  memset(a,0,sizeof(a));
	for(int i=0;i<x;i++)
	 scanf("%d",&a[i]);
	 sort(a,a+x,cmp);
	 long long sum=0;
	 for(int q=0;q<y;q++)
	 sum=sum+a[q];
	 
	printf("%lld\n",sum);
	
	
	
}

return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:10: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   20 |          sort(a,a+x,cmp);
      |          ^~~~
      |          std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
Language: C++

#include <algorithm> 
#include <iostream> 
using namespace std; 

int main(){
int N,a,l[50],yan,b;
cin>>N>>a;
for(int i=0;i<N;i++){
cin>>l[i];
}
for(int j=0;j<N;j++){
for(int k=i+1;k<N;k++){
if(l[j]>l[k]){
yan=l[j];
l[j]=l[k];
l[k]=yan;
}
}
}
for(int m=0;m<a;m++){
b+=l[m]
}
cout<<b<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:11: error: 'i' was not declared in this scope
   12 | for(int k=i+1;k<N;k++){
      |           ^
a.cc:21:8: error: expected ';' before '}' token
   21 | b+=l[m]
      |        ^
      |        ;
   22 | }
      | ~
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
	int n,k;
	while(scanf("%d %d",&n,&k)!=EOF)
	{
		int a[52],s=0,i,j;
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		sort(a,a+n);
		for(i=n-1,j=0;i>=0;i--,j++)
		{
			s=s+a[i];
			if(j==(k-1))break;
		}
		printf("%d\n",s);
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:13:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |                 sort(a,a+n);
      |                 ^~~~
      |                 short
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> L;
    L.reserve(N);

    int data;
    for (int n = 0; n < N; n++) {
        cin >> data;
        L.push_back(data);
    }
    sort(L.begin(), L.end());
    
    auto itr = L.rbegin();

    int sum = 0;
    for (int n = 0; n < K; n++) {
        sum += *itr;
        itr++;
    }

    cout << sum << endl;

    return 0;
 

Compiler output:
a.cc: In function 'int main()':
a.cc:31:14: error: expected '}' at end of input
   31 |     return 0;
      |              ^
a.cc:7:12: note: to match this '{'
    7 | int main() {
      |            ^
Language: C++

#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main(void){
	int N, K;
	int ans=0;
	cin >> N >> K;
	int l[N];
	for(int i=0; i<N; i++){
		cin >> l[i];
	}
	sort(l, l+N);
	for(int i=0; i<K; i++){
		ans += l[N-i-1];
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   15 |         sort(l, l+N);
      |         ^~~~
      |         short
Language: C++




#include <iostream>
#include <vector>

using namespace std;


int main(void) {
    
    int N, K;
    int ans = 0;
    vector<int> L;
    vector<int> M;
    
    cin >> N >> K;
    
    
    for (int i = 0; i < N; ++i) {
        
        int n; cin >> n;
        
        L.push_back(n);
        
    }
    
    for (int i = 0; i < K; ++i) {
        
        auto itr = max_element(L.begin(), L.end());
        
        M[i] = *itr;
        
        L.erase(itr);
        
        ans += *itr;
        
    }
    
    cout << ans << endl;
    
    return 0;
    
}





















Compiler output:
a.cc: In function 'int main()':
a.cc:30:20: error: 'max_element' was not declared in this scope
   30 |         auto itr = max_element(L.begin(), L.end());
      |                    ^~~~~~~~~~~