Submission #67529885


Source Code Expand

#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using ull = unsigned long long;
using ld = long double;
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rep(X, a, b) for(int X = a; X < b; ++X)
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define fi first
#define se second

#ifdef LOCAL
#define ZTMYACANESOCUTE // freopen("in.txt", "r", stdin);
#define debug(...) {cerr << #__VA_ARGS__ << " = "; dbg(__VA_ARGS__);}
#else
#define ZTMYACANESOCUTE ios_base::sync_with_stdio(0), cin.tie(0);
#define debug(...) 6;
#endif

void dbg() { cerr << '\n'; }
template<typename T, typename ...U>
void dbg(T t, U ...u) { cerr << t << ' '; dbg(u...); }

pii operator + (const pii &p1, const pii &p2) { return make_pair(p1.fi + p2.fi, p1.se + p2.se); }
pii operator - (const pii &p1, const pii &p2) { return make_pair(p1.fi - p2.fi, p1.se - p2.se); }
pll operator + (const pll &p1, const pll &p2) { return make_pair(p1.fi + p2.fi, p1.se + p2.se); }
pll operator - (const pll &p1, const pll &p2) { return make_pair(p1.fi - p2.fi, p1.se - p2.se); }

template<class T> bool chmin(T &a, T b) { return (b < a && (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b && (a = b, true)); }

#define lpos pos << 1
#define rpos pos << 1 | 1
 
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator << (ostream &os, const vector<A> &p) { for(const auto &a : p) os << a << " "; os << '\n'; return os; }
 
const int MAXN = 2e5 + 5, MOD = 998244353, IINF = 1e9 + 7, MOD2 = 1000000007;
const ll LINF = 1e18L + 5;
const int B = 320;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int get_rand(int l, int r){ return uniform_int_distribution<int>(l, r)(rng); }
 
ll fpow (ll x, ll exp, ll mod = LLONG_MAX) { if (x == 0) return 0; ll res = 1; while (exp > 0) { if (exp & 1) res = res * x % mod; x = x * x % mod; exp >>= 1; } return res; }

void solve() {
    int n, m; cin >> n >> m;
    vector<ll> x(n);
    rep (i, 0, n) cin >> x[i];
    sort(all(x));
    vector<ll> d;
    rep (i, 0, n - 1) d.pb(x[i + 1] - x[i]);
    sort(all(d));
    rep (i, 0, m - 1) d.pop_back();
    cout << accumulate(all(d), 0LL) << '\n';
}
 
int main() {
    ZTMYACANESOCUTE;
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
}

Submission Info

Submission Time
Task D - Transmission Mission
User Justinshao
Language C++ 20 (gcc 12.2)
Score 400
Code Size 2644 Byte
Status AC
Exec Time 102 ms
Memory 11208 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 18
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3384 KiB
00-sample-02.txt AC 1 ms 3480 KiB
00-sample-03.txt AC 1 ms 3420 KiB
01-01.txt AC 1 ms 3472 KiB
01-02.txt AC 1 ms 3460 KiB
01-03.txt AC 1 ms 3432 KiB
01-04.txt AC 1 ms 3528 KiB
01-05.txt AC 1 ms 3612 KiB
01-06.txt AC 1 ms 3484 KiB
01-07.txt AC 44 ms 11112 KiB
01-08.txt AC 44 ms 11208 KiB
01-09.txt AC 76 ms 11036 KiB
01-10.txt AC 57 ms 10060 KiB
01-11.txt AC 79 ms 11164 KiB
01-12.txt AC 55 ms 9264 KiB
01-13.txt AC 102 ms 11168 KiB
01-14.txt AC 63 ms 9708 KiB
01-15.txt AC 79 ms 11164 KiB