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

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

void main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, m;
	cin >> n >> m;
	vector<ll> x(m);
	rep(i, m) cin >> x[i];

	if (n >= m) {
		cout << 0 << endl;
		return;
	}

	sort(allof(x));

	vector<ll> d(m - 1);
	Rep(i, 1, m) {
		d[i - 1] = x[i] - x[i - 1];
	}

	sort(allof(d), greater<ll>());

	ll ans = 0;
	rep(i, m - 1) {
		ans += d[i];
	}

	rep(i, n - 1) {
		ans -= d[i];
	}

	cout << ans << endl;
}

Compiler output:
a.cc:29:1: error: '::main' must return 'int'
   29 | void main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:40:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   40 |                 return;
      |                 ^~~~~~
Language: C++

N, M = map(int, input().split())
if N >= M:
  print(0)
  exit()

X = [int(x) for x in input().split()]

X = sorted(X)
L = [ X[i] - X[i-1] for i in range(1, M)]
L = sorted(L)
#print(X)
#print(L)

print(sum(L[:-(N-1)]))

Compiler output:
a.cc:11:2: error: invalid preprocessing directive #print
   11 | #print(X)
      |  ^~~~~
a.cc:12:2: error: invalid preprocessing directive #print
   12 | #print(L)
      |  ^~~~~
a.cc:1:1: error: 'N' does not name a type
    1 | N, M = map(int, input().split())
      | ^
Language: Java

import java.util.Arrays;
import java.util.Scanner;

public class Main

	public static void main(final String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int num = scanner.nextInt();
		final int point = scanner.nextInt();

		if (num >= point) {
			System.out.println(0);
			return;
		}

		final int[] points = new int[point];

		for (int i = 0; i < point; i++) {
			points[i] = scanner.nextInt();
		}

		int sum = 0;
		final int[] diffs = new int[point - 1];

		Arrays.sort(points);

		for (int i = 0; i < point - 1; i++) {
			final int diff = points[i + 1] - points[i];
			sum += diff;
			diffs[i] = diff;
		}

		Arrays.sort(diffs);

		int reducible = 0;

		for (int i = diffs.length - num + 1; i < diffs.length; i++) {
			reducible += diffs[i];
		}

		System.out.println(sum - reducible);
	}

}

Compiler output:
Main.java:4: error: '{' expected
public class Main
                 ^
Main.java:6: error: unnamed classes are a preview feature and are disabled by default.
	public static void main(final String[] args) {
	              ^
  (use --enable-preview to enable unnamed classes)
Main.java:44: error: class, interface, enum, or record expected
}
^
3 errors
Language: C

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

int n, m, x[100000], ans, sum, i;
int main(){
  scanf("%d%d", &n, &m);
  for(i=0; i<n; i++){
    scanf("%d", x+i);
  }
  qsort(x, n, sizeof(int), compare_int);
  sum=x[0]-[n-1];
  for(i=0; i<n-1; i++){
    x[i]=x[i]-x[i+1];
  }
  qsort(x, n-1, sizeof(int), compare_int);
  for(i=0; i<m; i++){
    ans+=x[i];
  }
  printf("%d\n", sum-ans);
}



Compiler output:
main.c: In function 'main':
main.c:7:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    7 |   scanf("%d%d", &n, &m);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int compare_int(const void *a, const void *b){
main.c:7:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    7 |   scanf("%d%d", &n, &m);
      |   ^~~~~
main.c:7:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:11:3: error: implicit declaration of function 'qsort' [-Wimplicit-function-declaration]
   11 |   qsort(x, n, sizeof(int), compare_int);
      |   ^~~~~
main.c:12:12: error: expected expression before '[' token
   12 |   sum=x[0]-[n-1];
      |            ^
main.c:20:3: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   20 |   printf("%d\n", sum-ans);
      |   ^~~~~~
main.c:20:3: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:20:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:20:3: note: include '<stdio.h>' or provide a declaration of 'printf'
Language: C++

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


int main(){
    int N, M;
    int X[10005];
    int diff[10005];
    cin >> N >> M;
    for (int i = 0; i < M; ++i) cin >> X[i];

    sort(X, X+M);a
    for (int i = 0; i < M-1; ++i) diff[i] = X[i+1] - X[i];
    sort(diff, diff+(M-1));
    
    int ans = 0;
    for (int i = 0; i < M-N; ++i) ans += diff[i];    
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:18: error: 'a' was not declared in this scope
   13 |     sort(X, X+M);a
      |                  ^
a.cc:14:21: error: 'i' was not declared in this scope
   14 |     for (int i = 0; i < M-1; ++i) diff[i] = X[i+1] - X[i];
      |                     ^
Language: C++

#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<string>
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#define LL long long
using namespace std;
#define INF 1000000000
//1171201016　稲村佑哉 改行文字の処理に手間取った
vector<string> v;



LL N,M,x[100000],xx[100000],ans;

int main() {
  
	cin>>N>>M;
	
	for(int i=0;i<M;i++){
		cin>>x[i];
	}
	if(N>M){
		cout<<0<<endl;
		return 0;
	}
	sort(x,x+M);
	for(int i=0;i<M-1;i++){
		xx[i]=x[i+1]-x[i];
	}

	sort(xx,xx+(M-1));

	for(int i=M-2;i>(M-2)-(N-1);i--){
		ans+=xx[i];
	}

	cout<<(x[M-1]-x[0])-ans<<endl;

	return 0;
}

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

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int n_max = 100000;
int n,m,x[n_max+10],l[n_max+10];

int main(){
  cin>>n>>m;
  rep(i,m)cin>>x[i];

  if ( n>=m){
    cout << 0 << endl;
    return 0;
  }

  sort(x,x+m);

  for(int i=1;i<m;i++){
    l[i-1] = x[i]-x[i-1];
  }

  sort(l,l+m-1);

  int sum = 0;
  for(int i=m-1-1;i > m-n-1;i--){
    sum += l[i];
  }
  cout << ((x[m-1]-x[0]) - sum) << endl;
  
}

Compiler output:
a.cc:14:16: error: size of array 'x' is not an integral constant-expression
   14 | int n,m,x[n_max+10],l[n_max+10];
      |           ~~~~~^~~
a.cc:14:28: error: size of array 'l' is not an integral constant-expression
   14 | int n,m,x[n_max+10],l[n_max+10];
      |                       ~~~~~^~~
Language: C

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

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

int main(void){
  int n,m,i,high,memo,j,count;
  count=0;
  while(scanf("%d",&n)!=1);
  while(scanf("%d",&m)!=1);
  int array[m];
  int piece[n+2];
  for(i=0;i<m;i++){
    while(scanf("%d",&array[i])!=1);
  }
  if(m<n){
    printf("0\n");
    return 0;
  }
  qsort(array,m,sizeof(int),asc);
  int diff[m-1];
  for(i=0;i<m-1;i++){
    diff[i]=array[i+1]-array[i];
  }
  for(j=2;j<n+1;j++){
    high=diff[0];
    memo=0;
    for(i=0;i<m-1;i++){
      if(high<diff[i]){
        memo=i;
        high=diff[i];
      }
    }
    diff[memo]=0;
    piece[j]=memo+1;
  }
  piece[0]=0;
  piece[1]=piece[2]-1;
  piece[n+1]=m-1;
    if(piece[0]==piece[1]){
      continue;
    }else{
      count+=array[piece[1]]-array[piece[0]];
    }
    if(piece[n]+1==piece[n+1]){
      continue;
    }else if(piece[n]==piece[n+1]){
      continue;
    }else{
      count+=array[piece[n+1]]-array[piece[n]];
  }
  for(i=1;i<n;i++){
      if(piece[i]+1==piece[i+1]){
        continue;
      }else if(piece[i]==piece[i+1]){
        continue;
      }else{
        count+=array[piece[i+1]-1]-array[piece[i]];
      }
    }
  printf("%d\n",count);
  return 0;
}


Compiler output:
main.c: In function 'main':
main.c:43:7: error: continue statement not within a loop
   43 |       continue;
      |       ^~~~~~~~
main.c:48:7: error: continue statement not within a loop
   48 |       continue;
      |       ^~~~~~~~
main.c:50:7: error: continue statement not within a loop
   50 |       continue;
      |       ^~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    ll n,m;
    ll x[m];

    ll length = 0;
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x,x+m);
    ll difference[m-1];
    for(int i = 0; i < m-2; i++){
        difference[i] = x[i+1]-x[i];
    }
    sort(difference, difference + m-1);
    for(int i = 0; i < n-1; i++){
        sum += difference[m-2-i];
    }
    cout << sum << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:9: error: 'sum' was not declared in this scope
   27 |         sum += difference[m-2-i];
      |         ^~~
a.cc:29:13: error: 'sum' was not declared in this scope
   29 |     cout << sum << endl;
      |             ^~~
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n,m,x[100005],a[100005],s;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    fort (i,m)
        cin >> x[i];
    sort (x+1,x+m+1);
    fort (i,m-1)
        a[i]=x[i+1]-x[i], s+=a[i];
    sort (a+1,a+m);
    fort (i,n-1)
        s-=a[m-i];
    cout << max(s,0);
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:30:16: error: no matching function for call to 'max(long long int&, int)'
   30 |     cout << max(s,0);
      |             ~~~^~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:30:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |     cout << max(s,0);
      |             ~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:30:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |     cout << max(s,0);
      |             ~~~^~~~~
Language: C++

#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <memory>
#include <sstream>

#include <limits.h>

using namespace std;

class Hoge
{

public:
  int add(int a, int b)
  {
    return a + b;
  }

  static void ABC117B()
  {
    int n;
    cin >> n;

    int j;
    int max = 0;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
      cin >> j;
      max = max < j ? j : max;
      sum += j;
    }

    sum = sum - max;
    if (max < sum)
    {
      cout << "Yes";
    }
    else
    {
      cout << "No";
    }

    return;
  }

  static void ABC117C()
  {
    int n, m, t;
    std::vector<int> x;
    cin >> n;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
      cin >> t;
      x.push_back(t);
    }
    std::sort(x.begin(), x.end());

    // cerr << "started n: " << n << ", m: " << m << endl;
    int result = ABC117C_sub(n, m, 0, x);
    cout << result;
    return;
  }

  static int ABC117C_sub(int n, int m, int idx, std::vector<int> &x)
  {
    if (m <= n)
    {
      return 0;
    }
    else
    {
      int minSteps = 1000000;
      for (int i = 0; i < m - 1; i++)
      {
        int stepsLeft = std::abs(x[idx + i] - x[idx]);
        if (stepsLeft >= minSteps)
        {
          break;
        }
        int stepsRight = 0;
        if (n > 1)
        {
          stepsRight = ABC117C_sub(n - 1, m, idx + i + 1, x);
        }
        else
        {
          stepsRight = std::abs(x[m - 1] - x[idx + i]);
        }
        int steps = stepsLeft + stepsRight;
        minSteps = std::min(minSteps, steps);
        //cerr << "n: " << n << ", m: " << m << ", idx: " << idx;
        //cerr << ", minSteps: " << minSteps << ", left:" << stepsLeft << ", right: " << stepsRight << endl;
      }
      return minSteps;
    }
  }
};
int main(int argc, char const *argv[])
{
    Hoge::ABC117C() return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:105:20: error: expected ';' before 'return'
  105 |     Hoge::ABC117C() return 0;
      |                    ^~~~~~~
      |                    ;
Language: C++

#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int x[m];
  for(int i=0; i<m; i++){
    cin >> x[i];
  }
  sort(x, x+m);
  int min_x = n;
  for(int i=0; i<m-1; i++){
    min_x = min(min_x, x[i+1]-x[i]);
  }
  cout << n - m + min_x <<endl;
  return 0;
}

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

using namespace std;
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <memory>
#include <sstream>

#include <limits.h>

using namespace std;
class Hoge;

int main(int argc, char const *argv[])
{
  Hoge::ABC117C();
  return 0;
}

class Hoge
{

public:
  int add(int a, int b)
  {
    return a + b;
  }

  static void ABC117B()
  {
    int n;
    cin >> n;

    int j;
    int max = 0;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
      cin >> j;
      max = max < j ? j : max;
      sum += j;
    }

    sum = sum - max;
    if (max < sum)
    {
      cout << "Yes";
    }
    else
    {
      cout << "No";
    }

    return;
  }

  static void ABC117C()
  {
    int n, m, t;
    std::vector<int> x;
    cin >> n;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
      cin >> t;
      x.push_back(t);
    }
    std::sort(x.begin(), x.end());

    // cerr << "started n: " << n << ", m: " << m << endl;
    int result = ABC117C_sub(n, m, 0, x);
    cout << result;
    return;
  }

  static int ABC117C_sub(int n, int m, int idx, std::vector<int> &x)
  {
    if (m <= n)
    {
      return 0;
    }
    else
    {
      int minSteps = 1000000;
      for (int i = 0; i < m - 1; i++)
      {
        int stepsLeft = std::abs(x[idx + i] - x[idx]);
        if (stepsLeft >= minSteps)
        {
          break;
        }
        int stepsRight = 0;
        if (n > 1)
        {
          stepsRight = ABC117C_sub(n - 1, m, idx + i + 1, x);
        }
        else
        {
          stepsRight = std::abs(x[m - 1] - x[idx + i]);
        }
        int steps = stepsLeft + stepsRight;
        minSteps = std::min(minSteps, steps);
        //cerr << "n: " << n << ", m: " << m << ", idx: " << idx;
        //cerr << ", minSteps: " << minSteps << ", left:" << stepsLeft << ", right: " << stepsRight << endl;
      }
      return minSteps;
    }
  }
};

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:17:9: error: incomplete type 'Hoge' used in nested name specifier
   17 |   Hoge::ABC117C();
      |         ^~~~~~~
Language: C++

using namespace std;
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <memory>
#include <sstream>

#include <limits.h>
#include "hoge.cpp"

using namespace std;
class Hoge;

int main(int argc, char const *argv[])
{
  Hoge::ABC117C();
  return 0;
}

class Hoge
{

public:
  int add(int a, int b)
  {
    return a + b;
  }

  static void ABC117B()
  {
    int n;
    cin >> n;

    int j;
    int max = 0;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
      cin >> j;
      max = max < j ? j : max;
      sum += j;
    }

    sum = sum - max;
    if (max < sum)
    {
      cout << "Yes";
    }
    else
    {
      cout << "No";
    }

    return;
  }

  static void ABC117C()
  {
    int n, m, t;
    std::vector<int> x;
    cin >> n;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
      cin >> t;
      x.push_back(t);
    }
    std::sort(x.begin(), x.end());

    // cerr << "started n: " << n << ", m: " << m << endl;
    int result = ABC117C_sub(n, m, 0, x);
    cout << result;
    return;
  }

  static int ABC117C_sub(int n, int m, int idx, std::vector<int> &x)
  {
    if (m <= n)
    {
      return 0;
    }
    else
    {
      int minSteps = 1000000;
      for (int i = 0; i < m - 1; i++)
      {
        int stepsLeft = std::abs(x[idx + i] - x[idx]);
        if (stepsLeft >= minSteps)
        {
          break;
        }
        int stepsRight = 0;
        if (n > 1)
        {
          stepsRight = ABC117C_sub(n - 1, m, idx + i + 1, x);
        }
        else
        {
          stepsRight = std::abs(x[m - 1] - x[idx + i]);
        }
        int steps = stepsLeft + stepsRight;
        minSteps = std::min(minSteps, steps);
        //cerr << "n: " << n << ", m: " << m << ", idx: " << idx;
        //cerr << ", minSteps: " << minSteps << ", left:" << stepsLeft << ", right: " << stepsRight << endl;
      }
      return minSteps;
    }
  }
};

Compiler output:
a.cc:11:10: fatal error: hoge.cpp: No such file or directory
   11 | #include "hoge.cpp"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <memory>
#include <sstream>

#include <limits.h>

using namespace std;
int ABC117C_sub(int n, int m, int idx, std::vector<int> &x);

int ABC117C_sub(int n, int m, int idx, std::vector<int> &x)
{
  if (m <= n)
  {
    return 0;
  }
  else
  {
    // loop 0+m-1, 0..1+m-2, ..., (m-2)+m-(m-1)
    int minSteps = 1000000;
    for (int i = 0; i < m - 1; i++)
    {
      int stepsLeft = std::abs(x[idx + i] - x[idx]);
      if (stepsLeft >= minSteps)
      {
        break;
      }
      int stepsRight = 0;
      if (n > 1)
      {
        stepsRight = Hoge::ABC117C_sub(n - 1, m, idx + i + 1, x);
      }
      else
      {
        stepsRight = std::abs(x[m - 1] - x[idx + i]);
      }
      int steps = stepsLeft + stepsRight;
      minSteps = std::min(minSteps, steps);
      //cerr << "n: " << n << ", m: " << m << ", idx: " << idx;
      //cerr << ", minSteps: " << minSteps << ", left:" << stepsLeft << ", right: " << stepsRight << endl;
    }
    return minSteps;
  }
}

int main(int argc, char const *argv[])
{
  int n, m, t;
  std::vector<int> x;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++)
  {
    cin >> t;
    x.push_back(t);
  }
  std::sort(x.begin(), x.end());

  //cerr << "started n: " << n << ", m: " << m << endl;
  int result = ABC117C_sub(n, m, 0, x);
  cout << result;
  return 0;
}


Compiler output:
a.cc: In function 'int ABC117C_sub(int, int, int, std::vector<int>&)':
a.cc:34:22: error: 'Hoge' has not been declared
   34 |         stepsRight = Hoge::ABC117C_sub(n - 1, m, idx + i + 1, x);
      |                      ^~~~
Language: C

#include <stdio.h>

void quicksort(int X[],int head,int tail);
void swap(int X[],int a,int b);

main(){
  int N,M; //コマ,座標の数
  int i; //カウンター
  scanf("%d%d",&N,&M);
  int X[M]; //座標の配列
  int D[M-1]; //隣り合う座標の差
  int A=0;
  
  if(N<M){ //N>=Mの時すべてのコマを座標上に置くことが出来るので0
    quicksort(X,0,M-1);
    for(i=0;i<M-1;i++){
      D[i] = X[i+1] - X[i];
    }
    quicksort(D,0,M-2);
    for(i=0;i<M-N;i++)
      A += X[i];
  }
  printf("%d\n",A);
  
  return 0;
}

void quicksort(int X[],int head,int tail){
  if(head>=tail) return;
  int pivot; //ピボット
  int tmphead,tmptail;
  int i; //カウンター
  tmphead = head;
  tmptail = tail;
  pivot = head;
  tmphead--; tmptail++;
  wihle(tmphead<tmptail){
    wihle(X[++tmphead]<=X[pivot]); 
    wihle(X[--tmptail]>=X[pivot]);
    swap(X,tmphead,tmptail);
  }
  swap(X,pivot,tmptail);
  quicksort(X,head,tmptail-1);
  quicksort(X,tmptail+1,tail);
}

void swap(int X[],int a,int b){
  int tmp;
  tmp = X[a];
  X[a] = X[b];
  X[b] = tmp;
}

Compiler output:
main.c:6:1: error: return type defaults to 'int' [-Wimplicit-int]
    6 | main(){
      | ^~~~
main.c: In function 'quicksort':
main.c:37:3: error: implicit declaration of function 'wihle' [-Wimplicit-function-declaration]
   37 |   wihle(tmphead<tmptail){
      |   ^~~~~
main.c:37:25: error: expected ';' before '{' token
   37 |   wihle(tmphead<tmptail){
      |                         ^
      |                         ;
Language: C++

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

#define MAX_M 100002

bool space_sort(const pair<int, int>& p1, const pair<int, int>& p2) {
	return p1.second > p2.second;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > v;
	int X[MAX_M] = {0};
	for (int i = 0; i < M; i++) {
		cin >> X[i];
	}
	if (N >= M) {
		cout << 0 << endl;
	} else {
		sort(X, X+M);

		v.push_back(make_pair(0, 0));

		for (int i = 1; i < M; i++) {
			int space = X[i]-X[i-1];
			v.push_back(make_pair(i, space));
		}

		sort(v.begin(), v.end(), space_sort);

		int remaining = N-1;
		bool position[MAX_M] = {true};

		for (int i = 0; i < M; i++) {
			int index = v[i].first;
			position[index] = true;
			remaining--;
			if (!remaining) {
				break;
			}
		}

		int index, before_index = 0;
		int sum = 0;
		for (index = 1; index < M; index++) {
			if (position[index]) {
				sum += X[index-1] - X[before_index];
				before_index = index;
			}
		}
		sum += X[index-1] - X[before_index];
		cout << sum << endl;
	}
}


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

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

int main(){
    int N,M;
    cin >> N >> M;
    if(N >= M){
        cout << 0 << endl;
        return 1;
    }
    vector<int> X(M);
    for(int i;i<M;i++){
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    vector<int> Y(M-1);
    for(int i=0;i<M-1;i++){
        Y[i] = X[i+1] - X[i];
    }
    sort(Y.begin(),Y.end());
    long long XX = X[X.size()-1] - X[0], sumY=0;
    for(int i=0;i<N-1;i++){
        sumY += Y[Y.size()-1-i];
    }
    cout << XX - sumY << endl;
}

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

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

int main(){
    int N,M;
    cin >> N >> M;
    if(N >= M){
        cout << 0 << endl;
        return 1;
    }
    vector<int> X(M);
    for(int i;i<M;i++){
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    vector<int> Y(M-1);
    for(int i=0;i<M-1;i++){
        Y[i] = X[i+1] - X[i];
    }
    sort(Y.begin(),Y.end());
    long long XX = X[X.size()-1] - X[0], sumY=0;
    for(int i=0;i<N-1;i++){
        sumY += Y[Y.size()-1-i];
    }
    cout << XX - sumY << endl;
}

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

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

int main(){
    int N,M;
    cin >> N >> M;
    if(N >= M){
        cout << 0 << endl;
        return 1;
    }
    vector<int> X(M);
    for(int i;i<M;i++){
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    vector<int> Y(M-1);
    for(int i=0;i<M-1;i++){
        Y[i] = X[i+1] - X[i];
    }
    sort(Y.begin(),Y.end());
    long long XX = X[X.size()-1] - X[0], sumY=0;
    for(int i=0;i<N-1;i++){
        sumY += Y[Y.size()-1-i];
    }
    cout << XX - sumY << endl;
}

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

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

int main(){
    int N,M;
    cin >> N >> M;
    if(N >= M){
        cout << 0 << endl;
        return 1;
    }
    vector<int> X(M);
    for(int i;i<M;i++){
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    vector<int> Y(M-1);
    for(int i=0;i<M-1;i++){
        Y[i] = X[i+1] - X[i];
        cout << Y[i] << " ";
    }
    sort(Y.begin(),Y.end());
    long long XX = X[X.size()-1] - X[0], sumY=0;
    cout << XX << endl;
    for(int i=0;i<N-1;i++){
        sumY += Y[Y.size()-1-i];
    }
    cout << XX - sumY << endl;
}

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

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

int cmp(int *a, int *b){
    return *a - *b;
}
int main(void)
{
    int i;
    int n, m;
    int *xs;
    int sum = 0;
    
    scanf("%d %d", &n, &m);
    
    xs = malloc(m * sizeof(int));
    
    for(i = 0; i < m, ++i){
        scanf("%d", &xs[i]);
    }
  
    qsort(xs, m, sizeof(int), cmp);
    
    for(i = m-1; i > 0, --i){
        xs[i] -= xs[i-1];  //1..m-1: distances
    }
    
    qsort(&xs[1], m-1, sizeof(int), cmp);
  
    for(i = 1; i <= m-n; ++i)
        sum += xs[i]; 
  
    printf("%d", sum);
  
    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:18:26: error: expected ';' before ')' token
   18 |     for(i = 0; i < m, ++i){
      |                          ^
      |                          ;
main.c:22:31: error: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
   22 |     qsort(xs, m, sizeof(int), cmp);
      |                               ^~~
      |                               |
      |                               int (*)(int *, int *)
In file included from main.c:2:
/usr/include/stdlib.h:971:34: note: expected '__compar_fn_t' {aka 'int (*)(const void *, const void *)'} but argument is of type 'int (*)(int *, int *)'
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~
main.c:24:28: error: expected ';' before ')' token
   24 |     for(i = m-1; i > 0, --i){
      |                            ^
      |                            ;
main.c:28:37: error: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
   28 |     qsort(&xs[1], m-1, sizeof(int), cmp);
      |                                     ^~~
      |                                     |
      |                                     int (*)(int *, int *)
/usr/include/stdlib.h:971:34: note: expected '__compar_fn_t' {aka 'int (*)(const void *, const void *)'} but argument is of type 'int (*)(int *, int *)'
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~
Language: C++

#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) sort(a.rbegin(),a.rend())
#define Sort(a) sort(a.begin(),a.end())
#define Sum(a)  accumulate(a.begin(), a.end(), 0)
#define rep(i,n) for(UI i=0;i<n;i++)

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

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M;
	LL calc = 0;
	LL sum = 0;

	cin >> N >> M;

	vector<LL>X((UI)M);

	rep(i, M) {
		cin >> X[i];
	}

	Sort(X);
	vector<__int64>Y;

	for (UI i = 0; i< X.size() - 1; i++) {
		Y.push_back(X[i + 1] - X[i]);
		sum += Y[i];
	}

	rSort(Y);

	for (UI i = 0; i < N - 1; i++) {
		calc += Y[i]; // 除去する分
	}

	cout << sum - calc << endl;

	return 0;

}

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:50:16: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   50 |         vector<__int64>Y;
      |                ^~~~~~~
      |                __ynf64
a.cc:50:23: error: template argument 1 is invalid
   50 |         vector<__int64>Y;
      |                       ^
a.cc:50:23: error: template argument 2 is invalid
a.cc:53:19: error: request for member 'push_back' in 'Y', which is of non-class type 'int'
   53 |                 Y.push_back(X[i + 1] - X[i]);
      |                   ^~~~~~~~~
a.cc:54:25: error: invalid types 'int[UI {aka unsigned int}]' for array subscript
   54 |                 sum += Y[i];
      |                         ^
a.cc:27:25: error: request for member 'rbegin' in 'Y', which is of non-class type 'int'
   27 | #define rSort(a) sort(a.rbegin(),a.rend())
      |                         ^~~~~~
a.cc:57:9: note: in expansion of macro 'rSort'
   57 |         rSort(Y);
      |         ^~~~~
a.cc:27:36: error: request for member 'rend' in 'Y', which is of non-class type 'int'
   27 | #define rSort(a) sort(a.rbegin(),a.rend())
      |                                    ^~~~
a.cc:57:9: note: in expansion of macro 'rSort'
   57 |         rSort(Y);
      |         ^~~~~
a.cc:60:26: error: invalid types 'int[UI {aka unsigned int}]' for array subscript
   60 |                 calc += Y[i]; // 除去する分
      |                          ^
Language: C++

#include<stdio.h>
#include<algorithm>
#include<utility>

int main(void){

	int n, m, k, ans;

	int x[100000],sa[100000];

	scanf("%d %d",&n,&m);

	for (k = 0; k < m; k++) {
		if (k != m - 1) {
			scanf("%d ",&x[k]);
		}else{
			scanf("%d", &x[k]);
		}
	}
	
	sort(x,x+m);

	if (n >= m) {
		printf("0\n");
	}
	else {
		for (k = 0; k < m - 1; k++) {
			sa[k] = x[k + 1] - x[k];
		}
		sort(sa, sa + m);

		ans = x[m - 1] - x[0];

		for (k = 0; k < m;k++) {

			ans = ans - sa[m - 1 - k];
		}

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

	}


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:9: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   21 |         sort(x,x+m);
      |         ^~~~
      |         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);
      | ^~~~
Language: C++

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

using namespace std;

int main(void)
 int N, M;
 cin >> N >> M;
 vector<int> x(M);
 for(int i = 0; i < M; i++){
  cin >> x[i];
 }
 if(M <= N){
	 cout << 0 << endl;
	 return 0;
 }
 sort(x.begin(), x.end());
 vector<int> xsub(M-1);
 for(int i = 0; i < M-1; i++){
  xsub[i] = x[i+1] - x[i];
 }
 
 sort(xsub.begin(), xsub.end(), greater<int>());
 int length = x[M-1] - x[0];
 for(int i =0; i < N-1; i++){
  length -= xsub[i];
 }
 cout << length << endl;
 return 0;
}


Compiler output:
a.cc:8:2: error: expected initializer before 'int'
    8 |  int N, M;
      |  ^~~
a.cc:9:2: error: 'cin' does not name a type
    9 |  cin >> N >> M;
      |  ^~~
a.cc:10:16: error: 'M' was not declared in this scope
   10 |  vector<int> x(M);
      |                ^
a.cc:11:2: error: expected unqualified-id before 'for'
   11 |  for(int i = 0; i < M; i++){
      |  ^~~
a.cc:11:17: error: 'i' does not name a type
   11 |  for(int i = 0; i < M; i++){
      |                 ^
a.cc:11:24: error: 'i' does not name a type
   11 |  for(int i = 0; i < M; i++){
      |                        ^
a.cc:14:2: error: expected unqualified-id before 'if'
   14 |  if(M <= N){
      |  ^~
a.cc:18:6: error: expected constructor, destructor, or type conversion before '(' token
   18 |  sort(x.begin(), x.end());
      |      ^
a.cc:19:19: error: 'M' was not declared in this scope
   19 |  vector<int> xsub(M-1);
      |                   ^
a.cc:20:2: error: expected unqualified-id before 'for'
   20 |  for(int i = 0; i < M-1; i++){
      |  ^~~
a.cc:20:17: error: 'i' does not name a type
   20 |  for(int i = 0; i < M-1; i++){
      |                 ^
a.cc:20:26: error: 'i' does not name a type
   20 |  for(int i = 0; i < M-1; i++){
      |                          ^
a.cc:24:6: error: expected constructor, destructor, or type conversion before '(' token
   24 |  sort(xsub.begin(), xsub.end(), greater<int>());
      |      ^
a.cc:25:17: error: 'M' was not declared in this scope
   25 |  int length = x[M-1] - x[0];
      |                 ^
a.cc:26:2: error: expected unqualified-id before 'for'
   26 |  for(int i =0; i < N-1; i++){
      |  ^~~
a.cc:26:16: error: 'i' does not name a type
   26 |  for(int i =0; i < N-1; i++){
      |                ^
a.cc:26:25: error: 'i' does not name a type
   26 |  for(int i =0; i < N-1; i++){
      |                         ^
a.cc:29:2: error: 'cout' does not name a type
   29 |  cout << length << endl;
      |  ^~~~
a.cc:30:2: error: expected unqualified-id before 'return'
   30 |  return 0;
      |  ^~~~~~
a.cc:31:1: error: expected declaration before '}' token
   31 | }
      | ^
Language: C++

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

using namespace std;

int main(void)
{
 int N, M;
 cin >> N >> M;
 vector<int> x(M);
 for(int i = 0; i < M; i++){
  cin >> x[i];
 }
 
 vector<int> xsub(M-1);
 for(int i = 0; i < M-1; i++){
  xsub[i] = x[i+1] - x[i];
 }
 
 sort(xsub.begin(), xsub.end(), greater<int>());
 sort(x.begin(), x.end())
 int length = x[M-1] - x[0];
 for(int i =0; i < N-1; i++){
  length -= xsub[i];
 }
 cout << length << endl;
 return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:26: error: expected ';' before 'int'
   22 |  sort(x.begin(), x.end())
      |                          ^
      |                          ;
   23 |  int length = x[M-1] - x[0];
      |  ~~~                      
a.cc:25:3: error: 'length' was not declared in this scope
   25 |   length -= xsub[i];
      |   ^~~~~~
a.cc:27:10: error: 'length' was not declared in this scope
   27 |  cout << length << endl;
      |          ^~~~~~
Language: C++

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

using namespace std;

int main(void)
{
 int N, M;
 cin >> N >> M;
 vector<int> x(M);
 for(int i = 0; i < M; i++){
  cin >> x[i];
 }
 
 vector<int> xsub(M-1);
 for(int i = 0; i < M-1; i++){
  xsub[i] = x[i+1] - x[i];
 }
 
 sort(xsub.begin(), xsub.end(), greater<int>);
 sort(x.begin(), x.end())
 int length = x[M-1] - x[0];
 for(int i =0; i < N-1; i++){
  length -= xsub[i];
 }
 cout << length << endl;
 return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:45: error: expected primary-expression before ')' token
   21 |  sort(xsub.begin(), xsub.end(), greater<int>);
      |                                             ^
a.cc:22:26: error: expected ';' before 'int'
   22 |  sort(x.begin(), x.end())
      |                          ^
      |                          ;
   23 |  int length = x[M-1] - x[0];
      |  ~~~                      
a.cc:25:3: error: 'length' was not declared in this scope
   25 |   length -= xsub[i];
      |   ^~~~~~
a.cc:27:10: error: 'length' was not declared in this scope
   27 |  cout << length << endl;
      |          ^~~~~~
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 M = sc.nextInt();
        int[] xArr = new int[M];
        for (int i = 0; i < M; i++) {
            xArr[i] = sc.nextInt();
        } 
        Arrays.sort(xArr);
        int[] diff = new int[M - 1];
        for (int i = 0; i < M - 1; i++) {
            diff[i] = xArr[i + 1] - xArr[i];
        }
        Arrays.sort(diff);
        int minSum = 0;
        for (int i = 0; i < M - N; i++) {
            minSum += diff[i];
        }
        return minSum;
    }
}

Compiler output:
Main.java:22: error: incompatible types: unexpected return value
        return minSum;
               ^
1 error
Language: C

#include<stdio.h>
#include <utility>
int main(void){

	int k, m, n, l;

	int x[100000];
	int sa[100000];
	int ans;

	scanf("%d %d",&n,&m);

	for (k = 1; k <= m; k++) {
		if (k != m) {
			scanf("%d ", &x[k]);
		}
		else {
			scanf("%d", &x[k]);
		}
		for (l = 1;l < k; l++) {
			if (x[k] < x[l]) {
				std::swap(x[k], x[l]);
			}
		}
	}

	for (k = 2; k <= m; k++) {
		
		sa[k] = x[k] - x[k - 1];

		for (l = 2; l < k; l++) {

			if (sa[k] < sa[l]) {
				std::swap(sa[k], sa[l]);
			}

		}
	}

	ans = x[m] - x[1];

	for (k = 0; k <= n - 2; k++) {
		ans = ans - sa[m - k];
	}

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

/*	for (k = 1; k <= m; k++) {
		printf("%d\n", x[k]);
	}

	for (k = 2; k <= m; k++) {
		printf("%d\n",sa[k]);
	}*/
	return 0;
}

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

#include<stdio.h>
#include <iostream>
#include <utility>
int main(void){

	int k, m, n, l;

	int x[100000];
	int sa[100000];
	int ans;

	scanf("%d %d",&n,&m);

	for (k = 1; k <= m; k++) {
		if (k != m) {
			scanf("%d ", &x[k]);
		}
		else {
			scanf("%d", &x[k]);
		}
		for (l = 1;l < k; l++) {
			if (x[k] < x[l]) {
				std::swap(x[k], x[l]);
			}
		}
	}

	for (k = 2; k <= m; k++) {
		
		sa[k] = x[k] - x[k - 1];

		for (l = 2; l < k; l++) {

			if (sa[k] < sa[l]) {
				std::swap(sa[k], sa[l]);
			}

		}
	}

	ans = x[m] - x[1];

	for (k = 0; k <= n - 2; k++) {
		ans = ans - sa[m - k];
	}

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

/*	for (k = 1; k <= m; k++) {
		printf("%d\n", x[k]);
	}

	for (k = 2; k <= m; k++) {
		printf("%d\n",sa[k]);
	}*/
	return 0;
}

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

#include<stdio.h>
#include <iostream>
#include <utility>
int main(void){

	int k, m, n, l;

	int x[100000];
	int sa[100000];
	int ans;

	scanf("%d %d",&n,&m);

	for (k = 1; k <= m; k++) {
		if (k != m) {
			scanf("%d ", &x[k]);
		}
		else {
			scanf("%d", &x[k]);
		}
		for (l = 1;l < k; l++) {
			if (x[k] < x[l]) {
				std::swap(x[k],x[l])
			}
		}
	}

	for (k = 2; k <= m; k++) {
		
		sa[k] = x[k] - x[k - 1];

		for (l = 2; l < k; l++) {

			if (sa[k] < sa[l]) {
				std::swap(sa[k], sa[l])
			}

		}
	}

	ans = x[m] - x[1];

	for (k = 0; k <= n - 2; k++) {
		ans = ans - sa[m - k];
	}

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

/*	for (k = 1; k <= m; k++) {
		printf("%d\n", x[k]);
	}

	for (k = 2; k <= m; k++) {
		printf("%d\n",sa[k]);
	}*/
	return 0;
}

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

#include <iostream>
#include <algorithm>
 
int main(void) {
  int N, M;
  std::cin >> N >> M;
 
  std::vector<int> X(M);
  for (int i =0; i < M; i++) {
    std::cin >> X[i];
  }
 
  std::sort(X.begin(), X.end());
  int *dif = new int[M-1];
 
  int result = 0;
 
  for(int i = 0; i < M-1; i++) {
    dif[i] = X[i] - X[i+1];
  }
  for(int i=0; i<M-N; i++) {
    result+= dif[i];
  }
  std::cout << result;
  delete[] dif;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:8: error: 'vector' is not a member of 'std'
    8 |   std::vector<int> X(M);
      |        ^~~~~~
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:8:15: error: expected primary-expression before 'int'
    8 |   std::vector<int> X(M);
      |               ^~~
a.cc:10:17: error: 'X' was not declared in this scope
   10 |     std::cin >> X[i];
      |                 ^
a.cc:13:13: error: 'X' was not declared in this scope
   13 |   std::sort(X.begin(), X.end());
      |             ^
Language: C++

#include <iostream>
#include <algorithm>

int main(void) {
  int N, M;
  std::cin >> N >> M;

  vector<int> X(M);
  for (int i =0; i < M; i++) {
    std::cin >> X[i];
  }

  std::sort(X.begin(), X.end());
  int *dif = new int[M-1];

  int result = 0;

  for(int i = 0; I < M-1; i++) {
    dif[i] = X[i] - X[i+1];
  }
  for(int i=0; i<M-N; i++) {
    result+= dif[i];
  }
  std::cout << result;
  delete[] dif;
  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> X(M);
      |   ^~~~~~
a.cc:8:10: error: expected primary-expression before 'int'
    8 |   vector<int> X(M);
      |          ^~~
a.cc:10:17: error: 'X' was not declared in this scope
   10 |     std::cin >> X[i];
      |                 ^
a.cc:13:13: error: 'X' was not declared in this scope
   13 |   std::sort(X.begin(), X.end());
      |             ^
a.cc:18:18: error: 'I' was not declared in this scope
   18 |   for(int i = 0; I < M-1; i++) {
      |                  ^
Language: Java

Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] X = new int[M];
        for(int i = 0; i < M; i++) {
            X[i] = sc.nextInt();
        }
        
        Arrays.sort(X);
        int[] Y = new int[M-1];
        for(int i = 0; i < M-1; i++) {
            Y[i] = X[i+1] - X[i];
            //System.out.println(Y[i] +"="+ X[i+1] +"-"+ X[i]);
        }
        Arrays.sort(Y);
        int ans = 0;
        for(int i = 0; i < (M-1)-(N-1); i++) {
            ans += Y[i];
        }
        System.out.println(ans);

Compiler output:
Main.java:1: error: unnamed classes are a preview feature and are disabled by default.
Scanner sc = new Scanner(System.in);
^
  (use --enable-preview to enable unnamed classes)
Main.java:5: error: class, interface, enum, or record expected
        for(int i = 0; i < M; i++) {
        ^
Main.java:5: error: class, interface, enum, or record expected
        for(int i = 0; i < M; i++) {
                       ^
Main.java:5: error: class, interface, enum, or record expected
        for(int i = 0; i < M; i++) {
                              ^
Main.java:7: error: class, interface, enum, or record expected
        }
        ^
Main.java:11: error: class, interface, enum, or record expected
        for(int i = 0; i < M-1; i++) {
        ^
Main.java:11: error: class, interface, enum, or record expected
        for(int i = 0; i < M-1; i++) {
                       ^
Main.java:11: error: class, interface, enum, or record expected
        for(int i = 0; i < M-1; i++) {
                                ^
Main.java:14: error: class, interface, enum, or record expected
        }
        ^
Main.java:17: error: class, interface, enum, or record expected
        for(int i = 0; i < (M-1)-(N-1); i++) {
        ^
Main.java:17: error: class, interface, enum, or record expected
        for(int i = 0; i < (M-1)-(N-1); i++) {
                       ^
Main.java:17: error: class, interface, enum, or record expected
        for(int i = 0; i < (M-1)-(N-1); i++) {
                                        ^
Main.java:19: error: class, interface, enum, or record expected
        }
        ^
13 errors
Language: C++

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

int main()
{
    int N, M; cin >> N >> M;
    int X[M]{};
    int distance[M - 1]{};
    
    for(int i = 0; i < N; i++)
    {
        cin >> X[i];
    }

    if(N <= M)
    {
        cout << 0 << endl;
        return 0;
    }

    sort(X.begin(), X.end());
    
    for(int i = 0; i < M - 1; i++)
    {
        distance[i] = X[i + 1] - X[i];
    }

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

    int len = X[M - 1] - X[0];

    for(int i = 0; i < N - 1; i++)
    {
        len -= distance[M - 1 - i];
    }
    cout << len << endl;
    return 0;
}

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

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

int main() {
  int N, M; cin >> N >> M;
  if (M == 1) cout << 0 << endl;
  else if (N >= M) cout << 0 << endl;
  else {
    int X[M]; for (i = 0; i < M; ++i) cin >> X[i];
    sort(X, X + M);
    int dif[M - 1];
    for (i = 0; i < M - 1; ++i) dif[i] = X[i + 1] - X[i];
    sort(dif, dif + M - 1, greater<int>());
    int mov_count = X[M - 1] - X[0];
    for (i = 0; i < N - 1; ++i) {
      mov_count = mov_count - dif[i];
    }
    cout << mov_count << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:20: error: 'i' was not declared in this scope
   10 |     int X[M]; for (i = 0; i < M; ++i) cin >> X[i];
      |                    ^
a.cc:13:10: error: 'i' was not declared in this scope
   13 |     for (i = 0; i < M - 1; ++i) dif[i] = X[i + 1] - X[i];
      |          ^
a.cc:16:10: error: 'i' was not declared in this scope
   16 |     for (i = 0; i < N - 1; ++i) {
      |          ^
Language: C++

#include <iostream>
#include <vector>

using namespace std;

struct distandindex{
    int dist;
    int index;
};

bool cmp(const distandindex &a, const distandindex &b){
    return a.dist > b.dist;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> x(M);
    for(int i=0;i<M;i++){
        cin >> x[i];
    }
    std::sort(x.begin(), x.end());
    // for(int i=0;i<M;i++){
    //     cout << x[i] << endl;
    // }

    if(M == 1){
        cout << 0 << endl;
        return 0;
    }
    vector<distandindex> kaisa(M-1);
    for(int i=0; i<M-1;i++){
        distandindex d = {x[i+1]-x[i], i};
        kaisa[i] = d;
    }
    std::sort(kaisa.begin(), kaisa.end(), cmp);
    // for(int i=0; i<M-1;i++){
    //     cout << kaisa[i].dist << " " << kaisa[i].index << endl;
    // }

    vector<int> index(N-1);
    for(int i=0;i<N-1;i++){
        index[i] = kaisa[i].index;
    }
    // for(int i=0;i<N-1;i++){
    //     cout << index[i] << endl;
    // }
    int start = 0;
    int sum = 0;
    for(int i = 0; i<N-1;i++){
        sum += x[index[i]] - x[start];
        start = index[i] + 1;
    }
    sum += x[M-1] - x[start];
    cout << sum << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   22 |     std::sort(x.begin(), x.end());
      |          ^~~~
      |          qsort
a.cc:36:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   36 |     std::sort(kaisa.begin(), kaisa.end(), cmp);
      |          ^~~~
      |          qsort