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

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

using namespace std;

int main(){

    int N = 0;
    int M = 0;
    int in = 0;
    cin >> N >> M;

    if(N >= M){
        std::cout << "0" << std::endl;
        return;
    }

    std::vector<int> X(M,0);

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

    std::sort(X.begin(), X.end());

    std::vector<int> sa(M-1,0);

    for(int i = 1; i < M; i++){
        sa[i - 1] = X[i] - X[i-1];
        std::cout << sa[i - 1] << " ";
    }
    std::cout << std::endl;

    std::sort(sa.begin(), sa.end());

    int total = 0;
    for(int i = 0; i < (M - 1) - (N - 1); i++){
        total += sa[i];
    }

    std::cout << total << std::endl;


}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
   16 |         return;
      |         ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  sort(X.begin(), X.end());

  for(int i = 0; i < M; i++){
    cin >> X.at(i);
  }

  int ans;
  
  vector<int> dis;
  for(int i = 0; i < M-1; i++){
    dis.puxh_back(X.at(i+1) - X.at(i));
  }
  
  ans = X.at(M-1) - X.at(0);
  
  sort(dis.begin(), dis.end());
  reverse(dis.begin(), dis.end());
  
  for(int i = 0; i < N-1; i++){
    ans -= dis.at(i);
  }

  if(N >= M) ans = 0;

  cout << ans << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:9: error: 'class std::vector<int>' has no member named 'puxh_back'; did you mean 'push_back'?
   17 |     dis.puxh_back(X.at(i+1) - X.at(i));
      |         ^~~~~~~~~
      |         push_back
Language: C++

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

int main(void){
	int N, M;
  	std::cin >> N >> M;
  
	if(M == 1 || N >= M) std::cout << 0; 
  
  	std::vector<int> zahyou;
  	zahyou.resize(M);
  	
  	for(int i = 0; i < M; i++){
    	std::cin >> zahyou[i];
    }
  
  	std::sort(zahyou.begin(), zahyou.end());
  	std::vector<int> distance;
  	distance.resize(M-1);
  	
  	for(int i = 0; i < M-1; i++){
    	distance[i] = std::abs(zahyou[i]-zahyou[i+1]);
    }
  	
  	std::sort(distance.begin(), distance.end());
  
  	count = 0;
  	for(int i = 0; i < distance.size()-N; i++){
    	count += distance[i];
    }
  
  	std::cout << count;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:9: error: 'count' was not declared in this scope; did you mean 'std::count'?
   29 |         count = 0;
      |         ^~~~~
      |         std::count
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:4:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: 'std::count' declared here
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // n:コマの個数
    // m:全座標の個数

    int n, m;
    cin >> n >> m;
    vector<int> x(m);

    //配列宣言 vecter<型名>　変数名(要素数);

    for(int i=0; i<m; ++i)
        cin >> x[i];
    sort(x.begin(), x.end());

    sort 
 
    vector<int> v(m-1);
    for(int i=0; i<m-1; ++i){
        v[i] = x[i+1] - x[i];
    sort(v.begin(), v.end());
    }
 
    long long ans = 0;
    for(int i=0; i<m-n; ++i){
        ans += v[i];
    cout << ans << endl;
    }
 
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:9: error: expected ';' before 'vector'
   19 |     sort
      |         ^
      |         ;
   20 | 
   21 |     vector<int> v(m-1);
      |     ~~~~~~
a.cc:21:23: error: statement cannot resolve address of overloaded function
   21 |     vector<int> v(m-1);
      |                       ^
a.cc:23:9: error: 'v' was not declared in this scope
   23 |         v[i] = x[i+1] - x[i];
      |         ^
a.cc:29:16: error: 'v' was not declared in this scope
   29 |         ans += v[i];
      |                ^
Language: C++

#include<iostream>

using namespace std;

int main(){
    int N;
    int M;

    int goal[100000];
    int i;
    cin>>N>>M;
    int sum=0;
    for(i=0;i<M;i++){
        cin>>goal[i];
        sum+=goal[i];
    }
    sort(goal,goal+M);
    int adjacent_length[100000];
    for(i=0;i<M-1;i++){
        adjacent_length[i]=goal[i+1]-goal[i];
    }
    sort(adjacent_length,adjacent_length+M-1);
    int answer;
    for(i=0;i<M-1;i++){
        cout<<adjacent_length[i]<<endl;
    }
    for(i=0;i<M-N;i++){
        //cout<<adjacent_length[i]<<endl;
        answer+=adjacent_length[i];
    }
    cout<<answer<<endl;
}

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

#include<iostream>

using namespace std;

int main(){
    int N;
    int M;

    int goal[100000];
    int i;
    cin>>N>>M;
    int sum=0;
    for(i=0;i<M;i++){
        cin>>goal[i];
        sum+=goal[i];
    }
    sort(goal[0],goal[M-1]);
    int adjacent_length[100000];
    for(i=0;i<M-1;i++){
        adjacent_length[i]=goal[i+1]-goal[i];
    }
    sort(adjacent_length[0],adjacent_length[M-1]);
    int answer;
    for(i=M-1;i>N-1;i--){
        answer+=adjacent_length[i];
    }
    cout<<answer<<endl;
}

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

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


using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> vec(m);
  for(int i=0;i<m;i++){
    cin >> x[i];
  }
  if(n>=m){
    cout << 0 << endl;
    return 0;
  }
  sort(vec.begin(),vec.end());
  vector<int> diff(m-1);
  for(int i=0;i<m-1;i++){
    diff[i] = vec[i+1] - vec[i];
  }
  sort(diff.begin(),diff.end());
  
  cout << accumulate(diff.begin(),diff.end(),0) - accumulate(diff.begin(),diff.begin()+n-1,0) << endl;
  
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:12: error: 'x' was not declared in this scope
   13 |     cin >> x[i];
      |            ^
a.cc:26:11: error: 'accumulate' was not declared in this scope
   26 |   cout << accumulate(diff.begin(),diff.end(),0) - accumulate(diff.begin(),diff.begin()+n-1,0) << endl;
      |           ^~~~~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;
using ll = long long int;

ll calc(vector<int> x, int l, int r)
{
  if(l >= r) return 0;
  ll result = 0;
  for(int i = l + 1; i < r; i++)
  {
    if(x[i] - x[l] <= x[r] - x[i])
    {
      result += x[i] - x[i - 1];
      l++;
    }  
  }
  for(int i = r - 1; i > l; i--)
  {
    if(x[i] - x[l] > x[r] - x[i])
    {
      result += x[i + 1] - x[i];
      r--;
    }  
  }
  return result;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<ll> x(m, 0);
  for(int i = 0; i < m; i++)
  {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  /*for(auto e : x)
  {
    cout << e << " ";
  }
  cout << endl;*/
  int l = 0;
  int r = m - 1;
  ll result = 0;
  if(n < 2)
  {
    for(int i = 1; i < m; i++)
    {
      result += x[i] - x[i - 1];
    }
  }else if(n >= m){
    result = 0;
  }else{
    for(int i = 2; i < n; i++)
    {
      ll templ = x[l + 1] - x[l];
      ll tempr = x[r] - x[r - 1];
      if(templ < tempr)
      {
        r--;
      }else{
        l++;
      }
    }
    //cout << l << " " << r << endl;
    result = calc(x, l, r);
  }
  cout << result << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:19: error: could not convert 'x' from 'vector<long long int>' to 'vector<int>'
   73 |     result = calc(x, l, r);
      |                   ^
      |                   |
      |                   vector<long long int>
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;
using ll = long long int;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> x(m, 0);
  for(int i = 0; i < m; i++)
  {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  /*for(auto e : x)
  {
    cout << e << " ";
  }
  cout << endl;*/
  int l = 0;
  int r = m - 1;
  ll result = 0;
  if(n < 2)
  {
    for(int i = 1; i < m; i++)
    {
      result += x[i] - x[i - 1];
    }
  }else if(n >= m){
    result = 0;
  }else{
    for(int i = 2; i < n; i++)
    {
      ll templ = x[l + 1] - x[l];
      ll tempr = x[r] - x[r - 1];
      if(templ < tempr)
      {
        r--;
      }else{
        l++;
      }
    }
    //cout << l << " " << r << endl;
    result = calc(x, l, r);
  }
  cout << result << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:50:14: error: 'calc' was not declared in this scope
   50 |     result = calc(x, l, r);
      |              ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x;
  cin>>n>>m;
  if(m>=n){cout<<0;return 0;}
  vector<int> x(m),y(m-1);
  for(int i=0;i<n;++i)cin>>x[i];
  sort(x.begin(),x.end());
  for(int i=0;i<n-1;++i)y[i]=x[i+1]-x[i];
  for(int i=1;i<n;++i)y[i]+=y[i-1];
  sort(y.begin(),y.end(),greater());
  cout<<y[n-1];
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:15: error: conflicting declaration 'std::vector<int> x'
    7 |   vector<int> x(m),y(m-1);
      |               ^
a.cc:4:11: note: previous declaration as 'int x'
    4 |   int n,m,x;
      |           ^
a.cc:8:29: error: invalid types 'int[int]' for array subscript
    8 |   for(int i=0;i<n;++i)cin>>x[i];
      |                             ^
a.cc:9:10: error: request for member 'begin' in 'x', which is of non-class type 'int'
    9 |   sort(x.begin(),x.end());
      |          ^~~~~
a.cc:9:20: error: request for member 'end' in 'x', which is of non-class type 'int'
    9 |   sort(x.begin(),x.end());
      |                    ^~~
a.cc:10:31: error: invalid types 'int[int]' for array subscript
   10 |   for(int i=0;i<n-1;++i)y[i]=x[i+1]-x[i];
      |                               ^
a.cc:10:38: error: invalid types 'int[int]' for array subscript
   10 |   for(int i=0;i<n-1;++i)y[i]=x[i+1]-x[i];
      |                                      ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n, m, x[100000], d[99999], i;
	cin >> n >> m;
	for(i = 0; i < m; i++) cin >> x[i];
	sort(x, x+m);
	for(i = 1; i < m; i++){
		d[i - 1] = x[i] - x[i - 1];
	}
	sort(d, d+(m-1), greater<>())
	int result = x[m - 1] - x[0];
	for(i = 0; i < n - 1; i++){
		result -= d[i];
	}
 
	cout << result << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:38: error: expected ';' before 'int'
   12 |         sort(d, d+(m-1), greater<>())
      |                                      ^
      |                                      ;
   13 |         int result = x[m - 1] - x[0];
      |         ~~~                           
a.cc:15:17: error: 'result' was not declared in this scope
   15 |                 result -= d[i];
      |                 ^~~~~~
a.cc:18:17: error: 'result' was not declared in this scope
   18 |         cout << result << endl;
      |                 ^~~~~~
Language: C++

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

using namespace std;

int main() {
	long long  N,M,LL;
	cin >> N >> M;

	if ( N > M )
	long long x[M],d[M];
	for(int i=0; i<M; i++) cin >> x[i]; 
	if (( M > 1) || ( N >= M))  {
		sort(x, x+M);
		for(int i=0; i<M-1; i++) d[i] = abs(x[i+1] -x[i]);
		sort(d, d+M-1, greater<>() );
		LL = abs(x[M-1] - x[0]);
		for(int i=0; i<N-1; i++) {
			LL = LL -d[i];
		}
	} else {
		LL = 0;
	}	
	
	cout << LL << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:39: error: 'x' was not declared in this scope
   15 |         for(int i=0; i<M; i++) cin >> x[i];
      |                                       ^
a.cc:17:22: error: 'x' was not declared in this scope
   17 |                 sort(x, x+M);
      |                      ^
a.cc:18:42: error: 'd' was not declared in this scope
   18 |                 for(int i=0; i<M-1; i++) d[i] = abs(x[i+1] -x[i]);
      |                                          ^
a.cc:19:22: error: 'd' was not declared in this scope
   19 |                 sort(d, d+M-1, greater<>() );
      |                      ^
Language: C++

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

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

int main(){
    int n=0,m=0,i=0,ans=0,sum=0;
    int x[100000]={0};
    int sub[9999]={0};

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

Compiler output:
a.cc: In function 'int main()':
a.cc:27:9: error: redeclaration of 'int ans'
   27 |     int ans=0;
      |         ^~~
a.cc:14:21: note: 'int ans' previously declared here
   14 |     int n=0,m=0,i=0,ans=0,sum=0;
      |                     ^~~
Language: C++

/*
間隔長い順に上位N - 1個の和を全長から差っ引く
*/

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

int main()
{
  int N, M;
  cin >> N >> M;
  
  // 座標
  vector<int> coordinates(M);
  for(int i = 0; i < M; ++i)
  {
    cin >> coordinates.at(i);
  }
  
  // 座標小さい順にソート
  sort(coordinates.begin(), coordinates.end());
  
  // 座標同士の間隔（一番小さい座標から順番）
  vector<int> intervals(M - 1);
  for(int i = 0; i < M - 1; ++i)
  {
    intervals.at(i) = coordinates.at(i + 1) - coordinates.at(i);
  }
  
  sort(intervals.begin(), intervals.end(), greater<type>());
  
  // 差っ引く間隔の合計
  long deletedintervals = 0;
  // 座標が全てコマで埋まるなら差っ引く必要無し
  if(M > N)
  {
    for(int i = 0; i < N - 1; ++i)
    {
      deletedintervals += intervals.at(i);
    }
  }

  cout << coordinates.back() - coordinates.front() - deletedintervals << endl; 
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:52: error: 'type' was not declared in this scope; did you mean 'wctype'?
   30 |   sort(intervals.begin(), intervals.end(), greater<type>());
      |                                                    ^~~~
      |                                                    wctype
a.cc:30:56: error: template argument 1 is invalid
   30 |   sort(intervals.begin(), intervals.end(), greater<type>());
      |                                                        ^
Language: C++

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

using namespace std;

int main()
{
  // input
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; i++) {
      cin >> X[i];
  }

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

  // sort X
  sort(X.begin(), X.end());

  // Diff X
  vector<int> X_diff(M-1);
  for (int i = 0; i < M-1; i++){
    X_diff[i] = X[i+1] - X[i];
  }

  sort(X_diff.begin(), X_diff.end())
  int L = 0;
  for(i = 0; i < M-N; i++){
    L += X_diff[i];
  }
  cout << X[M-1] - X[0] - L << endl;

  // Output
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:37: error: expected ';' before 'int'
   32 |   sort(X_diff.begin(), X_diff.end())
      |                                     ^
      |                                     ;
   33 |   int L = 0;
      |   ~~~                                
a.cc:34:7: error: 'i' was not declared in this scope
   34 |   for(i = 0; i < M-N; i++){
      |       ^
a.cc:35:5: error: 'L' was not declared in this scope
   35 |     L += X_diff[i];
      |     ^
a.cc:37:27: error: 'L' was not declared in this scope
   37 |   cout << X[M-1] - X[0] - L << endl;
      |                           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int x[10000000];
int y[10000000];

int main(){
  	int n , m;
	int i;	
	cin >> n >> m;

	rep(i, m) cin >> x[i];
	sort(x.begin(), x.end());
  
	rep(i, m-1){
		y[i] = x[i+1] - x[i];
	}
	sort(y.begin(), y.end());
  	
  	
  	long long j = 0;
	rep(i, m-n){
		j += y[i];
	}
	cout << j << endl;
}

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

#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int x[10000000];
int y[10000000]

int main(){
  	int n , m;
	int i;	
	cin >> n >> m;

	rep(i, m) cin >> x[i];
	sort(x.begin(), x.end());
  
	rep(i, m-1){
		y[i] = x[i+1] - x[i];
	}
	sort(y.begin(), y.end());
  	
  	
  	long long j = 0;
	rep(i, m-n){
		j += y[i];
	}
	cout << j << endl;
}

Compiler output:
a.cc:10:1: error: expected initializer before 'int'
   10 | int main(){
      | ^~~
Language: C++

#include <iostream>
using namespace std;

int main(){
	int n, m, x[100000], d[99999], i;
	cin >> n, m;
	for(i = 0; i < m; i++) cin >> x[i];
	sort(a, a+m);
	for(i = 1; i < m; i++){
		d[i - 1] = x[i] - x[i - 1];
	}
	sort(d, d+m-1);
	int result = x[m - 1] - x[0];
	for(i = 0; i < n - 1; i++){
		result -= d[i];
	}
 
	cout << result << endl;
	return 0;
}

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

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

int myabs( int n ) {
    return n < 0 ? -n : n;
}

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

    int n, m;
    std::cin >> n >> m;
    if( n > m ){
        std::cout << 0 << std::endl;
        return 0;
    }

    std::vector<int> x( m );
    for( auto& elem : x ){
        std::cin >> elem;
    }
    std::sort( x.begin(), x.end() );

    int sum = 0;
    std::vector<int> dist_between_elems( m - 1 );
    auto dist_itr = dist_between_elems.begin();
    for( auto itr = x.begin() + 1; itr != x.end(); ++itr ){
        *dist_itr = myabs( *itr - *( itr - 1 ) );
        sum += *dist_itr
        ++dist_itr;
    }

    std::vector<int>::iterator max_itr;
    for( int i = 0; i < n - 1; ++i ){
        max_itr = std::max_element( dist_between_elems.begin(), dist_between_elems.end() );
        sum -= *max_itr;
        *max_itr = 0;
    }

    std::cout << sum << std::endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:11: error: expected ';' before 'dist_itr'
   32 |         ++dist_itr;
      |           ^~~~~~~~
      |           ;
Language: C++

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

int myabs( int n ) {
    return n < 0 ? -n : n;
}

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

    int n, m;
    std::cin >> n >> m;
    if( n > m ){
        std::cout << 0 << std::endl;
        return 0;
    }

    std::vector<int> x( m );
    for( auto& elem : x ){
        std::cin >> elem;
    }
    std::sort( x.begin(), x.end() );

    int sum = 0;
    std::vector<int> dist_between_elems( m - 1 );
    auto dist_itr = dist_between_elems.begin();
    for( auto itr = x.begin() + 1; itr != x.end(); ++itr ){
        sum += *dist_itr = myabs( *itr - *( itr - 1 ) );
        ++dist_itr;
    }

    std::vector<int>::iterator max_itr;
    for( int i = 0; i < n - 1; ++i ){
        sum -= max_itr = std::max_element( dist_between_elems.begin(), dist_between_elems.end() );
        *max_itr = 0;
    }

    std::cout << sum << std::endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:13: error: no match for 'operator-=' (operand types are 'int' and 'std::vector<int>::iterator')
   36 |         sum -= max_itr = std::max_element( dist_between_elems.begin(), dist_between_elems.end() );
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

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

int main() {
  int N,M,same=0,length=0;
  cin >> N >> M;
  vector<int> X(M),delta(M-1);
  for(int i=0;i<M;i++){
  	cin >> X.at(i);
  }
  if(N>=M){
  	cout << 0 << endl;
  }
  else{
  sort(X.begin(),X.end());
  for(int i=0;i<M-1;i++){
  	delta.at(i)=X.at(i+1)-X.at(i);
  }
  sort(delta.begin(),delta.end());
  for(int i=0;i<M-N-1;i++){
  	length+=dalta.at(i);
  }
  cout << length << endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: 'dalta' was not declared in this scope; did you mean 'delta'?
   21 |         length+=dalta.at(i);
      |                 ^~~~~
      |                 delta
Language: C++

#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int C[100010]={0};
int FLAG;
struct node{
    int dis=0;
    int S,E;
};
bool com(node a,node b){
    if(FLAG==1){
        return (a.dis<=b.dis);
    }
    if(FLAG==2){
        return (a.S>=b.S);
    }
}
int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    if(N>=M){
        cout<<'0';
        return 0;
    }
    for(int i=0;i<M;i++){
        scanf("%d",&C[i]);
    }
    sort(C,C+M);
    if(N==1){
        cout<<(C[0]-C[M-1]);
        return 0;
    }
    node n[M];
    for(int i=0;i<M-1;i++){
        n[i].dis=C[i+1]-C[i];
        n[i].S=C[i];
        n[i].E=C[i+1];
    }
    FLAG=1;
    sort(n,n+M,com);
    FLAG=2;
    sort(n,n+N-1,com);
    int s,e,ans=0,k=0;
    s=C[i];
    for(int i=0;i<M;i++){
        if(i>=n[k].S){
            ans=ans+C[i]-s;
            i=n[k].E;
            s=C[i];
            k++;
        }
    }
    cout<<ans;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:9: error: 'i' was not declared in this scope
   48 |     s=C[i];
      |         ^
a.cc: In function 'bool com(node, node)':
a.cc:21:1: warning: control reaches end of non-void function [-Wreturn-type]
   21 | }
      | ^
Language: C++

#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(m);
	LL cns[m];
	rep(i, 0, m)	cns[i] = scanLong();
	sort(cns, cns+m);
	VLL diffs;
	rep(i, 1, m)	diffs.push_back(cns[i]-cns[i-1]);
	LL ans = accumulate(cns, cns+m, 0ll);
	sort(diffs.begin(), diffs.end());
	LL cnt = 0;
	rep(i, (LL)diffs.size(), 0ll) {
		if(cnt + 1 == n)	break;
		ans -= diffs[i];
		cns++;
	}
	pll(ans); nl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:17: error: lvalue required as increment operand
   72 |                 cns++;
      |                 ^~~
Language: C++

#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(m);
	LL cns[m];
	rep(i, 0, m)	cns[i] = scanLong();
	sort(cns, cns+m);
	VLL diffs;
	rep(i, 1, m)	diffs.push_back(cns[i]-cns[i-1]);
	LL dist = accumulate(cns, cns+m, 0ll);
	sort(diffs.begin(), diffs.end());
	LL cnt = 0;
	rep(i, (LL)diffs.size(), 0ll) {
		if(cnt + 1 == n)	break;
		ans -= diffs[i];
		cns++;
	}
	pll(ans); nl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:71:17: error: 'ans' was not declared in this scope; did you mean 'cns'?
   71 |                 ans -= diffs[i];
      |                 ^~~
      |                 cns
a.cc:72:17: error: lvalue required as increment operand
   72 |                 cns++;
      |                 ^~~
a.cc:74:13: error: 'ans' was not declared in this scope; did you mean 'cns'?
   74 |         pll(ans); nl;
      |             ^~~
a.cc:10:32: note: in definition of macro 'pll'
   10 | #define pll(x) printf("%lld ", x)
      |                                ^
Language: C++

#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
#endif
	sll(n); sll(m);
	LL cns[m];
	rep(i, 0, m)	cns[i] = scanLong();
	sort(cns, cns+m);
	VLL diffs;
	rep(i, 1, m)	diffs.push_back(cns[i]-cns[i-1]);
	LL dist = accumulate(cns, cns+m, 0ll);
	sort(diffs.begin(), diffs.end());
	LL cnt = 0;
	rep(i, (LL)diffs.size(), 0ll) {
		if(cnt + 1 == n)	break;
		ans -= diffs[i];
		cns++;
	}
	pll(ans); nl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:17: error: 'ans' was not declared in this scope; did you mean 'cns'?
   74 |                 ans -= diffs[i];
      |                 ^~~
      |                 cns
a.cc:75:17: error: lvalue required as increment operand
   75 |                 cns++;
      |                 ^~~
a.cc:77:13: error: 'ans' was not declared in this scope; did you mean 'cns'?
   77 |         pll(ans); nl;
      |             ^~~
a.cc:10:32: note: in definition of macro 'pll'
   10 | #define pll(x) printf("%lld ", x)
      |                                ^
Language: C++

#include <iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N, M;

    cin >> N >> M;

    int Spins[M];

    for (int num = 0; num < M; num++)
    {
        cin >> Spins[num];
    }

    sort(Spins, Spins + M);

    int diff[M-1];

    for (int i = 0; i < M - 1; i++)
    {
        diff[i] = std::abs(Spins[i] - Spins[i + 1]);
    }

    if(M < N) {
        N =M;
    }

    sort(diff, diff + M - 1);

    int index = 0;
    int ans = 0;

    int roop = N - 1;

    for(int i = 0; i < N -1; i++) {
        ans += diff[i];
    }

    cout << ans;

    return 0;
}

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

#include <stdio.h>

int main(){
    int n=0;
    int m=0;
    int x[100000]={0};
    int i,j,tmp;
    int a[100000]
    int b;
    int div;
    int sum;
    int count;
    int t;


    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d",&x[i]);
    }
    for (i=0; i<m; ++i) {
        for (j=i+1; j<m; ++j) {
            if (x[i] > x[j]) {
                tmp =  x[i];
                x[i] = x[j];
                x[j] = tmp;
            } 
        }
   }
    for(i=1;i<m;i++){
     t[i-1]=x[i]-x[i-1]
    }
    for (i=0; i<m; ++i) {
        for (j=i+1; j<m; ++j) {
            if (t[i] > t[j]) {
                tmp =  t[i];
                t[i] = x[j];
                t[j] = tmp;
            }
        }
    }
    for(i=0;i<n<i++){
        sum=t[n];
        if(t[n]==t[n+1]){
            sumt[n+1];
            i++;
        }
    }


    if(n>m){
        sum=0;
    }
    printf("%d",sum);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:5: error: expected initializer before 'int'
    9 |     int b;
      |     ^~~
a.cc:30:7: error: invalid types 'int[int]' for array subscript
   30 |      t[i-1]=x[i]-x[i-1]
      |       ^
a.cc:34:18: error: invalid types 'int[int]' for array subscript
   34 |             if (t[i] > t[j]) {
      |                  ^
a.cc:34:25: error: invalid types 'int[int]' for array subscript
   34 |             if (t[i] > t[j]) {
      |                         ^
a.cc:35:25: error: invalid types 'int[int]' for array subscript
   35 |                 tmp =  t[i];
      |                         ^
a.cc:36:18: error: invalid types 'int[int]' for array subscript
   36 |                 t[i] = x[j];
      |                  ^
a.cc:37:18: error: invalid types 'int[int]' for array subscript
   37 |                 t[j] = tmp;
      |                  ^
a.cc:41:20: error: expected ';' before ')' token
   41 |     for(i=0;i<n<i++){
      |                    ^
      |                    ;
a.cc:42:14: error: invalid types 'int[int]' for array subscript
   42 |         sum=t[n];
      |              ^
a.cc:43:13: error: invalid types 'int[int]' for array subscript
   43 |         if(t[n]==t[n+1]){
      |             ^
a.cc:43:19: error: invalid types 'int[int]' for array subscript
   43 |         if(t[n]==t[n+1]){
      |                   ^
a.cc:44:13: error: 'sumt' was not declared in this scope; did you mean 'sum'?
   44 |             sumt[n+1];
      |             ^~~~
      |             sum
Language: C++

#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define H_MAX 50
#define W_MAX 50

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

namespace patch {
  template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
}

int main() {

  int n,m;
  cin >> n >> m;
  vector<int> x;
  int temp;
  rep(i,m){
    cin >> temp;
    x.push_back(temp);
  }
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  sort(x.begin(),x.end());
  int length[m-1];
  int sum=0;
  int acclength[m-1];
  int accrlength[m-1];
  acclength[0]=0;
  rep(i,m-1) {
    length[i] = x[i+1] - x[i];
    sum += length[i];
    acclength[i+1] = sum;
  }
  int sum2=0;
  rep(i,m-1) {
    sum2 += length[m-2-i];
    accrlength[m-2-i] = sum2;
  }
  int count=n;
  int len_to_left,len_to_right;
  len_to_left = length[0];
  len_to_right= length[m-2];
  int num_to_left=0,num_to_right=m-1;
  vector<pii> y;
  rep(i,m-1) {
    y.push_back(pii(length[i],i));
  }
  sort(y.begin(),y.end());
  int count2 = m-2;
  int liter=0,riter=m-1;
  bool visited[m];
  rep(i,m) {
    visited[i]==false;
  }
  while(1) {
    if(count == 0)
      break;
    else if(count == 1) {
      if(len_to_left > len_to_right) {
	sum -= len_to_left;
      }
      else {
	sum -= len_to_right;
      }
      break;
    }
    else {
      sum -= y[count2].first;
      visited[y[count2].second] = true;
      visited[y[count2].second+1]=true;
      if(y[count2].second > num_to_left) {
	num_to_left = y[count2].second;
	while(visited[liter] == false) {
	  liter++;
	}
	len_to_left = acclength[y[count2].second] - acclength[liter];
      if(y[count2].second < num_to_right)
	num_to_right = y[count2].second;
	if(y[count2].second+1==riter) {
	  riter--;
	}
	while(visited[riter]==false){
	  riter--;
	}
	len_to_right = accrlength[y[count2].second] - acclength[riter-1];
      count -= 2;
      count2--;
    }
  }
  cout << sum << endl;
  return 0;
}
 


Compiler output:
a.cc: In function 'int main()':
a.cc:105:2: error: expected '}' at end of input
  105 | }
      |  ^
a.cc:22:12: note: to match this '{'
   22 | int main() {
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M,K;
  cin>>N>>M;
  vector<int> x;
  vector<int> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  K=0;
  for(int k=0;k<M-1;k++){
    S.at(i)=x.at(i+1)-x.at(i);
    K=K+S.at(i);
  }
  sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  for(int j=0;j<N;j++){
    K=K-S.at(j);
    if(N>=M){
      K=1;
      break;
    }
    K=K-S.at(j);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:10: error: 'i' was not declared in this scope
   14 |     S.at(i)=x.at(i+1)-x.at(i);
      |          ^
Language: C++

#include <stdio.h>

int main(){
    int n=0;
    int m=0;
    int x[100000]={0};
    int i,j,tmp;
    int a[100000]
    int b;
    int div;
    int sum;
    int count;
    int t


    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d",&x[i]);
    }
    for (i=0; i<m; ++i) {
        for (j=i+1; j<m; ++j) {
            if (x[i] > x[j]) {
                tmp =  x[i];
                x[i] = x[j];
                x[j] = tmp;
            } 
        }
   }
    for(i=1;i<m;i++){
     t[i-1]=x[i]-x[i-1]
    }
    for (i=0; i<m; ++i) {
        for (j=i+1; j<m; ++j) {
            if (t[i] > t[j]) {
                tmp =  t[i];
                t[i] = x[j];
                t[j] = tmp;
            }
        }
    }
    for(i=0;i<n<i++){
        sum=t[n];
        if(t[n]==t[n+1]){
            sumt[n+1];
            i++;
        }
    }


    if(n>m){
        sum=0;
    }
    printf("%d",sum);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:5: error: expected initializer before 'int'
    9 |     int b;
      |     ^~~
a.cc:16:5: error: expected initializer before 'scanf'
   16 |     scanf("%d%d",&n,&m);
      |     ^~~~~
a.cc:30:6: error: 't' was not declared in this scope
   30 |      t[i-1]=x[i]-x[i-1]
      |      ^
a.cc:34:17: error: 't' was not declared in this scope
   34 |             if (t[i] > t[j]) {
      |                 ^
a.cc:41:20: error: expected ';' before ')' token
   41 |     for(i=0;i<n<i++){
      |                    ^
      |                    ;
a.cc:42:13: error: 't' was not declared in this scope
   42 |         sum=t[n];
      |             ^
a.cc:44:13: error: 'sumt' was not declared in this scope; did you mean 'sum'?
   44 |             sumt[n+1];
      |             ^~~~
      |             sum
Language: C++

  // 一番広い所をさがす
  int maxi = -1;
  REP(i,l,M-r+1) {
    maxi = max(maxi, X[i] - X[i-1]);
  }

  return (X[M-r] - X[l-1]) - maxi;
}

int main()
{
  cin >> N >> M;
  REP(i,0,M) cin >> X[i];
  sort(X, X+M);

  int ans = 0;
  if (N >= M) ans = 0;
  else { // N < M
    ans = INF;
    REP(i,0,N+1) {
      ans = min(ans, take(i,N-i));
    }
  }
  cout << ans << endl;

  return 0;
}


Compiler output:
a.cc:3:6: error: expected constructor, destructor, or type conversion before '(' token
    3 |   REP(i,l,M-r+1) {
      |      ^
a.cc:7:3: error: expected unqualified-id before 'return'
    7 |   return (X[M-r] - X[l-1]) - maxi;
      |   ^~~~~~
a.cc:8:1: error: expected declaration before '}' token
    8 | }
      | ^
a.cc: In function 'int main()':
a.cc:12:3: error: 'cin' was not declared in this scope
   12 |   cin >> N >> M;
      |   ^~~
a.cc:12:10: error: 'N' was not declared in this scope
   12 |   cin >> N >> M;
      |          ^
a.cc:12:15: error: 'M' was not declared in this scope
   12 |   cin >> N >> M;
      |               ^
a.cc:13:7: error: 'i' was not declared in this scope
   13 |   REP(i,0,M) cin >> X[i];
      |       ^
a.cc:13:3: error: 'REP' was not declared in this scope
   13 |   REP(i,0,M) cin >> X[i];
      |   ^~~
a.cc:14:8: error: 'X' was not declared in this scope
   14 |   sort(X, X+M);
      |        ^
a.cc:14:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |   sort(X, X+M);
      |   ^~~~
      |   short
a.cc:19:11: error: 'INF' was not declared in this scope
   19 |     ans = INF;
      |           ^~~
a.cc:24:3: error: 'cout' was not declared in this scope
   24 |   cout << ans << endl;
      |   ^~~~
a.cc:24:18: error: 'endl' was not declared in this scope
   24 |   cout << ans << endl;
      |                  ^~~~
Language: C++

#include <iostream>
#include <stdlib.h>

// int 型要素を昇順ソートするときの比較関数
int IntCompareA(const void* pElem1, const void* pElem2)
{
    return *(const int*)pElem1 - *(const int*)pElem2;
}

int main()
{
	int n,m;
	int x[100000];
	std::cin>>n>>m;
	for(int i=0;i<m;i++)
	    std::cin>>x[i];
    qsort(x, n, sizeof *x, IntCompareA);
    
    int dist[100000];
    for(int i=0;i<m-1;i++){
        dist[i]=x[i+1]-x[i];
        if(dist[i]<0){
            dist[i]= -1 * dist[i];
        }
    }
    qsort(dist, m-1, sizeof *dist, IntCompareA);
    int sum=0;
    if(m-n-1=>0){
        for(int i=0;i<m-n-1;i++){
            sum+=dist[i];
        }
    }
    std::cout<<sum;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:14: error: expected primary-expression before '>' token
   28 |     if(m-n-1=>0){
      |              ^
Language: C++

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

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

  vector<int> x(m);
  vector<int> gap(m-1);
  int sum = 0;

  for(int i = 0; i < m; i++) cin >> x[i];

  if(m == 1){
    cout << '0' << endl;
    return 0;
  }
  else{
    sort(x.begin(), x.end());

    for(int i = 0; i < m; i++){
      if(i != 0){
        gap[i-1] = abs(x[i]-x[i-1]);
        sum += gap[i-1];
      }
    }

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

    for(int i = 0; i < n-1; i++) sum -= gap[gap.size()-1-i];

    cout << sum << endl;
  }

  return 0;
}


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

#include <iostream>
#include <stdlib.h>

// int 型要素を昇順ソートするときの比較関数
int IntCompareA(const void* pElem1, const void* pElem2)
{
    return *(const int*)pElem1 - *(const int*)pElem2;
}

int main()
{
	int n,m;
	int x[100000];
	std::cin>>n>>m;
	for(int i=0;i<m;i++)
	    std::cin>>x[i];
    qsort(x, n, sizeof *x, IntCompareA);
    
    int dist[100000];
    for(int i=0;i<m-1;i++){
        dist[i]=x[i+1]-x[i];
        if(dist[i]<0){
            dist[i]= -1 * dist[i]
        }
    }
    qsort(dist, m-1, sizeof *dist, IntCompareA);
    int sum=0;
    if(m-n-1>0){
        for(int i=0;i<m-n-1;i++){
            sum+=dist[i];
        }
    }
    std::cout<<sum;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:34: error: expected ';' before '}' token
   23 |             dist[i]= -1 * dist[i]
      |                                  ^
      |                                  ;
   24 |         }
      |         ~
Language: C++

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


int main() {
  int N;
  int M;
  cin>>N;
  cin>>M;
  int X=0;
  vector<int> L(M);
  for (int i =0; i<M; i++){
    cin>>L.at(i);
  }
  vector<int> S(M-1);
  for (int i= 0; i<M-1; i++){
    S.at(i)=L.at(i+1)-L.at(i);
  }
  sort(S.begin(), S.end());
  for(int i = 0; i M-N;i++){
    X=X+S.at(i);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:19: error: expected ';' before 'M'
   20 |   for(int i = 0; i M-N;i++){
      |                   ^~
      |                   ;
a.cc:20:23: error: expected ')' before ';' token
   20 |   for(int i = 0; i M-N;i++){
      |      ~                ^
      |                       )
a.cc:20:24: error: 'i' was not declared in this scope
   20 |   for(int i = 0; i M-N;i++){
      |                        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K=0;
  cin>>N>>M;
  vector<int> x;
  vector<int> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    if(x.at(i+1)>=x.at(i)){
      S.at(i)=x.at(i+1)-x.at(i);
    }
    else{
      S.at(i)=x.at(i)-x.at(i+1);
    }
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    K=K-S(M-1-j);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:10: error: no match for call to '(std::vector<int>) (int)'
   23 |     K=K-S(M-1-j);
      |         ~^~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K=0;
  cin>>N>>M;
  vector<int> x;
  vector<int> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    if(x.at(i+1)>=x.at(i)){
      S.at(i)=x.at(i+1)-x.at(i);
    }
    else{
      S.at(i)=x.at(i)-x.at(i+1)
    }
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    K=K-S(M-1-j);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:32: error: expected ';' before '}' token
   17 |       S.at(i)=x.at(i)-x.at(i+1)
      |                                ^
      |                                ;
   18 |     }
      |     ~                           
a.cc:23:10: error: no match for call to '(std::vector<int>) (int)'
   23 |     K=K-S(M-1-j);
      |         ~^~~~~~~
Language: C

#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(){
  int N,M,X[100000],t,a,b,max,min,len;
  int partation[100000]={};　//どこで区切るか
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    scanf("%d",&X[i]);
  }
  qsort(X, M, sizeof(int), compare_int);
  max=X[M-1];
  min=X[0];
  for(int i=0;i<M-1;i++){
    a=partation[N-2];
    if(X[i+1]-X[i]<X[a]-X[a+1])continue;
    for(int j=0;j<N-1;j++){
      a=partation[j];
      if(X[i]-X[i-1]>X[a+1]-X[a]){
        partation[j]=i;
        break;
      }
    }
  }
  len=max-min;
  a=partation[0];
  len=len-(X[a+1]-X[a]);
  for(int i=1;i<N;i++){
    if(partation[i]!=partation[i-1]){
      a=partation[i];
      len=X[a+1]-X[a];
    }
  }
  printf("%d",len);
}

Compiler output:
main.c: In function 'main':
main.c:9:28: error: stray '\343' in program
    9 |   int partation[100000]={};<U+3000>//<U+3069><U+3053><U+3067><U+533A><U+5207><U+308B><U+304B>
      |                            ^~~~~~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <string.h>
#include <map>
#include <algorithm>
using namespace std;

int s[100005];
int ss[100005];

int main()
{
   	int n, m;
   	cin >> n >> m;
   	for (int i = 0; i < m; i++) {
   		cin>>s[i];	
	}
   	sort(s,s+m);
   	for (int i = 0; i < m-1; i++) {
   		ss[i] = s[i+1]-s[i];	
	}
   	sort(ss, ss+m-1);
   	long long sum = 0;
   	for (int i = 0; i < m-n; i++) {
   		sum += ss[i];	
	}
   	cout << sum;
   	
	return 0;
}
1 8 2 2

Compiler output:
a.cc:31:1: error: expected unqualified-id before numeric constant
   31 | 1 8 2 2
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K=0;
  cin>>N>>M;
  vector<int> x;
  vector<int> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    if(x.at(i+1)>=x.at(i){
      S.at(i)=x.at(i+1)-x.at(i);
    }
    else{
      S.at(i)=x.at(i)-x.at(i+1)
    }
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    K=K-S(M-1-j);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:26: error: expected ';' before '{' token
   13 |     if(x.at(i+1)>=x.at(i){
      |                          ^
      |                          ;
a.cc:16:5: error: expected primary-expression before 'else'
   16 |     else{
      |     ^~~~
a.cc:15:6: error: expected ')' before 'else'
   15 |     }
      |      ^
      |      )
   16 |     else{
      |     ~~~~
a.cc:13:7: note: to match this '('
   13 |     if(x.at(i+1)>=x.at(i){
      |       ^
a.cc:23:10: error: no match for call to '(std::vector<int>) (int)'
   23 |     K=K-S(M-1-j);
      |         ~^~~~~~~