Submission #853910

#TimeUsernameProblemLanguageResultExecution timeMemory
853910ventusliberumStove (JOI18_stove)C++17
100 / 100
17 ms2528 KiB
/** * title: Stove **/ #include <bits/stdc++.h> using namespace std; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { auto sep = ""; for (auto &x : v) os << exchange(sep, " ") << x; return os; } template <class T> vector<T> &operator+=(vector<T> &v, const T &a) { for (auto &x : v) x += a; return v; } template <class T> vector<T> &operator-=(vector<T> &v, const T &a) { for (auto &x : v) x -= a; return v; } template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); } template <class T, class U> inline bool chmin(T &a, const U &b) { return (b < a ? a = b, 1 : 0); } #define si(x) int(x.size()) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define fi first #define se second using ll = long long; constexpr int inf = 1001001001; constexpr long long infll = 4004004004004004004LL; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int> T(N); cin >> T; vector<int> V; for (int i = 0; i + 1 < N; i++) { V.push_back(T[i + 1] - T[i] - 1); } sort(all(V)); int ans = N; for (int i = 0; i < N - K; i++) { ans += V[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...