Submission #501654

#TimeUsernameProblemLanguageResultExecution timeMemory
501654dnauxStove (JOI18_stove)C++17
100 / 100
21 ms3200 KiB
#include <bits/stdc++.h> #define endline "\n" #define pb push_back #define mp make_pair #define st first #define nd second #define lsb(i) i&(-i) #define sz(i) (int)i.size() typedef long long ll; using namespace std; const ll INF = 1e18L; constexpr int mod = int(1e9) + 7; ll t=1, n, k, cases = 0; void solve(){ cin >> n >> k; vector<ll> ar(n),sortar; for(int i = 0; i < n; i++)cin >> ar[i]; for(int i = 0; i < n - 1; i++){ sortar.pb(ar[i + 1] - ar[i] - 1); } sort(sortar.begin(),sortar.end()); ll ans = n; for(int i = 0; i < n - k; i++){ ans += sortar[i]; } cout << ans; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); //cin>>t; for(; cases < t; cases++)solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...