You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
481 B
C++
21 lines
481 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
typedef long long ll;
|
|
const int N = 1e5 + 50;
|
|
int a[N];
|
|
int main()
|
|
{
|
|
int n, m;
|
|
ll ans = 0;
|
|
scanf("%d%d", &n, &m);
|
|
for (int i = 0; i < m; i++)
|
|
scanf("%d", a + i);
|
|
sort(a, a + m);
|
|
for (int i = 1; i < m; i++)
|
|
a[i - 1] = a[i] - a[i - 1];
|
|
sort(a, a + m - 1, greater<int>());
|
|
for (int i = n - 1; i < m - 1; i++)
|
|
ans += a[i];
|
|
printf("%lld", ans);
|
|
return 0;
|
|
} |