結果
| 問題 | 
                            No.5 数字のブロック
                             | 
                    
| コンテスト | |
| ユーザー | 
                             IRXGCGySDjxVBhf
                         | 
                    
| 提出日時 | 2021-11-14 08:43:39 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 365 bytes | 
| コンパイル時間 | 1,653 ms | 
| コンパイル使用メモリ | 170,644 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-29 06:10:04 | 
| 合計ジャッジ時間 | 2,393 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 29 WA * 5 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:24:11: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   24 |     cout<<ans<<endl;
      |           ^~~
main.cpp:14:9: note: 'ans' was declared here
   14 |     int ans;
      |         ^~~
            
            ソースコード
#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];
    }
    sort(W.begin(),W.end());
    int c=0;
    int ans;
    for(int i=0;i<N;i++)
    {
        c+=W[i];
        if(c>L)
        {
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
}
            
            
            
        
            
IRXGCGySDjxVBhf