結果

問題 No.5 数字のブロック
ユーザー hachidesyu
提出日時 2019-10-29 17:48:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 747 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 65,984 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 21:33:48
合計ジャッジ時間 1,611 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//関数プロトタイプ宣言
void Input(int&, int&, vector<int>&);

int main() {
	//各パラメータ
	int L; //箱の幅
	int N; //個数
	int count = 0;
	vector<int> W; //幅の配列

	//パラメータの入力
	Input(L, N, W);

	//各幅の配列を昇順に並べる
	sort(W.begin(), W.end());

	if (N == 1) {
		if (L - W[0] >= 0) {
			count = 1;
		}
		else {
			count = 0;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			L -= W[i];
			if (L < 0) {
				break;
			}
			count++;
		}
	}

	cout << count << endl;
}

void Input(int& L, int& N, vector<int>& W) {
	int w;
	cin >> L;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> w;
		W.push_back(w);
	}
}
0