結果
| 問題 | No.5 数字のブロック |
| コンテスト | |
| ユーザー |
JokoMasaya
|
| 提出日時 | 2019-01-06 16:58:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 5,000 ms |
| コード長 | 587 bytes |
| コンパイル時間 | 644 ms |
| コンパイル使用メモリ | 66,628 KB |
| 最終ジャッジ日時 | 2025-01-06 20:12:16 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:11: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
34 | cout<<ans<<endl;
| ^~~
main.cpp:10:13: note: ‘ans’ was declared here
10 | int l,n,ans,m=0;
| ^~~
ソースコード
#include <iostream>
#include <stdlib.h>
using namespace std;
int compare_int(const void *a, const void *b){
return *(int*)a - *(int*)b;
}
int main(){
int l,n,ans,m=0;
cin>>l>>n;
int w[n];
for(int i=0;i<n;i++){
cin>>w[i];
}
qsort(w, n, sizeof(int), compare_int);
for(int i=0;i<n;i++){
m+=w[i];
if(m<l&&i<n-1){
continue;
}
else if(m==l){
ans=i+1;
break;
}
else if(m>l){
ans=i;
break;
}
ans=n;
}
cout<<ans<<endl;
}
JokoMasaya