Submission #545508

#TimeUsernameProblemLanguageResultExecution timeMemory
545508MohamedAliSaidaneStove (JOI18_stove)C++14
100 / 100
25 ms3212 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpi; typedef vector<pll> vpl; #define pb push_back #define popb pop_back #define pf push_front #define popf pop_front #define all(x) (x).begin(),(x).end() #define ff first #define ss second int nx[4] = {0,0,1,-1}, ny[4] = {1,-1,0,0}; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} int n, k; vll A; void solve() { cin >> n >> k; A.assign(n,0); for(int i = 0; i < n ; i ++) cin >> A[i]; sort(all(A)); vll B; for(int i = 0; i < n - 1; i ++) B.pb(A[i+1] - A[i]); sort(all(B)); ll ans = n; for(int i = 1; i <= n - k; i ++) ans += B[i-1]-1; cout << ans ; } int main() { ios::sync_with_stdio(false); int tt = 1; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...