結果

問題 No.5 数字のブロック
ユーザー SAIKI_R_ASAIKI_R_A
提出日時 2019-05-17 14:02:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 83,668 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 05:53:56
合計ジャッジ時間 1,758 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()		
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int l;
	int n;
	cin >> l;
	cin >> n;

	vector<int> w(n);

	rep(i, n)
	{
		cin >> w[i];
	}

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

	int cnt = 0;

	for (int i = 0; i < n; i++)
	{
		if (l - w[i] >= 0)
		{
			l -= w[i];
			cnt++;
		}
		else break;
	}

	cout << cnt << endl;

}
0