Advertisement
jakaria_hossain

codeforce - sale

Apr 3rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement