結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2019-11-21 11:40:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 409 bytes |
コンパイル時間 | 1,572 ms |
コンパイル使用メモリ | 172,600 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-09 13:50:42 |
合計ジャッジ時間 | 2,573 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 24 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:23:15: warning: 'last' may be used uninitialized [-Wmaybe-uninitialized] 23 | cout << ans-last << endl; | ^~~~ main.cpp:17:7: note: 'last' was declared here 17 | int last; | ^~~~
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int l,n; cin >> l >> n; vector<int> w(n); for(int i=0;i<n;i++){ cin >> w[i]; } if(accumulate(w.begin(),w.end(),0)<=l){ cout << n << endl; return 0; } sort(w.begin(),w.end()); int ans =0; int last; while(ans<l){ last = w.back(); w.pop_back(); ans += last; } cout << ans-last << endl; return 0; }