結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー hogeover30
提出日時 2015-02-27 00:09:33
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 316 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 457 ms
コンパイル使用メモリ 61,680 KB
最終ジャッジ日時 2026-05-10 04:11:22
合計ジャッジ時間 1,568 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:8:9: error: 'vector' was not declared in this scope
    8 |         vector<int> c(n);
      |         ^~~~~~
main.cpp:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:8:16: error: expected primary-expression before 'int'
    8 |         vector<int> c(n);
      |                ^~~
main.cpp:9:21: error: 'c' was not declared in this scope
    9 |         for(int& v: c) cin>>v;
      |                     ^
main.cpp:10:20: error: 'c' was not declared in this scope
   10 |         sort(begin(c), end(c));
      |                    ^

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    while (cin>>n>>m) {
        vector<int> c(n);
        for(int& v: c) cin>>v;
        sort(begin(c), end(c));
        for(int i=1;i<n;++i) c[i]+=c[i-1];
        cout<<upper_bound(begin(c), end(c), m)-begin(c)<<endl;
    }
}
0