Language: C++

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

using namesapce std;

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N);
  for(int i = 0; i < M; i++) cin >> A[i];
  
  sort(A.begin(), A.end());
  
  vector<int>> B(M-1);
  
  for(int i = 0; i < M-1; i++){
    B[i] = A[i+1]-A[i];
  }
  
  sort(B.begin(),B.end(),greater<int>);
  int th = B[N - 2];
  
  int ans = 0;
  for(int i = 0; i < M-1; i++){
    if(A[i + 1] - A[i] < th);
    ans += B[i];
  }
  cout << ans;
}

Compiler output:
a.cc:6:7: error: expected nested-name-specifier before 'namesapce'
    6 | using namesapce std;
      |       ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:10:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   10 |   cin >> N >> M;
      |   ^~~
      |   std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:12:3: error: 'vector' was not declared in this scope
   12 |   vector<int> A(N);
      |   ^~~~~~
a.cc:12:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:12:10: error: expected primary-expression before 'int'
   12 |   vector<int> A(N);
      |          ^~~
a.cc:13:37: error: 'A' was not declared in this scope
   13 |   for(int i = 0; i < M; i++) cin >> A[i];
      |                                     ^
a.cc:15:8: error: 'A' was not declared in this scope
   15 |   sort(A.begin(), A.end());
      |        ^
a.cc:15:3: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   15 |   sort(A.begin(), A.end());
      |   ^~~~
      |   std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:4:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:17:10: error: expected primary-expression before 'int'
   17 |   vector<int>> B(M-1);
      |          ^~~
a.cc:20:5: error: 'B' was not declared in this scope
   20 |     B[i] = A[i+1]-A[i];
      |     ^
a.cc:23:8: error: 'B' was not declared in this scope
   23 |   sort(B.begin(),B.end(),greater<int>);
      |        ^
a.cc:23:26: error: 'greater' was not declared in this scope; did you mean 'std::greater'?
   23 |   sort(B.begin(),B.end(),greater<int>);
      |                          ^~~~~~~
      |                          std::greater
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/stl_function.h:353:12: note: 'std::greater' declared here
  353 |     struct greater;
      |            ^~~~~~~
a.cc:23:34: error: expected primary-expression before 'int'
   23 |   sort(B.begin(),B.end(),greater<int>);
      |                                  ^~~
a.cc:31:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   31 |   cout << ans;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~