Submission #43537

#TimeUsernameProblemLanguageResultExecution timeMemory
43537wxh010910Stove (JOI18_stove)C++14
100 / 100
27 ms10384 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back #define Debug(...) fprintf(stderr, __VA_ARGS__) typedef long long LL; typedef long double LD; typedef unsigned int uint; typedef pair <int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } template <typename T> inline bool CheckMax(T &a, const T &b) { return a < b ? a = b, true : false; } template <typename T> inline bool CheckMin(T &a, const T &b) { return a > b ? a = b, true : false; } const int N = 100005; int n, m, ans, a[N], b[N]; int main() { #ifdef wxh010910 freopen("d.in", "r", stdin); #endif Read(n), Read(m); for (int i = 1; i <= n; ++i) { Read(a[i]); } for (int i = 1; i < n; ++i) { b[i] = a[i + 1] - a[i] - 1; } sort(b, b + n); for (int i = 1; i <= n - m; ++i) { ans += b[i]; } printf("%d\n", ans + n); #ifdef wxh010910 Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...