Submission #638684

#TimeUsernameProblemLanguageResultExecution timeMemory
638684itnesStove (JOI18_stove)C++14
100 / 100
23 ms2296 KiB
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<ll,int> pli; typedef pair<int,ll> pil; typedef pair<int,int> pii; const ll INFLL=1e18+7; const int INF=1e9+7; #define pb push_back const int MAXN=1e5+7; int arr[MAXN]; int main() { ios_base::sync_with_stdio(0); int n,k; cin>>n>>k; for(int i=1;i<=n;++i) cin>>arr[i]; int total=arr[n]-arr[1]+1; vector<int> segments; for(int i=1;i<n;++i){ segments.pb(arr[i+1]-arr[i]-1); } sort(segments.begin(),segments.end()); reverse(segments.begin(),segments.end()); for(int i=0;i<k-1;++i) total-=segments[i]; cout<<total<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...