Submission #14696561


Source Code Expand

Copy
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N,M;
    cin >> N >> M;
    vector<int> vp(M);
    if (N >= M ) {
        cout << 0 << endl;
        return;
    }
    REP(i,M) {
        int x;
        cin >> x;
        vp[i] = x;
    }
    sort(ALL(vp));
    vector<int> vl(M-1);
    REP(i,M-1) vl[i] = vp[i+ 1] - vp[i];
    sort(ALL(vl));
    reverse(ALL(vl));
    ll sm = 0;
    FOR(i,N-1,M-1) sm += vl[i];
    cout << sm << endl;
}

int main() {
    solve();
    return 0;
}

Submission Info

Submission Time
Task C - Streamline
User reud
Language C++ (GCC 9.2.1)
Score 300
Code Size 985 Byte
Status AC
Exec Time 41 ms
Memory 4016 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 23
AC × 3
Set Name Test Cases
All 0_normal_1, 0_normal_2, 0_normal_3, 0_normal_4, 1_max_1, 1_max_2, 1_max_3, 1_max_4, 2_nsmall_1, 2_nsmall_2, 2_nsmall_3, 2_nsmall_4, 3_msmall_1, 3_msmall_2, 3_msmall_3, 3_msmall_4, 4_corner_1, 4_corner_2, 4_corner_3, 4_corner_4, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_normal_1 AC 10 ms 3572 KB
0_normal_2 AC 2 ms 3488 KB
0_normal_3 AC 3 ms 3376 KB
0_normal_4 AC 40 ms 3888 KB
1_max_1 AC 2 ms 3488 KB
1_max_2 AC 2 ms 3376 KB
1_max_3 AC 3 ms 3648 KB
1_max_4 AC 41 ms 4016 KB
2_nsmall_1 AC 37 ms 3936 KB
2_nsmall_2 AC 18 ms 3596 KB
2_nsmall_3 AC 37 ms 3516 KB
2_nsmall_4 AC 19 ms 3668 KB
3_msmall_1 AC 2 ms 3480 KB
3_msmall_2 AC 2 ms 3452 KB
3_msmall_3 AC 2 ms 3608 KB
3_msmall_4 AC 2 ms 3456 KB
4_corner_1 AC 11 ms 3640 KB
4_corner_2 AC 30 ms 3652 KB
4_corner_3 AC 3 ms 3488 KB
4_corner_4 AC 3 ms 3560 KB
sample_01 AC 2 ms 3508 KB
sample_02 AC 2 ms 3428 KB
sample_03 AC 3 ms 3520 KB