Language: C++

#include "algorithm"
#include "array"
#include "cmath"
#include "complex"
#include "cstdio"
#include "deque"
#include "initializer_list"
#include "map"
#include "numeric"
#include "queue"
#include "regex"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "vector"

using std::accumulate;
using std::all_of;
using std::any_of;
using std::array;
using std::binary_search;
using std::copy;
using std::count_if;
using std::deque;
using std::fill;
using std::find_if;
using std::for_each;
using std::inner_product;
using std::lower_bound;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::next_permutation;
using std::none_of;
using std::priority_queue;
using std::queue;
using std::regex;
using std::search;
using std::set;
using std::sort;
using std::sregex_token_iterator;
using std::stable_sort;
using std::stack;
using std::string;
using std::swap;
using std::to_string;
using std::transform;
using std::unordered_map;
using std::upper_bound;
using std::vector;

#define INF 1000000000 // 10^10
#define FOR(i, n) for ((i) = 0; (i) < (n); ++(i))
#define FOR_FROM_NOT_ZERO(i, s, n) for ((i) = (s); (i) < (n); ++(i))
#define FOR_dec(i, n) for ((i) = (n); (i) >= 0; --(i))
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define d2_arr(height, width) array<array<int, (width)>, (height)>
#define d2_vec vector<vector<int>>
#define in_int(x) scanf(" %d/n", &(x));
#define in_str(x) scanf(" %[a-zA-Z 0-9_]/n", (x));
#define ch(x) printf("debag %d\n", (x))

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dx_ar[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy_ar[] = {1, 0, -1, 1, -1, 1, 0, -1};

template <typename type> void print_array_vertical(type d1_arr);
template <typename type> void print_array_horizon(type d1_arr);
template <typename type> void print_2darray(type d2_arr);
vector<vector<int>> d2_zeros(int height, int width);
vector<vector<int>> padding(vector<vector<int>> arr, int pad);
inline vector<int> str_int_split(char *s);
inline std::vector<std::vector<int>> in_d2_arr(int N, int size = 1000);
inline std::vector<int> in_d1_arr(int size = 1000);
inline double d2_distance(int x1, int y1, int x2, int y2);
inline int d2_manhattan(int x1, int y1, int x2, int y2);

int main() {
  int i, N, M, temp;
  std::vector<int> v = in_d1_arr();
  N = v[0];
  M = v[1];
  std::vector<int> tar;

  FOR(i, N) {
    in_int(temp);
    tar.push_back(temp);
  }

  sort(tar.begin(), tar.end(), std::greater<int>());
  int point = 0;

  FOR(i, 4) {
    FOR(i, N) {
      if (point + tar[i] <= M) {
        point = point + tar[i];
        break;
      }
    }
  }

  printf("%d\n", point);

  return 0;
}

template <typename type> void print_array_vertical(type d1_arr) {
  int i;
  string s;
  FOR(i, d1_arr.size()) {
    printf("%d\n", d1_arr[i]);
    fflush(stdout);
  }
}

template <typename type> void print_array_horizon(type d1_arr) {
  int i;
  FOR(i, d1_arr.size() - 1) { printf("%d ", d1_arr[i]); }
  printf("%d\n", d1_arr.back());
  fflush(stdout);
}

template <typename type> void print_2darray(type d2_arr) {
  int i, j;
  FOR(i, d2_arr.size()) {
    FOR(j, d2_arr[i].size() - 1) { printf("%d ", d2_arr[i][j]); }
    printf("%d\n", d2_arr[i].back());
    fflush(stdout);
  }
}

vector<vector<int>> d2_zeros(int height, int width) {
  vector<vector<int>> temp;
  temp.resize(height);
  int i, j;
  FOR(i, height) {
    temp[i].resize(width);
    FOR(j, width) { temp[i][j] = 0; }
  }
  return temp;
}

vector<vector<int>> padding(vector<vector<int>> arr, int pad) {
  vector<vector<int>> arr_c = arr;
  int height = arr_c.size();
  int width = arr_c[0].size();
  std::vector<int> v;
  v.resize(width);
  fill(v.begin(), v.end(), pad);
  arr_c.insert(arr_c.begin(), v);
  arr_c.push_back(v);
  int i;
  FOR(i, height + 2) {
    arr_c[i].insert(arr_c[i].begin(), pad);
    arr_c[i].resize(width + 2);
  }
  arr_c.shrink_to_fit();
  return arr_c;
}

inline vector<int> str_int_split(char *s) {
  char *tok = strtok(s, " ");
  std::vector<int> v;
  while (tok != NULL) {
    v.push_back(atoi(tok));
    tok = strtok(NULL, " "); /* 2回目以降 */
  }
  return v;
}

inline std::vector<std::vector<int>> in_d2_arr(int N, int size) {
  int i;
  std::vector<std::vector<int>> v;
  FOR(i, N) {
    char *lines;
    lines = new char[size];
    in_str(lines);
    v.push_back(str_int_split(lines));
    delete[] lines;
  }
  return v;
}

inline std::vector<int> in_d1_arr(int size) {
  std::vector<int> v;
  char *lines;
  lines = new char[size];
  in_str(lines);
  v = str_int_split(lines);
  delete[] lines;
  return v;
}

inline double d2_distance(int x1, int y1, int x2, int y2) {
  return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
}

inline int d2_manhattan(int x1, int y1, int x2, int y2) {
  return (abs(x2 - x1) + abs(y2 - y1));
}



Compiler output:
a.cc: In function 'std::vector<int> str_int_split(char*)':
a.cc:167:15: error: 'strtok' was not declared in this scope; did you mean 'strtoq'?
  167 |   char *tok = strtok(s, " ");
      |               ^~~~~~
      |               strtoq