結果
問題 | No.1015 おつりは要らないです |
ユーザー |
|
提出日時 | 2020-04-23 21:44:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 1,750 ms |
コンパイル使用メモリ | 81,048 KB |
最終ジャッジ日時 | 2025-01-09 22:52:36 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> template <class T> using MaxHeap = std::priority_queue<T>; using lint = long long; const std::vector<lint> money{10000, 5000, 1000}; void solve() { int n; std::cin >> n; std::vector<lint> xs(3); for (auto& x : xs) std::cin >> x; std::reverse(xs.begin(), xs.end()); MaxHeap<lint> heap; while (n--) { lint a; std::cin >> a; heap.push(++a); } for (int i = 0; i < 3; ++i) { while (xs[i] > 0 && !heap.empty()) { auto a = heap.top(); heap.pop(); auto need = a / money[i]; if (need == 0) { --xs[i]; a = 0; } else { auto pay = std::min(xs[i], need); xs[i] -= pay; a -= money[i] * pay; } if (a > 0) heap.push(a); } } std::cout << (heap.empty() ? "Yes" : "No") << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }