結果
問題 | No.156 キャンディー・ボックス |
ユーザー |
|
提出日時 | 2019-09-05 21:31:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 610 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 171,768 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 03:17:40 |
合計ジャッジ時間 | 3,136 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:38:11: warning: 'end' may be used uninitialized [-Wmaybe-uninitialized] 38 | cout << end << endl; | ^~~ main.cpp:25:7: note: 'end' was declared here 25 | int end; | ^~~
ソースコード
/** @file 156.cpp @title No.156 キャンディー・ボックス - yukicoder @url https://yukicoder.me/problems/no/156 **/ #include <bits/stdc++.h> using namespace std; typedef long long LL; #define ALL(obj) (obj).begin(), (obj).end() #define REP(i, N) for (int i = 0; i < (N); ++i) int main() { int N; LL M; cin >> N >> M; vector<LL> C(N, 0); REP(i, N) { cin >> C[i]; } sort(ALL(C)); LL ans = 0; int end; REP(i, N) { ans += C[i]; if (M < ans) { end = i; break; } if (i == N - 1) { end = N; } } cout << end << endl; return 0; }