結果
問題 | No.5 数字のブロック |
ユーザー |
|
提出日時 | 2016-02-09 22:29:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 521 bytes |
コンパイル時間 | 330 ms |
コンパイル使用メモリ | 44,032 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-18 08:08:43 |
合計ジャッジ時間 | 1,231 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
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); | ~~~~~^~~~~~~~~~
ソースコード
#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; bool flag = true; for(int i = 0; i < v.size(); i++) { sum += v[i]; if(sum == L) { printf("%d\n", i + 1); flag = false; break; } if(sum > L) { printf("%d\n", i); flag = false; break; } } if(flag) printf("%lu\n", v.size()); }