SHARE
TWEET

codeforce - array splitting

jakaria_hossain Jul 23rd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,k,ans,i;
  6.     cin>>n>>k;
  7.     int ara[n+1];
  8.     for(i=0;i<n;i++)cin>>ara[i];
  9.     ans= ara[n-1]-ara[0];
  10.     n--,k--;
  11.     for(i=0;i<n;i++)ara[i]=ara[i+1]-ara[i];
  12.     sort(ara,ara+n);
  13.     reverse(ara,ara+n);
  14.     for(i=0;i<k;i++)ans-=ara[i];
  15.     cout<<ans<<endl;
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top