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

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

int main() {
  int N,K;
  cin>>N>>K;
  
  int vec[N];
  for(int i=0;i<N;++i){
    cin>>vec[i];
  }
  
  sort(vec.begin(),vec.end(),greater<int>());
  
  int max=0;
  
  for(int i=0;i<K;++i){
    max=max+vec[i];
  }
  
  cout<<max<<endl;
}


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

import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] l = new int(n);
		for(int i=0; i<n; i++){
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		int len = 0;
		for(int i=0; i<k; i++){
			len += l[n-i-1];
		}
		System.out.println(len);
	}
}

Compiler output:
Main.java:7: error: '[' expected
		int[] l = new int(n);
		                 ^
Main.java:7: error: ']' expected
		int[] l = new int(n);
		                    ^
2 errors
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(k);
    REP(i,n)cin>>vec[i];
    sort(vec.begin(),vec.end());
    recerse(vec.begin(),vec.end());
    int ans;
    REP(i,k){
        ans += vec[i];
    }
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'recerse' was not declared in this scope
   11 |     recerse(vec.begin(),vec.end());
      |     ^~~~~~~
Language: C++

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

int main() {
  int N, K, l[60];
  cin >> N >>K;
  
  for (int i=0; i<N; i++) cin >> l[i];
  
  sort(l, l+N, greater<int>());
  
  int t=0;
  for (int i=0; i<K; i++){
  t+=l[i]
  }
    
  cout << t <<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:10: error: expected ';' before '}' token
   14 |   t+=l[i]
      |          ^
      |          ;
   15 |   }
      |   ~
Language: C++

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


using namespace std;

int main() {
	int n,k,s,iwa=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){cin>>s[i];}
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=0;i<k;i++){iwa+=s[i];}
	cout<<iwa<<endl;
	}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:36: error: invalid types 'int[int]' for array subscript
   11 |         for(int i=0;i<n;i++){cin>>s[i];}
      |                                    ^
a.cc:12:14: error: 'a' was not declared in this scope
   12 |         sort(a,a+n);
      |              ^
a.cc:14:36: error: invalid types 'int[int]' for array subscript
   14 |         for(int i=0;i<k;i++){iwa+=s[i];}
      |                                    ^
Language: C++

#include <stdio.h>
#pragma warning (disable : 4996)

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(void) {
 int i, n = 0, N, K, l[50];
  scanf ("%d %d", &N ,&K);
  
  for (i = 0; i < N; i++) { 
   scanf ("%d", &l[i]);
  }
  qsort(l, sizeof(l) / sizeof(*l), sizeof(*l), desc);
  
  for(i = 0; i < K; i++) {
    n += l[i];
  }
  printf("%d", n);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:3: error: 'qsort' was not declared in this scope
   15 |   qsort(l, sizeof(l) / sizeof(*l), sizeof(*l), desc);
      |   ^~~~~
Language: C++

#include <stdio.h>
#pragma warning (disable : 4996)

int main(void) {
 int i, n = 0, N[50] , K;
  scanf (%d %d, &N ,%K);
  
  for(i = N; i < K; i++) {
    n =+ N;
  }
  printf("%d", n);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:10: error: expected primary-expression before '%' token
    6 |   scanf (%d %d, &N ,%K);
      |          ^
a.cc:6:11: error: 'd' was not declared in this scope
    6 |   scanf (%d %d, &N ,%K);
      |           ^
a.cc:6:21: error: expected primary-expression before '%' token
    6 |   scanf (%d %d, &N ,%K);
      |                     ^
a.cc:8:11: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    8 |   for(i = N; i < K; i++) {
      |           ^
      |           |
      |           int*
a.cc:9:8: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    9 |     n =+ N;
      |        ^~~
      |        |
      |        int*
Language: C++

#include <stdio.h>
#pragma warning (disable : 4996)

int main(void) {
 int i,,n = 0, N[50] , K;
  scanf (%d %d, &N ,%K);
  
  for(i = N; i < K; i++) {
    n =+ N;
  }
  printf("%d", n);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:8: error: expected unqualified-id before ',' token
    5 |  int i,,n = 0, N[50] , K;
      |        ^
a.cc:6:10: error: expected primary-expression before '%' token
    6 |   scanf (%d %d, &N ,%K);
      |          ^
a.cc:6:11: error: 'd' was not declared in this scope
    6 |   scanf (%d %d, &N ,%K);
      |           ^
a.cc:6:21: error: expected primary-expression before '%' token
    6 |   scanf (%d %d, &N ,%K);
      |                     ^
a.cc:8:11: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    8 |   for(i = N; i < K; i++) {
      |           ^
      |           |
      |           int*
a.cc:9:8: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    9 |     n =+ N;
      |        ^~~
      |        |
      |        int*
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;

int K, N;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  priority_queue<int, vector<int>, greater<>> que;
  rep(i, N) {
    int a; cin >> a;
    que.push(a);
    if (que.size() > K) {
      que.pop();
    }
  }

  int sum = 0;
  rep(i, K) {
    sum += que.at(i);
  }
  cout << sum << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:16: error: 'class std::priority_queue<int, std::vector<int>, std::greater<void> >' has no member named 'at'
   36 |     sum += que.at(i);
      |                ^~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;

int K, N;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  priority_queue<int, vector<int>, greater<>> que;
  rep(i, N) {
    int a; cin >> a;
    que.push();
    if (que.size() > K) {
      que.pop();
    }
  }

  int sum = 0;
  rep(i, K) {
    sum += que.at(i);
  }
  cout << sum << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:13: error: no matching function for call to 'std::priority_queue<int, std::vector<int>, std::greater<void> >::push()'
   28 |     que.push();
      |     ~~~~~~~~^~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:8:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<void>; value_type = int]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<void>; value_type = int]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note:   candidate expects 1 argument, 0 provided
a.cc:36:16: error: 'class std::priority_queue<int, std::vector<int>, std::greater<void> >' has no member named 'at'
   36 |     sum += que.at(i);
      |                ^~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
  int N,K;
  vector<int> vec[51]
  cin >> N >> K;
  for(int i = 0;i < N;i++) cin >> vec[i];
  sort(vec.rbegin(),vec.rend());
  int length=0;
  for(int i = 0;i < K;i++){
    length += vec[i];
  }
  cout << length << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:3: error: expected initializer before 'cin'
   25 |   cin >> N >> K;
      |   ^~~
a.cc:26:35: error: 'vec' was not declared in this scope
   26 |   for(int i = 0;i < N;i++) cin >> vec[i];
      |                                   ^~~
a.cc:27:8: error: 'vec' was not declared in this scope
   27 |   sort(vec.rbegin(),vec.rend());
      |        ^~~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
  int N,K,l[51];
  cin >> N >> K;
  for(int i = 0;i < N;i++) cin >> l[i];
  sort(l.rbegin(),l.rend());
  int length=0;
  for(int i = 0;i < K;i++){
    length += l[i];
  }
  cout << length << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:10: error: request for member 'rbegin' in 'l', which is of non-class type 'int [51]'
   26 |   sort(l.rbegin(),l.rend());
      |          ^~~~~~
a.cc:26:21: error: request for member 'rend' in 'l', which is of non-class type 'int [51]'
   26 |   sort(l.rbegin(),l.rend());
      |                     ^~~~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
  int N,K,l[51];
  cin >> N >> K;
  for(int i = 0;i < N;i++) cin >> l[i];
  sort(l.rstart(),l.rend());
  int length=0;
  for(int i = 0;i < K;i++){
    length += l[i];
  }
  cout << length << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:10: error: request for member 'rstart' in 'l', which is of non-class type 'int [51]'
   26 |   sort(l.rstart(),l.rend());
      |          ^~~~~~
a.cc:26:21: error: request for member 'rend' in 'l', which is of non-class type 'int [51]'
   26 |   sort(l.rstart(),l.rend());
      |                     ^~~~
Language: C++

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

int main(){
  int n,k,a[50],sum=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n-k;i++)
    sum-=a[i];
  cout <<sum<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: 'cin' was not declared in this scope
    7 |   cin>>n>>k;
      |   ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include<algorithm>
  +++ |+#include <iostream>
    3 | using namespace std;
a.cc:15:3: error: 'cout' was not declared in this scope
   15 |   cout <<sum<<endl;
      |   ^~~~
a.cc:15:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:15:15: error: 'endl' was not declared in this scope
   15 |   cout <<sum<<endl;
      |               ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include<algorithm>
  +++ |+#include <ostream>
    3 | using namespace std;
Language: C++

#include <iostream>

using namespace std;

int main()
{
  int n, k, len;
  vector<int> iv;

  for (int i = 0; i < n; i++) {
    int l; cin >> l;
    iv.push_back(l);
  }

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

  for (int i = 0; i < k; i++) len += iv[i];

  cout << len << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:3: error: 'vector' was not declared in this scope
    8 |   vector<int> iv;
      |   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | 
a.cc:8:10: error: expected primary-expression before 'int'
    8 |   vector<int> iv;
      |          ^~~
a.cc:12:5: error: 'iv' was not declared in this scope; did you mean 'i'?
   12 |     iv.push_back(l);
      |     ^~
      |     i
a.cc:15:8: error: 'iv' was not declared in this scope; did you mean 'div'?
   15 |   sort(iv.begin(), iv.end(), greater<int>());
      |        ^~
      |        div
a.cc:15:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   15 |   sort(iv.begin(), iv.end(), greater<int>());
      |   ^~~~
      |   short
Language: C++

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

using namespace std;

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

	int a[100];
	for (i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	reverse(a, a + N);
	int nagasa = 0;
	for (i = 0; i < K; i++) {
		nagasa += a[i];
	}
	cout << nagasa << endl;
	return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(n);
  for(int i=0;i<N;i++){
    cin >> l.at(i);
  }
  int s=0;
  sort(l.begin(),l.end());
  for(int i=0;i<K;i++){
    s+=l.at(N-1-i);
  }
  cout << s << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:17: error: 'n' was not declared in this scope
    7 |   vector<int> l(n);
      |                 ^
Language: C++

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(60);
  for(int i=0;i<N;i++){
    cin >> l.at(i);
  }
  int s=0;
  sort(l.begin(),l.end());
  for(int i=0;i<K;i++){
    s+=l.at(N-1-i);
  }
  cout << s << endl;
}

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

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int K = sc.nextInt();
            int Ln[] = new int[N];
            
            for(int i = 0;i < N;i++){
                Ln[i] = sc.nextInt();
            }
            Arrays.sort(Ln, Comparator.reverseOrder());
            for(int i = 0;i < N;i++){
                System.out.println(Ln[i]);
            }

    }
}

Compiler output:
Main.java:13: error: no suitable method found for sort(int[],Comparator<T#1>)
            Arrays.sort(Ln, Comparator.reverseOrder());
                  ^
    method Arrays.<T#2>sort(T#2[],Comparator<? super T#2>) is not applicable
      (inference variable T#2 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method Arrays.<T#3>sort(T#3[],int,int,Comparator<? super T#3>) is not applicable
      (cannot infer type-variable(s) T#3
        (actual and formal argument lists differ in length))
  where T#1,T#2,T#3 are type-variables:
    T#1 extends Comparable<? super T#1>
    T#2 extends Object declared in method <T#2>sort(T#2[],Comparator<? super T#2>)
    T#3 extends Object declared in method <T#3>sort(T#3[],int,int,Comparator<? super T#3>)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
Language: C++

#include<bits/stdc++,h>
using namespace std;
int n,k,a[101],sum;
bool cmp(int c,int d)
{
	if(c>d)
	return true;
	else return false;
}
int main()
{
    int i;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1,cmp);
    for(i=1;i<=k;i++)
    sum+=a[i];
    cout<<sum;
    return 0;
}


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

from os import listdir, rename
from os.path import dirname, abspath, join

# Current working directory path
cwd = dirname(abspath(__file__))

# file list
cwd_dir = listdir(cwd)
for i in range(0,len(cwd_dir)):
    print([i, cwd_dir[i]])

# delete '\n', '\r' and replace '.'
select = int(input('select number : '))
N = 0
K = 0
array = []
with open(join(cwd, cwd_dir[select]), 'r', encoding='utf-8') as f:
    data = f.read()
    data = data.split()
    N = int(data[0])
    K = int(data[1])
    array = data[2:]

result = 0
for i in range(K):
    result += int(sorted(array)[-i])

print(result)

Compiler output:
a.cc:4:3: error: invalid preprocessing directive #Current
    4 | # Current working directory path
      |   ^~~~~~~
a.cc:7:3: error: invalid preprocessing directive #file
    7 | # file list
      |   ^~~~
a.cc:12:3: error: invalid preprocessing directive #delete
   12 | # delete '\n', '\r' and replace '.'
      |   ^~~~~~
a.cc:13:20: warning: multi-character literal with 16 characters exceeds 'int' size of 4 bytes
   13 | select = int(input('select number : '))
      |                    ^~~~~~~~~~~~~~~~~~
a.cc:17:53: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   17 | with open(join(cwd, cwd_dir[select]), 'r', encoding='utf-8') as f:
      |                                                     ^~~~~~~
a.cc:1:1: error: 'from' does not name a type
    1 | from os import listdir, rename
      | ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  int ans = 0;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) cin >> vec.at(i);
  sort(bec.begin(), vec.end(), greater<int>);
  for(int i = 0; i < k; i++) {
    ans += vec.at(i);
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:8: error: 'bec' was not declared in this scope; did you mean 'vec'?
    9 |   sort(bec.begin(), vec.end(), greater<int>);
      |        ^~~
      |        vec
a.cc:9:44: error: expected primary-expression before ')' token
    9 |   sort(bec.begin(), vec.end(), greater<int>);
      |                                            ^
Language: C++

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

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

  sort(l,l+N,greater<int>()); // lを大きい順にソート

  int total=0;
  for(int i=0 ; i < K ; i++) total += a[i];

  cout << total;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:39: error: 'a' was not declared in this scope
   13 |   for(int i=0 ; i < K ; i++) total += a[i];
      |                                       ^
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:11:27: error: expected ';' before ')' token
   11 |   for ( int i=0; i <N, ++i) cin >> a[i];
      |                           ^
      |                           ;
a.cc:13:27: error: expected ';' before ')' token
   13 |   for (int i =0; i <K, ++i) {
      |                           ^
      |                           ;
Language: C++

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

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> buf;
    v.push_back(buf);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int len;
  for (int i = 0; i < k; i++) {
    len += v[i];
  }
  cout << len << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:12: error: 'buf' was not declared in this scope
   12 |     cin >> buf;
      |            ^~~
Language: C++

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

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


Compiler output:
a.cc: In function 'int main()':
a.cc:12:16: error: no matching function for call to 'std::vector<int>::push_back(std::istream&)'
   12 |     v.push_back(cin);
      |     ~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::istream' {aka 'std::basic_istream<char>'} to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::istream' {aka 'std::basic_istream<char>'} to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
Language: C++

#include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp(int x,int y){return x>y;}
int main(){
  int n,k;
  int list[101]; 
 while(scanf("%d%d",&n,&k)!=EOF){
     for(int i=0;i<n;i++){
        scanf("%d",&list[i]);
     }
 sort(list,list+n,cmp);
int ans=0;
for(int i=0;i<k;i++){
    ans+=list[i];
    }
printf("%d\n",ans);
  }
return 0;


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

#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
  int n,k;
  int list[101]; 
bool cmp(int x,int y){return x>y;}
 while(scanf("%d%d",&n,&k)!=EOF){
     for(int i=0;i<n;i++){
        scanf("%d",&list[i]);
     }
 sort(list,list+n,cmp);
int ans=0;
for(int i=0;i<k;i++){
    ans+=list[i];
    }
printf("%d\n",ans);
  }
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:22: error: a function-definition is not allowed here before '{' token
    7 | bool cmp(int x,int y){return x>y;}
      |                      ^
a.cc:12:19: error: 'cmp' was not declared in this scope
   12 |  sort(list,list+n,cmp);
      |                   ^~~
Language: C++

#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
  int n,k;
  int list[101]; 
 while(scanf("%d%d",&n,&k)!=EOF){
     for(int 0;i<n;i++){
        scanf("%d",&list[i]);
     }
 sort(list,list+n);
int ans=0;
for(int i=0;i<k;i++){
    ans+=list[i];
    }
printf("%d\n",ans);
  }
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:14: error: expected unqualified-id before numeric constant
    8 |      for(int 0;i<n;i++){
      |              ^
a.cc:8:13: error: expected ';' before numeric constant
    8 |      for(int 0;i<n;i++){
      |             ^~
      |             ;
a.cc:8:16: error: 'i' was not declared in this scope
    8 |      for(int 0;i<n;i++){
      |                ^
a.cc:8:19: error: expected ')' before ';' token
    8 |      for(int 0;i<n;i++){
      |         ~         ^
      |                   )
a.cc:8:20: error: 'i' was not declared in this scope
    8 |      for(int 0;i<n;i++){
      |                    ^
Language: C++

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

int main(){
int n,k;
cin>>k>>n;
vector<int>l;
for(int i=0;i<n;i++){
  cin>>l.at(i);
}
sort(l.begin(),l.end());
reverse(l.begin,l.end());
int a=0;
for(int i=0;i<k;i++){
  a+=l.at(i);
  }
  cout<<a<<endl;  
return 0;
}
 

Compiler output:
a.cc: In function 'int main()':
a.cc:12:8: error: no matching function for call to 'reverse(<unresolved overloaded function type>, std::vector<int>::iterator)'
   12 | reverse(l.begin,l.end());
      | ~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:1083:5: note: candidate: 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]'
 1083 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1083:36: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 1083 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note:   candidate expects 3 arguments, 2 provided
Language: C++

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

int main(){
int a,b,c[50],d = 0;
  cin >> a >> b;
  for(int S = 0; S < a;S++){
  cin >> c[S];
  }
  
  sort(c,c+a,greater<int>());
  
  for(int S = 0;S < b;S++){
  d += c[S];
  }
  cout << d << endl;
return -;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:9: error: expected primary-expression before ';' token
   17 | return -;
      |         ^
Language: C++

#include <bits/stdc++.h>

#define o(output) cout << output << endl
#define priolity_queue pq
#define push p
#define top t

using namespace std;

string s;
int a,b,c,d;
char A,B;
priority_queue<int> pr;

int main(){
  cin>>a>>b;
  for(int i=0;i<a;i++){
    int dispo;
    cin>>dispo;
    pr.p(dispo);
    }
  for(int i=0;i<b;i++){
    c+=pr.top();
  pr.pop();
    }
  o(c);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:8: error: 'class std::priority_queue<int>' has no member named 'p'
   20 |     pr.p(dispo);
      |        ^
a.cc:6:13: error: 'class std::priority_queue<int>' has no member named 't'
    6 | #define top t
      |             ^
a.cc:23:11: note: in expansion of macro 'top'
   23 |     c+=pr.top();
      |           ^~~
Language: C++

#incluse<iostream>
using namespace std;

int main () {
  int N,K,l1,l2,l3,...ln;
  cin>>N>>K>>l1>>l2>>l3>>...>>ln;
  
  cout<<l1+l2+l3+...ln<<emdl;
}

Compiler output:
a.cc:1:2: error: invalid preprocessing directive #incluse; did you mean #include?
    1 | #incluse<iostream>
      |  ^~~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:5:20: error: expected unqualified-id before '...' token
    5 |   int N,K,l1,l2,l3,...ln;
      |                    ^~~
a.cc:6:3: error: 'cin' was not declared in this scope
    6 |   cin>>N>>K>>l1>>l2>>l3>>...>>ln;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #incluse<iostream>
a.cc:8:3: error: 'cout' was not declared in this scope
    8 |   cout<<l1+l2+l3+...ln<<emdl;
      |   ^~~~
a.cc:8:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

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

int main() {
	int k, n, i, j;
	cin >> n >> k;
	vector<int> vec(n);
	for (i = 0; i < n; i++){
		cin >> vec.at(i);
	}
	
	
	int a, b, c;
	c = 0;
	for (j = 0; j < k; j++ ){
		b = 0
		for (i = 0;i < n; i ++){
			if (a < vec.at(i)){
				a = vec.at(i);
				b = i;
			}
		}
		vec.at(b) = 0;
		c += a;
	}
	cout << c << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:22: error: expected ';' before 'for'
   17 |                 b = 0
      |                      ^
      |                      ;
   18 |                 for (i = 0;i < n; i ++){
      |                 ~~~   
a.cc:18:39: error: expected ';' before ')' token
   18 |                 for (i = 0;i < n; i ++){
      |                                       ^
      |                                       ;
Language: C++

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

int main() {
	int k, n, i, j;
	cin >> k >> n;
	vector<int> vec(n);
	for (i = 0; i < n; i++){
		cin >> vec.at(i)
	}
	int a, b, c;
	for (j = 0; j < k; j++ ){
		for (i = 0;i < n; i ++){
			if (a < vec.at(i)){
				a = vec.at(i);
				b = i;
			}
		}
		vec.at(b) = 0;
		c += a;
	}
	cout << c << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:33: error: expected ';' before '}' token
   10 |                 cin >> vec.at(i)
      |                                 ^
      |                                 ;
   11 |         }
      |         ~
Language: C++

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

int main() {
	int k, n, i, j;
	cin >> k >> n;
	vector<int> vec(n);
	for (i = 0; i < n; i++){
		cin >> vex.at(i)
	}
	int a, b, c;
	for (j = 0; j < k; j++ ){
		for (i = 0;i < n; i ++){
			if (a < vec.at(i)){
				a = vec.at(i);
				b = i;
			}
		}
		vec.at(b) = 0;
		c += a;
	}
	cout << c << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:24: error: 'vex' was not declared in this scope; did you mean 'vec'?
   10 |                 cin >> vex.at(i)
      |                        ^~~
      |                        vec
Language: C++

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

int main() {
	int k, n, i, j;
	cin >> k >> n;
	vector<int> vec(n);
	for (i = 0; i < n; i++){
		cin >> vex.at(i)
	}
	int a, b, c;
	for (j = 0; j < k; j++ ){
		for (i = 0;i < n; i ++){
			if (a < vec.at(i)){
				a = vec.a(i);
				b = i;
			}
		}
		vec.at(b) = 0;
		c += a
	}
	cout << c << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:24: error: 'vex' was not declared in this scope; did you mean 'vec'?
   10 |                 cin >> vex.at(i)
      |                        ^~~
      |                        vec
a.cc:16:41: error: 'class std::vector<int>' has no member named 'a'; did you mean 'at'?
   16 |                                 a = vec.a(i);
      |                                         ^
      |                                         at
a.cc:21:23: error: expected ';' before '}' token
   21 |                 c += a
      |                       ^
      |                       ;
   22 |         }
      |         ~
Language: C++

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

Compiler output:
a.cc: In function 'int main()':
a.cc:11:18: error: expected ';' before 'return'
   11 |         cout<<ans
      |                  ^
      |                  ;
   12 |         return 0;
      |         ~~~~~~
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:12:18: error: expected ';' before '<=' token
   12 |   for (int i=0, i<=N-1; i++) {
      |                  ^~
      |                  ;
a.cc:12:18: error: expected primary-expression before '<=' token
   12 |   for (int i=0, i<=N-1; i++) {
      |                  ^~
a.cc:16:23: error: 'i' was not declared in this scope
   16 |   for (int j; j<=K-1; i++){
      |                       ^
Language: C++

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

int main() {
	int n, k, sum;
	cin >> n >> k;
	int a[50];
	for (int i = 0;i < n;i++)cin >> a[i];
	for (int i = 0;i < n-k;i++) {
		int a = sum;
		for (int j;j < k;j++) {
			sum += a[i + j];
		}
		sum = max(sum, a);
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:33: error: invalid types 'int[int]' for array subscript
   13 |                         sum += a[i + j];
      |                                 ^
Language: C++

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int a[100000];
    int n,m,total=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>=n-m+1;i--)
    total+=a[i];
    cout<<total;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'cin' was not declared in this scope
   11 |     cin>>n>>m;
      |     ^~~
a.cc:6:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #include<cstring>
  +++ |+#include <iostream>
    6 | using namespace std;
a.cc:17:5: error: 'cout' was not declared in this scope
   17 |     cout<<total;
      |     ^~~~
a.cc:17:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int a[100000];
int main()
{
    int n,m,total=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>=n-m+1;i--)
    total+=a[i];
    cout<<total;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'cin' was not declared in this scope
   11 |     cin>>n>>m;
      |     ^~~
a.cc:6:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #include<cstring>
  +++ |+#include <iostream>
    6 | using namespace std;
a.cc:17:5: error: 'cout' was not declared in this scope
   17 |     cout<<total;
      |     ^~~~
a.cc:17:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

#include<bits/stdc++.h>
using namespace std;
int sum;
inline int read(){
    int f=1,x=0;
    char ch;
    do{
        ch=getchar();
        if(ch=='-'){
            f=-1;
        }
    }while(ch<'0'||ch>'9');
    do{
        x=x*10+ch-48;
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
inline int cmp(int a,int b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    vector<int> v;
    int n=read(),h=read();
    for(int i=0;i<n;++i){
        int temp=read();
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<h;++i){
        sum+=v[i];
    }
    print(sum);
    putchar('\n');
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:5: error: 'print' was not declared in this scope; did you mean 'rint'?
   38 |     print(sum);
      |     ^~~~~
      |     rint
Language: C

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


int main(int argc, char *argv[]) {
    int n, k;
    int l[50];

    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", &l[i]);
    }

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

    for (int i = 0; i < n; i++) {
#        printf("%d\n", l[i]);
    }


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

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

    return 0;
}


Compiler output:
main.c: In function 'main':
main.c:26:10: error: invalid preprocessing directive #printf
   26 | #        printf("%d\n", l[i]);
      |          ^~~~~~
Language: C++

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

int main(){
  int N, K;
  cin >> N >> K;
  
  int l[60];
  for(int i = 0; i < N; i++){
    cin >> l[i];
  }
  
  sort(l, l+N, greater<int>());
  int total = 0;
  for(int i = 0; i < K; i++){
    int total += l[i];
  }
  
  cout << total << endl;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:17:15: error: expected initializer before '+=' token
   17 |     int total += l[i];
      |               ^~
Language: C

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

int main()
{
    int n, k, l [50];
    int sum = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++){
        cin >> l[i];
    }

    sort(l, l + n);
    reverse(l, l + n);

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

    cout << sum << endl;

    return (0);
}


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

#include <iostream>
using namespace std;

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int l[n];

  REP(i, n) {
    cin >> l[i];
  }

  sort(l, l + n);

  int sum = 0;
  REP(i, k) {
    sum += l[n - i - 1];
  }

  cout << sum << endl;
}

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

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

int main()
{
  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(), [](const int x, const int y) { return x > y; } );
  int sum = 0;
  for (int i = 0; i < K; ++i) sum += a[i];
  cout << sum << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:19: error: 'N' was not declared in this scope
    8 |   vector< int > a(N);
      |                   ^
a.cc:12:23: error: 'K' was not declared in this scope
   12 |   for (int i = 0; i < K; ++i) sum += a[i];
      |                       ^
Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N, K;
vector<ll> L;

signed main()
{
    cin >> N >> K;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        L.push_back(tmp);
    }
    sort(tmp.begin(), tmp.end(), greater<ll>());
    ll ans = 0;
    REP(i, K) { ans += L[i]; }
    printf("%lld\n", ans);

    return 0;
}


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

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

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

  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += l[N - i - 1];
  }
  cout << sum << endl;

  return 0;
}


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

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int K, N;
  cin >> N >> K;
  int l[N - 1];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &l[i]);
  }
  sort(l, l + N); // array

  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += l[N - i - 1];
  }
  cout << sum << endl;

  return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,N,K;
  vector<int> l(N)
  int total = 0;
  scanf("%d", &N);
  scanf("%d", &K);
 
  for(i=0;i<N;i++){
    //scanf("%d", &l[i]);
     cin >> l[i];
  }
  sort(l.begin(), l.end());
 
  for(i=0;i<N;i++){
    if(i>=N-K)total += l;
  }
  printf("%d", total);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: expected ',' or ';' before 'int'
    7 |   int total = 0;
      |   ^~~
a.cc:18:15: error: 'total' was not declared in this scope
   18 |     if(i>=N-K)total += l;
      |               ^~~~~
a.cc:20:16: error: 'total' was not declared in this scope
   20 |   printf("%d", total);
      |                ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,N,K;
  vector<int> l(N)
  int total = 0;
  scanf("%d", &N);
  scanf("%d", &K);
  //ｌを入力
  for(i=0;i<N;i++){
    scanf("%d", &l[i]);
  }
  sort(l.begin(), l.end());
  //昇順になった
  for(i=0;i<N;i++){
    if(i>=N-K)total += l;
  }
  printf("%d", total);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: expected ',' or ';' before 'int'
    7 |   int total = 0;
      |   ^~~
a.cc:17:15: error: 'total' was not declared in this scope
   17 |     if(i>=N-K)total += l;
      |               ^~~~~
a.cc:19:16: error: 'total' was not declared in this scope
   19 |   printf("%d", total);
      |                ^~~~~
Language: C++

#include <iostream>
#include <vector>
#include <numeric>

int main(int argc, char const *argv[]) {

    int N,K;
    std::cin >> N >> K;

    std::vector<int> snake_bodys;
    for(int times = 0 ; times < N ; times++ )
    {
        int snake_body_length;
        std::cin >> snake_body_length;
        snake_bodys.push_back(snake_body_length);
    }

    std::sort(snake_bodys.begin(),snake_bodys.end(),std::greater<int>());

    int snake_length = 0;
    snake_length = std::accumulate(snake_bodys.begin(), snake_bodys.begin()+K,0);

    std::cout << snake_length << '\n';

    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:18:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   18 |     std::sort(snake_bodys.begin(),snake_bodys.end(),std::greater<int>());
      |          ^~~~
      |          qsort
Language: C++

include<bits/stdc++.h>
using namespace std;
int n,k;
int l[51];
int main(){
    int ans=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+n);
    for(int i=n;i>=n-k;i--){
        ans+=l[i];
    }
    cout<<ans<<endl;
    return 0;

}


Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<bits/stdc++.h>
      | ^~~~~~~
a.cc: In function 'int main()':
a.cc:7:5: error: 'cin' was not declared in this scope
    7 |     cin>>n>>k;
      |     ^~~
a.cc:11:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   11 |     sort(l,l+n);
      |     ^~~~
      |     short
a.cc:15:5: error: 'cout' was not declared in this scope
   15 |     cout<<ans<<endl;
      |     ^~~~
a.cc:15:16: error: 'endl' was not declared in this scope
   15 |     cout<<ans<<endl;
      |                ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main()
{
    int n, k, v[105];
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> v[i];
    sort(v, v + n);
    int ans = 0, now = n - 1;
    while(k--)
    {
        ans += v[i];
        --now;
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:18: error: 'i' was not declared in this scope
   16 |         ans += v[i];
      |                  ^
Language: C++

#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vsort(x) sort(x.begin(),x.end())

using namespace std;

int main() {

	int i, j, k;
	int n, k;
	int l[50];
	cin >> n >> k;
	rep(i, 0, n)
		cin >> l[i];
	sort(l, l + n);
	int ans = 0;
	rep(i, 0, k) {
		ans += l[n - 1 - i];
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:16: error: redeclaration of 'int k'
   23 |         int n, k;
      |                ^
a.cc:22:19: note: 'int k' previously declared here
   22 |         int i, j, k;
      |                   ^
Language: C++

package Kadai;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Sort {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] x = br.readLine().split(" ");
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		String[] line = br.readLine().split(" ");
		int[] ia = new int[a];
		int c = 0;

		for (int i = 0; i < a; i++) {
			ia[i] = Integer.parseInt(line[i]);
		}

		Arrays.sort(ia);

		for (int i = a - 1; i < a + b; i--) {
			c = c + ia[i];
			System.out.println(c);
		}

		System.out.println(c);

	}

}

Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package Kadai;
      | ^~~~~~~
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.BufferedReader;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.io.InputStreamReader;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.Arrays;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: expected unqualified-id before 'public'
    7 | public class Sort {
      | ^~~~~~