{"id":4569,"date":"2018-12-27T14:07:25","date_gmt":"2018-12-27T11:07:25","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4569"},"modified":"2018-12-27T18:08:43","modified_gmt":"2018-12-27T15:08:43","slug":"e-olymp-1228-%d0%b4%d0%be%d0%b1%d0%b0%d0%b2%d0%b8%d1%82%d1%8c-%d0%b2%d1%81%d0%b5","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4569","title":{"rendered":"e-olymp 1228. \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435"},"content":{"rendered":"<h1>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h1>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0412\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430. \u041d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0441\u043b\u0438 \u0412\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0441\u044f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C\/C++ \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0447\u0438\u0441\u0435\u043b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043d\u0435\u0441\u0435\u043c \u0432 \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u0442\u0442\u0435\u043d\u043e\u043a \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0412\u0432\u0435\u0434\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0447\u0438\u0441\u0435\u043b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0440\u0430\u0432\u043d\u044b\u043c \u0438\u0445 \u0441\u0443\u043c\u043c\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 $1$ \u0438 $10$ \u0441\u0442\u043e\u0438\u0442 $11$. \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f $1,2$ \u0440\u0430\u0432\u043d\u0430 $3$. \u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ol>\n<li>$1 + 2 = 3$ (\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c = 3), $3 + 3 = 6$ (\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c = 6), \u0412\u0441\u0435\u0433\u043e = 9 <\/li>\n<li>$1 + 3 = 4$ (\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c = 4), $2 + 4 = 6$ (\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c = 6), \u0412\u0441\u0435\u0433\u043e = 10 <\/li>\n<li>$2 + 3 = 5$ (\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c = 5), $1 + 5 = 6$ (\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c = 6), \u0412\u0441\u0435\u0433\u043e = 11 <\/li>\n<\/ol>\n<p>\u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0412\u044b \u043f\u043e\u043d\u044f\u043b\u0438 \u0412\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0430\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u0445 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u044b\u043b\u0430 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0430\u044f.\n<\/p>\n<h2>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c $n (2 \\leq n \\leq 100000)$, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0442 $n$ \u0446\u0435\u043b\u044b\u0445 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b (\u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 $100000$).<\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<h2>\u0422\u0435\u0441\u0442\u044b<\/h2>\n<table>\n<tr>\n<td><strong> \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 <\/strong> <\/td>\n<td> <strong> \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 <\/strong> <\/td>\n<\/tr>\n<tr>\n<td> $4$<br \/>\n$10$ $12$ $13$ $11$ <\/td>\n<td> $92$<\/td>\n<\/tr>\n<tr>\n<td> $5$<br \/>\n$100$ $11$ $8$ $30$ $12$ <\/td>\n<td> $272$<\/td>\n<\/tr>\n<tr>\n<td> $4$<br \/>\n$2$ $2$ $2$ $2$ <\/td>\n<td> $16$<\/td>\n<\/tr>\n<tr>\n<td> $6$<br \/>\n$1$ $2$ $3$ $4$ $5$ $6$ <\/td>\n<td> $51$<\/td>\n<\/tr>\n<\/table>\n<h2>\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<pre class=\"lang:java decode:true \">import java.util.PriorityQueue;\r\nimport java.util.Scanner;\r\n\r\npublic class Main{\r\n\r\n    public static void main(String[] args) {\r\n        PriorityQueue&lt;Long&gt; nums = new PriorityQueue&lt;Long&gt;();\r\n        Scanner sc = new Scanner(System.in);\r\n        long n = sc.nextLong();\r\n        for (int i = 0; i &lt; n; i++) {\r\n            long number = sc.nextLong();\r\n            nums.add(number);\r\n        }\r\n\r\n        long minSum = 0;\r\n        long a;\r\n        long b;\r\n        while (!nums.isEmpty()) {\r\n            \r\n            a = nums.poll();\r\n                     \r\n            if (nums.isEmpty()) {\r\n                break;\r\n            }\r\n            b = nums.poll();\r\n            minSum += a + b;            \r\n            nums.add(a + b);\r\n\r\n        }\r\n        System.out.println(minSum);\r\n\r\n    }\r\n}\r\n<\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b \u0431\u0443\u0434\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439, \u0435\u0441\u043b\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 $A$, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u044f\u0434\u0430 \u0447\u0438\u0441\u0435\u043b \u0438 \u0443\u0436\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u00ab\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0445 \u0441\u0443\u043c\u043c\u00bb. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433 \u0446\u0438\u043a\u043b\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 $A$ \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043d\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0445 \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $minSum$ \u0431\u0443\u0434\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u043e, \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043d\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f $minSum$ \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b.<br \/>\n\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e $A$ \u0432 \u0432\u0438\u0434\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p><a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/1228\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 e-olymp.com<\/a><br \/>\n<a href=\"https:\/\/ideone.com\/wo6m1q\" rel=\"noopener\" target=\"_blank\">\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 ideone.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0412\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430. \u041d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0441\u043b\u0438 \u0412\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0441\u044f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C\/C++ \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0447\u0438\u0441\u0435\u043b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043d\u0435\u0441\u0435\u043c \u0432 \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u0442\u0442\u0435\u043d\u043e\u043a \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0412\u0432\u0435\u0434\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0447\u0438\u0441\u0435\u043b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0440\u0430\u0432\u043d\u044b\u043c \u0438\u0445 \u0441\u0443\u043c\u043c\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 $1$ \u0438 $10$ \u0441\u0442\u043e\u0438\u0442 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4569\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":118,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107,110,106],"tags":[424,210],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4569"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/118"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4569"}],"version-history":[{"count":1,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4569\/revisions"}],"predecessor-version":[{"id":4570,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4569\/revisions\/4570"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}