complete 1183.cpp 1190.cpp 1929.cpp

This commit is contained in:
2026-07-10 15:25:46 +09:00
parent 1a69d9b1e9
commit 5d8efe99be
3 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#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<u64>(n);
for (let &l: lengths) {
cin >> l;
}
let gt = std::greater<u64>();
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;
}