-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path34B.cpp
More file actions
45 lines (37 loc) · 734 Bytes
/
34B.cpp
File metadata and controls
45 lines (37 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void solve() {
ll m , n;
cin>>n>>m;
ll sum = 0;
vector<ll>price(n);
for(ll i = 0 ; i < n ;i++){
cin>>price[i];
}
sort(price.begin() , price.end());
for(int i = 0 ; i < n ;i++){
if(price[i] < 0){
sum+=price[i];
m--;
}
if(m == 0){
break;
}
}
cout<<-sum<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}