結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
gon_027
|
| 提出日時 | 2019-09-12 21:36:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 488 bytes |
| コンパイル時間 | 628 ms |
| コンパイル使用メモリ | 70,476 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-02 17:10:49 |
| 合計ジャッジ時間 | 1,940 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 14 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:31:13: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
31 | cout << ans << endl;
| ^~~
main.cpp:16:9: note: 'ans' was declared here
16 | int ans;
| ^~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int l, n;
cin >> l >> n;
int w[n];
for(int i = 0; i < n; i++){
cin >> w[i];
}
sort(w, w + n);
int ans;
int count = 0;
int num = 0;
for(int i = 0; i < n; i++){
//cout << i << endl;
num = 0;
for(int j = 0; j < i; j++){
num += w[j];
}
if(num < l){
ans = i;
}
}
cout << ans << endl;
}
gon_027