Submission #139536

#TimeUsernameProblemLanguageResultExecution timeMemory
139536meatrowStove (JOI18_stove)C++17
100 / 100
26 ms2172 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int mod = 998244353; ll binpow(ll a, ll p) { ll res = 1; while (p) { if (p & 1) { (res *= a) %= mod; } p >>= 1; (a *= a) %= mod; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n); vector<int> dif(n - 1); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) { dif[i - 1] = a[i] - a[i - 1] - 1; } } int ans = n; sort(dif.begin(), dif.end()); for (int i = 0; i < n - k; i++) { ans += dif[i]; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...