jakaria_hossain

codeforce - sale

Apr 3rd, 2019
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. int main()
  5. {
  6. fastread()
  7. int n,k;;
  8. cin>>n>>k;
  9. int res[n],j=0;
  10. for(int i=0;i<n;i++)
  11. {
  12. int x;
  13. cin>>x;
  14. if(x<0)res[j++]=x;
  15. }
  16. sort(res,res+j);
  17. int sum=0;
  18. if(j<k)k=j;
  19. for(int i=0;i<k;i++)
  20. {
  21. sum-=res[i];
  22. //cout<<res[i]<<endl;
  23. }
  24. cout<<sum<<endl;
  25. }
RAW Paste Data