Problem:
Score : 200 points

Problem Statement

A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)

Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.

Constraints

1 \leq K \leq N \leq 1000

1 \leq p_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 p_2 \ldots p_N

Output

Print an integer representing the minimum possible total price of fruits.

Sample Input 1

5 3
50 100 80 120 80

Sample Output 1

210

This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.

The minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.

Sample Input 2

1 1
1000

Sample Output 2

1000

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

/*
 * Author: Pranayhalo
 * Time: 2020-06-26 22:53:59
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vvi = vector<vi>; //vector<vector<int>>
using vvll = vector<vll>;
using vs = vector<string>;

const int INF = 1 << 30;
const int MAX_N = 100000 + 5;
const int MAX_L = 20; // ~ Log N
const ll MOD = 1e9 + 7;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};

#define PI 3.14159265
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend() 
#define sz(x) (int)((x).size())
#define arrsz(x) (int) (sizeof((x))/sizeof((x)[0]))

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)
#define toDigit(x) ((int)((x)-'0'))

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)


/* Usage: dbg(a, b) */
void dbg_out() { cout << endl; }
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef PD
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#define dbgn(...) dbg_out(__VA_ARGS__)
#else
#define dbg(x...)
#define dbgn(...) 
#endif

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

/* Usage: output_vector(solution), which prints elements with spaces and then new line*/
template<typename T>
void output_vector(const vector<T> &v, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        cout << v[i] << " ";
    cout << endl;
}

/* (x, y) point structure */
template <typename T>
struct Point {
    T x, y;
    
    Point(T _x, T _y) : x(_x), y(_y) {}
    
    friend ostream& operator<<(ostream& os, const Point& p) {
        return os << "(" << p.x << ", " << p.y << ")";
    }
};

/* floor(log2(x)) */
int bit(int x) { return 31-__builtin_clz(x); }

/* division of a by b rounded up, assumes b > 0 */
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); }

/* Calculate A^B mod M. Time Complexity: O(logB) */
ll qexp(ll A, ll B, ll M) {
    if (B == 0) return 1;
    ll half = qexp(A, B/2, M) % M;
    half *= half;
    half %= M;
    if (B % 2 == 1) half *= A; 
    return half % M;
}

/* Custom comparator template for sorting */
struct Compare {
    bool operator()(pair<int, int> const & a, pair<int, int> const & b) { 
        if (a.fi != b.fi) {
            return a.fi < b.fi;
        }
        return a.se > b.se; 
    }
};

void run_case() {
    int n, k;
    cin >> n >> k;
    vi elems(n, 0);
    F0R(i, n) cin >> elems[i];

    sort(all(elems));

    ll total = 0;
    F0R(i, k) {
        total += elems[i];
    }
    cout << total << endl;
    
}

int main() {
    setIO();
    int tests = 1; //cin >> tests;
    while(tests--) {
        run_case();
        dbgn();
    }
}

/**
Remember to check for overflow (long long)
Does number need to be greater than a lower bound?
**/