Submission #221963

#TimeUsernameProblemLanguageResultExecution timeMemory
221963tselmegkhStove (JOI18_stove)C++14
100 / 100
30 ms2304 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 1e5 + 5, inf = 1e9; #define pb push_back #define mp make_pair #define ll long long #define ff first #define ss second #define all(a) a.begin(),a.end() #define sz(x) (int)x.size() typedef vector<int> vi; typedef pair<int,int> ii; typedef vector<ii> vii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n, k; cin >> n >> k; vi a(n), b; for(int i = 0; i < n; i++){ cin >> a[i]; if(i)b.pb(a[i] - a[i - 1] - 1); } ll ans = n; sort(all(b)); for(int i = 0; i < n - k; i++){ ans += b[i]; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...