結果

問題 No.5 数字のブロック
ユーザー shialt
提出日時 2015-01-13 20:06:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 405 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 64,448 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 22:17:02
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d", &width);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf("%d", &block[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;

int main(void)
{
	int width, N, riz;

	scanf("%d", &width);
	scanf("%d", &N);

	vector<int> block(N);

	for(int i = 0; i < N; i++)
		scanf("%d", &block[i]);

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

	for(riz = 0; (riz < N) && (width > 0); riz++)
		width -= block[riz];

	if(width < 0)
		riz--;

	printf("%d\n", riz);

	return 0;
}
0