結果

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

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int L;
	int N;
	vector<int> v;
	scanf("%d", &L);
	scanf("%d", &N);
	while(N--) {
		int w;
		scanf("%d", &w);
		v.push_back(w);
	}

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

	int sum = 0;
	for(int i = 0; i < v.size(); i++) {
		sum += v[i];
		if(sum >= L) {
			printf("%d\n", i);
			break;
		}
	}
}
0