From 5d8efe99be641d3822a5c6f044372188a1609a8d Mon Sep 17 00:00:00 2001 From: yenru0 Date: Fri, 10 Jul 2026 15:25:46 +0900 Subject: [PATCH] complete 1183.cpp 1190.cpp 1929.cpp --- storage/jungol/cpp/completed/1183.cpp | 88 +++++++++++++++++++++++++++ storage/jungol/cpp/completed/1190.cpp | 52 ++++++++++++++++ storage/jungol/cpp/completed/1929.cpp | 47 ++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 storage/jungol/cpp/completed/1183.cpp create mode 100644 storage/jungol/cpp/completed/1190.cpp create mode 100644 storage/jungol/cpp/completed/1929.cpp diff --git a/storage/jungol/cpp/completed/1183.cpp b/storage/jungol/cpp/completed/1183.cpp new file mode 100644 index 0000000..c6658df --- /dev/null +++ b/storage/jungol/cpp/completed/1183.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +#define let auto +#define fn auto +using namespace std; + +typedef size_t usize; +typedef ssize_t isize; +typedef int32_t i32; +typedef u_int32_t u32; +typedef int64_t i64; +typedef u_int64_t u64; + +fn fastio() { + ios::sync_with_stdio(false); + cin.tie(nullptr); +} + +struct State { + usize curr; + usize w; + vector pays; +}; + +fn main() -> int { + fastio(); + const usize N = 6; + let coins = vector{500, 100, 50, 10, 5, 1}; + let counts = vector(N); + + usize w; + cin >> w; + + for (let &v: counts) { + cin >> v; + } + + let stack = vector(); + let maxpays = vector(N, 0); + let maxtotal = (u64) 0; + stack.push_back({N - 1, w, vector(N, 0)}); + while (!stack.empty()) { + let now = stack.back(); + stack.pop_back(); + + let curr = now.curr; + if (curr == 0) { + if (now.w % coins[curr] != 0) { + continue; + } else { + now.pays[curr] = now.w / coins[curr]; + u64 total = accumulate(now.pays.begin(), now.pays.end(), 0); + if (total > maxtotal) { + maxpays = now.pays; + maxtotal = total; + } + } + + } else { + let rem = now.w % coins[curr - 1] / coins[curr]; + let delta = coins[curr - 1] / coins[curr]; + if (counts[curr] < rem) { + continue; + } + let maxto = (counts[curr] - rem) / delta; + + for (usize i = 0; i <= maxto; i++) { + let cst = (i * delta + rem) * coins[curr]; + if (cst > now.w) { + break; + } + let newpay = now.pays; + newpay[curr] = i * delta + rem; + stack.push_back({curr - 1, now.w - cst, newpay}); + } + } + } + + cout << maxtotal << endl; + for (let p: maxpays) { + cout << p << " "; + } + cout << endl; +} \ No newline at end of file diff --git a/storage/jungol/cpp/completed/1190.cpp b/storage/jungol/cpp/completed/1190.cpp new file mode 100644 index 0000000..70eb7b7 --- /dev/null +++ b/storage/jungol/cpp/completed/1190.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +#define let auto +#define fn auto +using namespace std; + +typedef size_t usize; +typedef ssize_t isize; +typedef int32_t i32; +typedef u_int32_t u32; +typedef int64_t i64; +typedef u_int64_t u64; + +fn fastio() { + ios::sync_with_stdio(false); + cin.tie(nullptr); +} + +fn main() -> int { + fastio(); + + usize n; + cin >> n; + let lengths = vector(n); + for (let &l: lengths) { + cin >> l; + } + + let gt = std::greater(); + + make_heap(lengths.begin(), lengths.end(), gt); + + u64 cost = 0; + while (lengths.size() > 1) { + pop_heap(lengths.begin(), lengths.end(), gt); + let a = lengths.back(); + lengths.pop_back(); + + pop_heap(lengths.begin(), lengths.end(), gt); + let b = lengths.back(); + lengths.pop_back(); + + cost += a + b; + lengths.push_back(a + b); + push_heap(lengths.begin(), lengths.end(), gt); + } + + cout << cost << endl; +} \ No newline at end of file diff --git a/storage/jungol/cpp/completed/1929.cpp b/storage/jungol/cpp/completed/1929.cpp new file mode 100644 index 0000000..d9c36f8 --- /dev/null +++ b/storage/jungol/cpp/completed/1929.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#define let auto +#define fn auto +#define usize size_t +using namespace std; + +fn fastio() { + ios::sync_with_stdio(false); + cin.tie(nullptr); +} + +fn main() -> int { + fastio(); + + + usize n; + cin >> n; + let lengths = vector(n); + for (let &l: lengths) { + cin >> l; + } + + let gt = std::greater(); + + make_heap(lengths.begin(), lengths.end(), gt); + + usize cost = 0; + while (lengths.size() > 1) { + pop_heap(lengths.begin(), lengths.end(), gt); + let a = lengths.back(); + lengths.pop_back(); + + pop_heap(lengths.begin(), lengths.end(), gt); + let b = lengths.back(); + lengths.pop_back(); + + cost += a + b; + lengths.push_back(a + b); + push_heap(lengths.begin(), lengths.end(), gt); + } + + cout << cost << endl; +} \ No newline at end of file