Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,k;cin>>n>>k;
  vector<int> a(n);rep(i,n)cin>>a[i];
  sort(all(a));

  int all = 0;
  rep(i,k)all += a[i];
  print(all);
  return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,k;cin>>n>>k;
  vector<int> a(n);rep(i,n)cin>>a[i];
  sort(all(a));

  int all = 0;
  rep(i,k)all += a[i];
  print(all);
  return 0;
}


Compiler output:
a.cc:92:11: error: redefinition of 'const int INF'
   92 | const int INF = 1e9+7;
      |           ^~~
a.cc:31:11: note: 'const int INF' previously defined here
   31 | const int INF = 1e9+7;
      |           ^~~
a.cc:93:10: error: redefinition of 'const ll INFL'
   93 | const ll INFL = 9*1e18;
      |          ^~~~
a.cc:32:10: note: 'const ll INFL' previously defined here
   32 | const ll INFL = 9*1e18;
      |          ^~~~
a.cc:98:11: error: redefinition of 'const int dx [8]'
   98 | const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
      |           ^~
a.cc:37:11: note: 'const int dx [8]' previously defined here
   37 | const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
      |           ^~
a.cc:99:11: error: redefinition of 'const int dy [8]'
   99 | const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};
      |           ^~
a.cc:38:11: note: 'const int dy [8]' previously defined here
   38 | const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};
      |           ^~
a.cc:101:11: error: redefinition of 'll digit(ll)'
  101 | ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
      |           ^~~~~
a.cc:40:11: note: 'll digit(ll)' previously defined here
   40 | ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
      |           ^~~~~
a.cc:102:33: error: redefinition of 'template<class T> void print(T&&)'
  102 | template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
      |                                 ^~~~~
a.cc:41:33: note: 'template<class T> void print(T&&)' previously declared here
   41 | template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
      |                                 ^~~~~
a.cc:103:30: error: redefinition of 'template<class T> T SUM(std::vector<_Tp>)'
  103 | template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
      |                              ^~~
a.cc:42:30: note: 'template<class T> T SUM(std::vector<_Tp>)' previously declared here
   42 | template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
      |                              ^~~
a.cc:104:30: error: redefinition of 'template<class T> T digitSum(T)'
  104 | template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
      |                              ^~~~~~~~
a.cc:43:30: note: 'template<class T> T digitSum(T)' previously declared here
   43 | template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
      |                              ^~~~~~~~
a.cc:105:30: error: redefinition of 'template<class T> T gcd(T, T)'
  105 | template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
      |                              ^~~
a.cc:44:30: note: 'template<class T> T gcd(T, T)' previously declared here
   44 | template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
      |                              ^~~
a.cc:106:30: error: redefinition of 'template<class T> T lcm(T, T)'
  106 | template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
      |                              ^~~
a.cc:45:30: note: 'template<class T> T lcm(T, T)' previously declared here
   45 | template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
      |                              ^~~
a.cc:107:30: error: redefinition of 'template<class T> T power(T, T)'
  107 | template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
      |                              ^~~~~
a.cc:46:30: note: 'template<class T> T power(T, T)' previously declared here
   46 | template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
      |                              ^~~~~
a.cc:108:31: error: redefinition of 'template<class T> bool chmax(T&, T)'
  108 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:47:31: note: 'template<class T> bool chmax(T&, T)' previously declared here
   47 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:109:31: error: redefinition of 'template<class T> bool chmin(T&, T)'
  109 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:48:31: note: 'template<class T> bool chmin(T&, T)' previously declared here
   48 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:110:5: error: redefinition of 'int ctoi(char)'
  110 | int ctoi(char c){return c-'0';}
      |     ^~~~
a.cc:49:5: note: 'int ctoi(char)' previously defined here
   49 | int ctoi(char c){return c-'0';}
      |     ^~~~
a.cc:113:5: error: redefinition of 'int main()'
  113 | int main() {
      |     ^~~~
a.cc:52:5: note: 'int main()' previously defined here
   52 | int main() {
      |     ^~~~