結果

問題 No.5 数字のブロック
ユーザー iroha168
提出日時 2016-10-29 19:21:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 422 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 62,988 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 10:22:36
合計ジャッジ時間 1,652 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define MAX 10000
int w[MAX];
int main() {
	int c = 0, i, l, n, s = 0;
	cin >> l >> n;
	for (i = 0; i < n; ++i) {
		cin >> w[i];
	}
	sort(w, w + n);
	for (i = 0; i < n; ++i) {
		if (s + w[i] <= l) {
			s += w[i];
			c++;
		}
		else {
			break;
		}
	}
	cout << c << endl;
	return 0;

}
0