jakaria_hossain

codeforce - array splitting

Jul 23rd, 2019
120
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