{"id":34236,"date":"2024-11-01T09:25:50","date_gmt":"2024-11-01T09:25:50","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34236"},"modified":"2024-11-01T10:58:03","modified_gmt":"2024-11-01T10:58:03","slug":"c-coding-test-course-making-the-maximum-value-by-grouping-numbers","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34236\/","title":{"rendered":"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers"},"content":{"rendered":"<article>\n<section>\n<h2>Problem Description<\/h2>\n<p>\n            You need to combine the given integers appropriately to create one maximum value while receiving multiple integers. The integers follow these rules:\n        <\/p>\n<ul>\n<li>Integers can include negative and positive values, and 0 also exists.<\/li>\n<li>Multiplying a negative with another negative creates a positive, allowing for larger numbers to be made.<\/li>\n<li>Positive numbers should only be multiplied with numbers greater than 1, otherwise, their sum will be larger. 1 is used for addition.<\/li>\n<li>0 does not affect the maximum value but can be multiplied by negative numbers.<\/li>\n<\/ul>\n<p>\n            For example, if the given integers are {1, 2, 0, -1, -2}, the maximum value would be<br \/>\n            <strong>(2 * 1) + (0) + ((-1) * (-2)) = 2 + 0 + 2 = 4<\/strong>.\n        <\/p>\n<\/section>\n<section>\n<h2>Input<\/h2>\n<p>\n            The first line contains an integer N (1 \u2264 N \u2264 100,000),<br \/>\n            and the second line contains N integers arr[i] (-1,000 \u2264 arr[i] \u2264 1,000).\n        <\/p>\n<\/section>\n<section>\n<h2>Output<\/h2>\n<p>\n            Output the maximum value of the integers in one line.\n        <\/p>\n<\/section>\n<section>\n<h2>Problem Solving Process<\/h2>\n<h3>Step 1: Reading Input<\/h3>\n<p>\n            Read the input integers and convert them into a format that the computer can understand. In C++,<br \/>\n            <code>vector<int><\/int><\/code> is used to store the integers.<br \/>\n            All values are processed by storing them in one list.\n        <\/p>\n<h3>Step 2: Separating Integers<\/h3>\n<p>\n            First, separate the integers into positive, negative, and 0. This allows for various cases<br \/>\n            to be handled efficiently. The goal is to group negative numbers to create positives,<br \/>\n            and combine positives to form the maximum value.\n        <\/p>\n<h3>Step 3: Handling Positives<\/h3>\n<p>\n            Sort the list of positive numbers and start multiplying the larger values at the end first. Only<br \/>\n            values greater than 1 should be combined, so it&#8217;s best to group with 1.\n        <\/p>\n<h3>Step 4: Handling Negatives<\/h3>\n<p>\n            Handle negatives by combining them in pairs to create the maximum value. For example,<br \/>\n            multiplying two negatives yields a positive, so they should be combined.\n        <\/p>\n<h3>Step 5: Calculating and Outputting the Result<\/h3>\n<p>\n            Ultimately, store the maximum value obtained through all combinations and output it.<br \/>\n            This process can be easily implemented using the C++ code below.\n        <\/p>\n<h3>Code Example<\/h3>\n<pre>\n            <code>\n                #include &lt;iostream&gt;\n                #include &lt;vector&gt;\n                #include &lt;algorithm&gt;\n\n                using namespace std;\n\n                int main() {\n                    int N;\n                    cin &gt;&gt; N;\n\n                    vector<int> arr(N);\n                    vector<int> positive;\n                    vector<int> negative;\n\n                    for (int i = 0; i &lt; N; i++) {\n                        cin &gt;&gt; arr[i];\n                        if (arr[i] &gt; 0) positive.push_back(arr[i]);\n                        else if (arr[i] &lt; 0) negative.push_back(arr[i]);\n                    }\n\n                    sort(positive.rbegin(), positive.rend());\n                    sort(negative.begin(), negative.end());\n\n                    long long result = 0;\n\n                    for (int i = 0; i &lt; positive.size(); i += 2) {\n                        if (i + 1 &lt; positive.size()) {\n                            result += positive[i] * positive[i + 1];\n                        } else {\n                            result += positive[i];\n                        }\n                    }\n\n                    for (int i = 0; i &lt; negative.size(); i += 2) {\n                        if (i + 1 &lt; negative.size()) {\n                            result += negative[i] * negative[i + 1];\n                        }\n                    }\n\n                    cout &lt;&lt; result &lt;&lt; endl;\n\n                    return 0;\n                }\n            <\/int><\/int><\/int><\/code>\n        <\/pre>\n<h2>Conclusion<\/h2>\n<p>\n            This problem is an important algorithmic challenge of creating maximum value from the given integers.<br \/>\n            The approach above helps to effectively solve the problem.<br \/>\n            The key is classifying integers and deriving results through appropriate mathematical operations. Additionally, learning to write code using C++&#8217;s STL can be applied to other problems as well.\n        <\/p>\n<\/section>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description You need to combine the given integers appropriately to create one maximum value while receiving multiple integers. The integers follow these rules: Integers can include negative and positive values, and 0 also exists. Multiplying a negative with another negative creates a positive, allowing for larger numbers to be made. Positive numbers should only &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34236\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, Making the Maximum Value by Grouping Numbers&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[111],"tags":[],"class_list":["post-34236","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ Coding Test Course, Making the Maximum Value by Grouping Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/34236\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Problem Description You need to combine the given integers appropriately to create one maximum value while receiving multiple integers. The integers follow these rules: Integers can include negative and positive values, and 0 also exists. Multiplying a negative with another negative creates a positive, allowing for larger numbers to be made. Positive numbers should only &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, Making the Maximum Value by Grouping Numbers&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34236\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:25:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:58:03+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34236\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34236\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers\",\"datePublished\":\"2024-11-01T09:25:50+00:00\",\"dateModified\":\"2024-11-01T10:58:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34236\/\"},\"wordCount\":365,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34236\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34236\/\",\"name\":\"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:25:50+00:00\",\"dateModified\":\"2024-11-01T10:58:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34236\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34236\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34236\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/34236\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Problem Description You need to combine the given integers appropriately to create one maximum value while receiving multiple integers. The integers follow these rules: Integers can include negative and positive values, and 0 also exists. Multiplying a negative with another negative creates a positive, allowing for larger numbers to be made. Positive numbers should only &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers\"","og_url":"https:\/\/atmokpo.com\/w\/34236\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:25:50+00:00","article_modified_time":"2024-11-01T10:58:03+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34236\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34236\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers","datePublished":"2024-11-01T09:25:50+00:00","dateModified":"2024-11-01T10:58:03+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34236\/"},"wordCount":365,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34236\/","url":"https:\/\/atmokpo.com\/w\/34236\/","name":"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:25:50+00:00","dateModified":"2024-11-01T10:58:03+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34236\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34236\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34236\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, Making the Maximum Value by Grouping Numbers"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=34236"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34236\/revisions"}],"predecessor-version":[{"id":34237,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34236\/revisions\/34237"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}