গুদামে বিভিন্ন দৈর্ঘ্যের nটা দড়ি আছে। রফি সব দড়ি জোড়া দিয়ে একটা লম্বা দড়ি বানাবে। দুইটা দড়ি জোড়া দিলে খরচ হয় তাদের দৈর্ঘ্যের যোগফল, আর নতুন দড়ির দৈর্ঘ্যও সেই যোগফল। সব দড়ি জোড়া দিতে মোট খরচ কত হওয়া উচিত সর্বনিম্ন?
যেমন 4 3 2 6: 2+3=5 (খরচ ৫), 5+4=9 (খরচ ৯), 9+6=15 (খরচ ১৫) — মোট 29।
প্রথম লাইনে n; দ্বিতীয় লাইনে nটি দৈর্ঘ্য।
সর্বনিম্ন মোট খরচ এক লাইনে।
Write your solution, test it against custom input, then submit for a real verdict.
Your submissions, verdicts, drafts and contest score are tied to your account. Registration is free.
1 <= n <= 200000
1 <= length_i <= 10^9
4 4 3 2 6
29
5 1 1 1 1 1
12