{"id":3850,"date":"2018-11-25T14:06:00","date_gmt":"2018-11-25T11:06:00","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=3850"},"modified":"2018-12-25T19:50:52","modified_gmt":"2018-12-25T16:50:52","slug":"e-olymp-7337-discounts","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=3850","title":{"rendered":"e-olymp 7337. Discounts"},"content":{"rendered":"<h1>Task<\/h1>\n<p>In the supermarket of electronics, if you believe in TV commercials, there is a system of discounts: from two purchased goods fully paid only the cost of a higher-value product, and the other is provided free of charge. What amount of money is enough to pay for the purchase of three goods, if the price of each is known.<\/p>\n<h1>Input data:<\/h1>\n<p>Three natural numbers [latex]a, b, c[\/latex] are prices of three products [latex]\\left(1 \u2264 a, b, \u0441 \u2264 10000\\right)[\/latex].<\/p>\n<h1>Output data:<\/h1>\n<p>Purchase cost.<\/p>\n<h1>Tests<\/h1>\n<table>\n<tr>\n<th>#<\/th>\n<th>Input data<\/th>\n<th>Output data<\/th>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>2 2 2<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>78 2 45<\/td>\n<td>80<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>452 89 88<\/td>\n<td>540<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>50 4 67<\/td>\n<td>71<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>15 37 20<\/td>\n<td>52<\/td>\n<\/tr>\n<\/table>\n<h1>Code<\/h1>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\nimport java.util.Scanner;\r\n\r\nclass Main\r\n{\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tScanner in = new Scanner(System.in);\r\n\t\tint a = in.nextInt();\r\n\t\tint b = in.nextInt();\r\n\t\tint c = in.nextInt();\r\n\t\tint s=0; \/\/ \"s\" used as an auxiliary variable to store the amount of money\r\n\t\tif (a&gt;=b&amp;&amp;a&gt;=c) {\r\n\t\t\ts=a;\r\n\t\t\tif (b&gt;=c) {\r\n\t\t\t\ts+=c;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\ts+=b;\r\n\t\t\t}\r\n\t\telse if (b&gt;=a&amp;&amp;b&gt;=c) {\r\n\t\t\ts=b;\r\n\t\t\tif (a&gt;=c) {\r\n\t\t\t\ts+=c;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\ts+=a;\r\n\t\t\t}\r\n\t\telse if (c&gt;=a&amp;&amp;c&gt;=b) {\r\n\t\t\ts=c;\r\n\t\t\tif (a&gt;=b) {\r\n\t\t\t\ts+=b;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\ts+=a;\r\n\t\t\t}\r\n\t\tSystem.out.print(s);\r\n\t}\r\n}<\/pre>\n<h1>Solution of the problem<\/h1>\n<p>Algorithm: you will have to pay the highest price, so let&#8217;s find it at first and save it in the variable  <span class=\"lang:java decode:true  crayon-inline \">s<\/span>. Next, you need to select the product for free receipt, which you put in a couple of the most expensive. To obtain the least amount of money, the remaining goods must be the cheapest.<\/p>\n<h1>Links<\/h1>\n<p>The task at <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/7337\">e-olymp<\/a><br \/>\nThe decision code at <a href=\"https:\/\/ideone.com\/MZdRH9\">ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Task In the supermarket of electronics, if you believe in TV commercials, there is a system of discounts: from two purchased goods fully paid only the cost of a higher-value product, and the other is provided free of charge. What amount of money is enough to pay for the purchase of three goods, if the &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=3850\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[456,457],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3850"}],"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\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3850"}],"version-history":[{"count":5,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3850\/revisions"}],"predecessor-version":[{"id":4282,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3850\/revisions\/4282"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}