Submission #684053

#TimeUsernameProblemLanguageResultExecution timeMemory
684053vjudge1Stove (JOI18_stove)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define all(a) a.begin(), a.end() typedef long long ll; typedef pair<int, int> ii; const int N = 1e5 + 5; const int mod = 1e9 + 7; int n, k; ll res, a[N], b[N]; void solve() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); res = a[n]; for(int i = 1; i < n; i++) b[i] = a[i + 1] - a[i] - 1; sort(b + 1, b + n, greater<ll>()); for(int i = 1; i < k; i++) res -= b[i]; cout << res; } signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...