結果

問題 No.5 数字のブロック
ユーザー hogeover30hogeover30
提出日時 2015-01-28 22:44:09
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 303 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 51,284 KB
最終ジャッジ日時 2023-08-11 07:58:59
合計ジャッジ時間 995 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:9: error: ‘vector’ was not declared in this scope
         vector<int> a(n);
         ^~~~~~
main.cpp:8:9: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:8:9:
         vector<int> a(n);
         ^~~~~~
main.cpp:8:16: error: expected primary-expression before ‘int’
         vector<int> a(n);
                ^~~
main.cpp:9:21: error: ‘a’ was not declared in this scope
         for(int& v: a) cin>>v;
                     ^
main.cpp:10:20: error: ‘a’ was not declared in this scope
         sort(begin(a), end(a));
                    ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int l, n;
    while (cin>>l>>n) {
        vector<int> a(n);
        for(int& v: a) cin>>v;
        sort(begin(a), end(a));

        int s=0, i;
        for(i=0;i<n;++i) if ((s+=a[i])>l) break;
        cout<<i<<endl;
    }
}
0