結果
問題 |
No.156 キャンディー・ボックス
|
ユーザー |
![]() |
提出日時 | 2018-10-05 20:52:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 438 bytes |
コンパイル時間 | 1,347 ms |
コンパイル使用メモリ | 172,712 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 16:23:25 |
合計ジャッジ時間 | 2,183 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:21:13: warning: 'rel' may be used uninitialized [-Wmaybe-uninitialized] 21 | cout << rel << endl; | ^~~ main.cpp:12:9: note: 'rel' was declared here 12 | int rel; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin >> n >> m; vector<int> C; for(int i=0; i < n; i++){ int x; cin >> x; C.push_back(x); } sort(C.begin(), C.end()); int sum=0; int rel; for(int i=0; i < n; i++){ sum += C[i]; if(sum >= m){ rel = i; if(sum == m) rel += 1; break; } } cout << rel << endl; }