結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
gon_027
|
| 提出日時 | 2019-09-12 21:37:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 489 bytes |
| コンパイル時間 | 692 ms |
| コンパイル使用メモリ | 68,992 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 17:10:51 |
| 合計ジャッジ時間 | 2,025 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 10 |
コンパイルメッセージ
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