// Header {{{ // includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // }}} using namespace std; // consts {{{ static const int INF = 1e9; static const double PI = acos(-1.0); static const double EPS = 1e-10; // }}} // typedefs {{{ typedef long long int LL; typedef unsigned long long int ULL; typedef vector VI; typedef vector VVI; typedef vector VLL; typedef vector VVLL; typedef vector VULL; typedef vector VVULL; typedef vector VD; typedef vector VVD; typedef vector VB; typedef vector VVB; typedef vector VC; typedef vector VVC; typedef vector VS; typedef vector VVS; typedef pair PII; typedef complex P; // }}} // macros & inline functions {{{ // syntax sugars {{{ #define FOR(i, b, e) for (int i = (b); i < (e); ++i) #define FORI(i, b, e) for (int i = (b); i <= (e); ++i) #define REP(i, n) FOR(i, 0, n) #define REPI(i, n) FORI(i, 0, n) #define OPOVER(_op, _type) inline bool operator _op (const _type &t) const // }}} // conversion {{{ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // }}} // array and STL {{{ #define ARRSIZE(a) ( sizeof(a) / sizeof(a[0]) ) #define F first #define S second #define MP(a, b) make_pair(a, b) #define PB(e) push_back(e) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) // }}} // for readable code {{{ #define EVEN(n) (n % 2 == 0) #define ODD(n) (!EVEN(n)) // }}} // debug {{{ #define arrsz(a) ( sizeof(a) / sizeof(a[0]) ) #define dprt(fmt, ...) if (opt_debug) { fprintf(stderr, fmt, ##__VA_ARGS__); } #define darr(a) if (opt_debug) { copy( (a), (a) + arrsz(a), ostream_iterator(cerr, " ") ); cerr << endl; } #define darr_range(a, f, t) if (opt_debug) { copy( (a) + (f), (a) + (t), ostream_iterator(cerr, " ") ); cerr << endl; } #define dvec(v) if (opt_debug) { copy( ALL(v), ostream_iterator(cerr, " ") ); cerr << endl; } #define darr2(a) if (opt_debug) { FOR(__i, 0, (arrsz(a))){ darr( (a)[__i] ); } } #define WAIT() if (opt_debug) { string _wait_; cerr << "(hit return to continue)" << endl; getline(cin, _wait_); } #define dump(x) if (opt_debug) { cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; } #define dumpl(x) if (opt_debug) { cerr << " [L" << __LINE__ << "] " << #x << endl << (x) << endl; } #define dumpf() if (opt_debug) { cerr << __PRETTY_FUNCTION__ << endl; } // ostreams {{{ // complex template ostream& operator<<(ostream& s, const complex& d) { return s << "(" << d.real() << ", " << d.imag() << ")"; } // pair template ostream& operator<<(ostream& s, const pair& d) { return s << "(" << d.first << ", " << d.second << ")"; } // vector template ostream& operator<<(ostream& s, const vector& d) { int len = d.size(); REP(i, len) { s << d[i]; if (i < len - 1) s << "\t"; } return s; } // 2 dimentional vector template ostream& operator<<(ostream& s, const vector< vector >& d) { int len = d.size(); REP(i, len) { s << d[i] << endl; } return s; } // map template ostream& operator<<(ostream& s, const map& m) { s << "{" << endl; for (auto itr = m.begin(); itr != m.end(); ++itr) { s << "\t" << (*itr).first << " : " << (*itr).second << endl; } s << "}" << endl; return s; } // }}} // }}} // }}} // string manipulation {{{ inline VS split(string s, char delimiter) { VS v; string t; REP(i, s.length()) { if (s[i] == delimiter) v.PB(t), t = ""; else t += s[i]; } v.PB(t); return v; } inline string join(VS s, string j) { string t; REP(i, s.size()) { t += s[i] + j; } return t; } // }}} // geometry {{{ #define Y real() #define X imag() // }}} // 2 dimentional array {{{ P dydx4[4] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1) }; P dydx8[8] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1), P(-1, 1), P(1, 1), P(1, -1), P(-1, -1) }; int g_height, g_width; bool in_field(P p) { return (0 <= p.Y && p.Y < g_height) && (0 <= p.X && p.X < g_width); } // }}} // }}} bool opt_debug = false; #define PRINT(s) cout << (s) << endl int main(int argc, char** argv) { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; VI c(n); int sum = 0; REP(i, n) { cin >> c[i]; sum += c[i]; } if (sum <= m) { cout << n << endl; return 0; } SORT(c); int tmpsum = 0; int size = c.size(); REP(i, size) { tmpsum += c[i]; if (tmpsum > m) { cout << i << endl; return 0; } else if (tmpsum == m) { cout << i + 1 << endl; return 0; } } cout << n << endl; return 0; }