Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <queue>
- #include <functional>
- using namespace std;
- int main()
- {
- int N = 0;
- priority_queue<int, vector<int>, greater<int>> values;
- fstream iof{ "input.txt", ios::in };
- iof >> N;
- for (int i = 0; i < N; i++)
- {
- int letto;
- iof >> letto;
- values.push(letto);
- }
- iof.close();
- int cont = 0, price = 0;
- while (cont < N - 1)
- {
- int somma = values.top();
- values.pop();
- somma += values.top();
- values.pop();
- price += somma;
- values.push(somma);
- cont++;
- }
- iof.open("output.txt", ios::out);
- iof << price;
- iof.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement