1 solutions

  • 0
    @ 2022-3-13 21:48:37
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int N=1e5+7;
    int n,m,a[N],ans,sum;
    int main(){
    	cin>>n>>m;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    	}
    	sort(a,a+n);
    	for(int i=0;i<n;i++){
    		if(a[i]<0){
    			ans-=a[i];
    			sum++;
    		}
    		if(sum>=m)break;
    		if(a[i]>=0)break;
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    Information

    ID
    1950
    Time
    2000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    # Submissions
    32
    Accepted
    14
    Uploaded By