Submission #1090737

#TimeUsernameProblemLanguageResultExecution timeMemory
1090737ivan_alexeevStove (JOI18_stove)C++17
100 / 100
22 ms2140 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #ifdef lisie_bimbi #else #define endl '\n' #endif typedef long long ll; const ll inf = 1'000'000'000'000'000'000; using namespace std; #pragma GCC optimize("O3") #pragma GCC target("avx,avx2,bmi2,fma,popcnt") //#define int long long void solve(){ int n, k; cin >> n >> k; vector<int> t(n); for(int i = 0; i < n; i++){ cin >> t[i]; } k--; vector<int> z(n - 1); for(int i = 0; i < n - 1; i++){ z[i] = t[i + 1] - t[i] - 1; } std::sort(z.rbegin(), z.rend()); int ans = t.back() + 1 - t[0]; for(int i = 0; i < k; i++){ ans -= z[i]; } cout << ans << endl; } signed main(){ #ifdef lisie_bimbi freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else cin.tie(nullptr)->sync_with_stdio(false); #endif cout << setprecision(5) << fixed; int _ = 1; //cin >> t; while(_--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...