結果

問題 No.5 数字のブロック
ユーザー prog470
提出日時 2016-09-07 11:26:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 616 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 71,368 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-15 21:03:26
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 4 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	int L, N, W[10005];

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

	sort(W, W+N);

	int cnt = 0;
	long long sum = 0;
	while (1) {
		if (sum > L) {
			cnt--;
			break;
		}
		else if (sum == L) {
			break;
		}
		sum += W[cnt];	//cnt番目が入らない。cntは個数-1だから、cntをそのまま出力で合う。
		cnt++;
	}

	cout << cnt<< endl;

	return 0;
}
0