Submission #1010226

#TimeUsernameProblemLanguageResultExecution timeMemory
1010226baotoan655Stove (JOI18_stove)C++14
100 / 100
15 ms2300 KiB
#include <bits/stdc++.h> #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) #define ll long long #define fi first #define se second using namespace std; const int N = 1e5 + 5; int n, k; int t[N], d[N]; void solve(int tc) { cin >> n >> k; FOR(i, 1, n) cin >> t[i]; FOR(i, 1, n - 1) d[i] = t[i + 1] - (t[i] + 1); int ans = t[n] + 1 - t[1]; sort(d + 1, d + n, greater<int>()); for(int i = 1; i < k; ++i) { ans -= d[i]; } cout << ans; return; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for(int i = 1; i <= tc; ++i) solve(tc); return (0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...