結果

問題 No.5 数字のブロック
ユーザー Microbe
提出日時 2017-03-14 11:30:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 576 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 161,904 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 10:57:25
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         scanf("%d %d", &L, &N);
      |         ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |                 scanf("%d", &w);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>  

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int L, N;
vector<int> W;

int main(){
	scanf("%d %d", &L, &N);
	rep(i, N) {
		int w;
		scanf("%d", &w);
		W.push_back(w);
	}
	sort(W.begin(), W.end());
	int cnt = 0, now = 0;
	rep(i, N) {
		if(now + W[i] > L) break;
		now += W[i];
		++cnt;
	}
	printf("%d\n", cnt);
	return 0;
}
0