April Fools' Problem (easy) (Codeforces 802M)
Tags: Greedy, sortings

The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal.However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools!

Input: The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104).

Output: Output one number.


Sample Inputs:
8 5
1 1 1 1 1 1 1 1

10 3
16 8 2 4 512 256 32 128 64 1

5 1
20 10 50 30 46

6 6
6 6 6 6 6 6

1 1
100

Sample Outputs:
5

7

10

36

100

Solution (Python):
(a, b) = map(int, input().split())
t = [int(i) for i in input().split()]
count = 0
t.sort()
for i in range(b):
    count += t[i]
print(count)

Solution (Python):
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a = sorted(a)
sum = 0
for i in range(0, k):
    sum += a[i]
print(sum)

Solution (Python):
import os
import sys
import collections
from io import BytesIO, IOBase
from math import ceil, floor, sqrt, factorial, inf, gcd
from string import capwords
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            (self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda : self.buffer.read().decode('ascii')
        self.readline = lambda : self.buffer.readline().decode('ascii')
sys.stdin = IOWrapper(sys.stdin)
sys.stdout = IOWrapper(sys.stdout)
input = lambda : sys.stdin.readline().rstrip('\r\n')
cout = sys.stdout.write
data = collections.Counter
queue = collections.deque
endl = lambda : sys.stdout.write('\n')
ii = lambda : int(input())
fi = lambda : float(input())
si = lambda : input().rstrip()
mi = lambda : map(int, input().split())
mf = lambda : map(float, input().split())
msi = lambda : map(str, input().strip().split(' '))
li = lambda : list(mi())
lf = lambda : list(mf())
ls = lambda : list(msi())
arrsi = lambda : list(si())
set_ii = lambda : set(li())
set_fi = lambda : set(lf())
set_si = lambda : set(input())
str_to_arr = lambda : list(input())

def ipow(x, y):
    return int(pow(x, y))

def maps(arr):
    return map(str, arr)

def push(arr, n):
    return arr.append(n)

def any_to_arr(arr, n):
    return arr.extend(str(n))

def capital_each_word(s):
    return capwords(s)

def duplicate_remover(a):
    return list(set(a))

def pop(arr, n):
    return arr.pop(n)

def delete(arr, n):
    del arr[n]
    return arr

def arr_pkg_rmv_by_index_wise(arr, n):
    arr.remove(n)

def arr_same_all_pkg_rmv(arr, n):
    return [i for i in arr if i != n]

def count(a, n):
    return a.count(n)

def dec_to_bin(n):
    return bin(n)[2:]

def YES():
    sys.stdout.write('YES\n')

def Yes():
    sys.stdout.write('Yes\n')

def yes():
    sys.stdout.write('yes\n')

def NO():
    sys.stdout.write('NO\n')

def No():
    sys.stdout.write('No\n')

def no():
    sys.stdout.write('no\n')

def NOT():
    sys.stdout.write('NOT\n')

class Solution:

    def __init__(self):
        return

    def solve(self):
        (a, b) = mi()
        arr = li()[:a]
        arr.sort()
        sys.stdout.write(f'{sum(arr[:b])}\n')
if __name__ == '__main__':
    Solution().solve()