#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // C++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include //#include #define rep(i,j,k) for(int i=(int)j;i<(int)k;i++) #define ll long long #define Sort(v) sort(all(v)) //#define INF 1e9 #define LINF (1LL<<40) #define END return 0 #define pb push_back #define se second #define fi first #define pb push_back #define all(v) (v).begin(), (v).end() #define MP make_pair #define int long long #define umap unordered_map #define re0 return 0 using namespace std; int day[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; //typedef pair P; const long long MOD=1000000007LL; bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;} bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;} bool isnumber(char c){return ('0'<=c&&c<='9');} bool isalpha(char c){return (isupper(c)||islower(c));} bool is_kaibun(string s){string rs = s;reverse(all(rs));if(s == rs)return true;else return false;} template void printv(vector v, bool is_endl=true){ for(int i=0;i void printendl(vector v){ for(auto date:v)cout< void printvv(vector> v){ for(int i=0;i split(string s, char c){ if(s[s.size()-1]!=c)s+=c; vector v; int pos=0; rep(i,0,s.size()){ if(s[i]==c){ v.push_back(s.substr(pos,i-pos)); pos=i+1; } if(i==s.size()-1 && s.substr(pos,i-pos)!="")v.push_back(s.substr(pos,i-pos)); } return v; } struct UnionFind{ vector par; UnionFind(int n){ par.assign(n,-1); } int root(int x){ if(par[x]<0)return x; else return par[x]=root(par[x]); } bool same(int a,int b){ return root(a)==root(b); } bool merge(int a,int b){ a=root(a); b=root(b); if(a==b)return false; if(par[a]>par[b])swap(a,b); par[a]+=par[b]; par[b]=a; return true; } int size(int x){ return -par[root(x)]; } }; signed main(){ int n,k; cin>>n>>k; vector v(n); rep(i,0,n)cin>>v[i]; sort(all(v)); reverse(all(v)); int ans=0; rep(i,0,k){ if(v[i]<0)break; ans+=v[i]; } cout<