Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
- int main()
- {
- fastread()
- int n,k;;
- cin>>n>>k;
- int res[n],j=0;
- for(int i=0;i<n;i++)
- {
- int x;
- cin>>x;
- if(x<0)res[j++]=x;
- }
- sort(res,res+j);
- int sum=0;
- if(j<k)k=j;
- for(int i=0;i<k;i++)
- {
- sum-=res[i];
- //cout<<res[i]<<endl;
- }
- cout<<sum<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement