結果
問題 | No.5 数字のブロック |
ユーザー | CQA11015 |
提出日時 | 2021-07-16 12:15:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 457 bytes |
コンパイル時間 | 680 ms |
コンパイル使用メモリ | 74,800 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 20:02:51 |
合計ジャッジ時間 | 1,703 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> // #include <bits/stdc++.h> using namespace std; int main() { int l,n; cin >> l >> n; vector<int> w(n); int sum=0, count=0; for (int i = 0; i < n; i++) { cin >> w.at(i); } sort(w.begin(),w.end()); for (int i = 0; i < n; i++) { if (sum + w.at(i) <= l) { sum += w.at(i); count++; } else break; } cout << count << endl; return 0; }