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