結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー Sota
提出日時 2022-05-22 21:29:22
言語 C++14
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 240µs
コード長 802 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 500 ms
コンパイル使用メモリ 106,236 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-31 19:30:52
合計ジャッジ時間 2,214 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>		//cin, cout
#include <vector>		//vector
#include <algorithm>	//sort,min,max,count
#include <string>		//string,getline, to_string
#include <cstdlib>		//abs(int)
#include <utility>		//swap, pair
#include <deque>		//deque
#include <climits>		//INT_MAX
#include <bitset>		//bitset
#include <cmath>		//sqrt, ceil. M_PI, pow, sin
#include <ios>			//fixed
#include <iomanip>		//setprecision
#include <sstream>		//stringstream

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;

	vector<int> C(N);
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}

	sort(C.begin(), C.end());

	int i = 0;
	int ans = 0;
	while (1) {
		M = M - C[i];
		if (M > 0) {
			i++;
			ans++;
		}
		else if (M == 0) {
			ans++;
			break;
		}
		else {
			break;
		}
	}

	cout << ans << endl;

	return 0;

}
0