{"id":34202,"date":"2024-11-01T09:25:27","date_gmt":"2024-11-01T09:25:27","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34202"},"modified":"2024-11-01T10:58:12","modified_gmt":"2024-11-01T10:58:12","slug":"c-coding-test-course-helping-the-underprivileged","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34202\/","title":{"rendered":"C++ Coding Test Course, Helping the Underprivileged"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! In this blog post, we will explore ways to contribute to society through the theme of helping the less fortunate by solving algorithm problems using C++. Algorithm problems play an important role in developing our problem-solving skills and are often a topic that comes up in actual job interviews.<\/p>\n<h2>Problem Description<\/h2>\n<p>Every year, many people face social issues, and during Christmas, charity donations are made. Each donor can donate an amount of their choice, and through these donations, we aim to help a specific number of less fortunate individuals. However, each recipient has a maximum amount they can receive in donations.<\/p>\n<h3>Problem Definition<\/h3>\n<p>Given the array of donation amounts from the donors and the maximum amount that each recipient can receive, calculate the maximum total amount of donations all recipients can receive.<\/p>\n<h3>Input Format<\/h3>\n<ul>\n<li>First line: the number of donors <code>N<\/code> (1 \u2264 N \u2264 1000)<\/li>\n<li>Second line: <code>N<\/code> integers representing the donation amounts from each donor <code>A<sub>1<\/sub>, A<sub>2<\/sub>, ..., A<sub>N<\/sub><\/code> (1 \u2264 <code>A<sub>i<\/sub><\/code> \u2264 10000)<\/li>\n<li>Third line: the number of recipients <code>M<\/code> (1 \u2264 M \u2264 1000)<\/li>\n<li>Fourth line: <code>M<\/code> integers representing the maximum amount each recipient can receive <code>B<sub>1<\/sub>, B<sub>2<\/sub>, ..., B<sub>M<\/sub><\/code> (1 \u2264 <code>B<sub>j<\/sub><\/code> \u2264 10000)<\/li>\n<\/ul>\n<h3>Output Format<\/h3>\n<p>Output the maximum total amount of donations that all recipients can receive.<\/p>\n<h2>Example Input<\/h2>\n<pre>\n5\n1500 2000 3000 4000 5000\n3\n2000 3000 10000\n<\/pre>\n<h2>Example Output<\/h2>\n<pre>\n10000\n<\/pre>\n<h2>Problem Solving Approach<\/h2>\n<p>The approach to solve this problem is as follows:<\/p>\n<ol>\n<li>Sort the donation amounts from the donors and the maximum amounts each recipient can receive.<\/li>\n<li>Check each donor&#8217;s maximum possible donation amount one by one and allocate it within the limits of each recipient&#8217;s maximum amount.<\/li>\n<li>Accumulate the results of each donation to calculate the total amount donated.<\/li>\n<\/ol>\n<h2>C++ Code Implementation<\/h2>\n<p>Below is the C++ code for the above approach:<\/p>\n<pre>\n#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\n\nusing namespace std;\n\nint main() {\n    int N;\n    cout &lt;&lt; \"Enter the number of donors: \";\n    cin &gt;&gt; N;\n\n    vector&lt;int&gt; donations(N);\n    cout &lt;&lt; \"Enter the donation amounts: \";\n    for (int i = 0; i &lt; N; i++) {\n        cin &gt;&gt; donations[i];\n    }\n\n    int M;\n    cout &lt;&lt; \"Enter the number of recipients: \";\n    cin &gt;&gt; M;\n\n    vector&lt;int&gt; beneficiaries(M);\n    cout &lt;&lt; \"Enter the maximum amount each recipient can receive: \";\n    for (int i = 0; i &lt; M; i++) {\n        cin &gt;&gt; beneficiaries[i];\n    }\n\n    \/\/ Sort the arrays of donors and recipients\n    sort(donations.rbegin(), donations.rend());\n    sort(beneficiaries.rbegin(), beneficiaries.rend());\n\n    int totalDonated = 0;\n    int donationIndex = 0;\n    int beneficiaryIndex = 0;\n\n    \/\/ Match donors with recipients\n    while (donationIndex &lt; N &amp;&amp; beneficiaryIndex &lt; M) {\n        if (donations[donationIndex] &lt;= beneficiaries[beneficiaryIndex]) {\n            totalDonated += donations[donationIndex];\n            donationIndex++;\n        } else {\n            totalDonated += beneficiaries[beneficiaryIndex];\n            beneficiaryIndex++;\n        }\n    }\n\n    cout &lt;&lt; \"Maximum total amount donated: \" &lt;&lt; totalDonated &lt;&lt; endl;\n    return 0;\n}\n<\/pre>\n<h2>Code Explanation<\/h2>\n<p>The above code works as follows:<\/p>\n<ol>\n<li>Receive input for the number of donors and recipients, as well as their respective donation amounts and maximum amounts each recipient can receive.<\/li>\n<li>Sort each array in descending order. This allows for comparison from the highest donations down to the lowest, enabling optimal allocation.<\/li>\n<li>Operate such that each donor does not exceed the maximum amount or the highest donation for each recipient, allowing for as many donations as possible.<\/li>\n<li>Calculate and output the total amount donated.<\/li>\n<\/ol>\n<h2>Performance Validation and Testing<\/h2>\n<p>The code written should be validated against various input examples. Testing should also consider extreme cases (e.g., all donors donating the same amount) in addition to normal cases.<\/p>\n<h3>Example Test Case<\/h3>\n<pre>\nInput:\n3\n3000 3000 3000\n4\n1500 3000 2000 1000\n\nOutput:\n9000\n<\/pre>\n<p>In the above code, the donors donate 3000, 3000, and 3000, while the recipients can receive 1500, 3000, 2000, and 1000 respectively. In this case, the maximum possible donation amount is 9000.<\/p>\n<h2>In Conclusion<\/h2>\n<p>In this post, we explored how to develop logical thinking through an algorithm problem matching donors and recipients using C++. This is a commonly used problem-solving method in coding tests and I hope learning about issues that can contribute to society will enhance your programming skills. I wish you the best in your coding test preparations!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this blog post, we will explore ways to contribute to society through the theme of helping the less fortunate by solving algorithm problems using C++. Algorithm problems play an important role in developing our problem-solving skills and are often a topic that comes up in actual job interviews. Problem Description Every year, many &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34202\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, Helping the Underprivileged&#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-34202","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, Helping the Underprivileged - \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\/34202\/\" \/>\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, Helping the Underprivileged - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this blog post, we will explore ways to contribute to society through the theme of helping the less fortunate by solving algorithm problems using C++. Algorithm problems play an important role in developing our problem-solving skills and are often a topic that comes up in actual job interviews. Problem Description Every year, many &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, Helping the Underprivileged&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34202\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:25:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:58:12+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=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34202\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34202\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, Helping the Underprivileged\",\"datePublished\":\"2024-11-01T09:25:27+00:00\",\"dateModified\":\"2024-11-01T10:58:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34202\/\"},\"wordCount\":471,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34202\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34202\/\",\"name\":\"C++ Coding Test Course, Helping the Underprivileged - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:25:27+00:00\",\"dateModified\":\"2024-11-01T10:58:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34202\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34202\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34202\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, Helping the Underprivileged\"}]},{\"@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, Helping the Underprivileged - \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\/34202\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, Helping the Underprivileged - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this blog post, we will explore ways to contribute to society through the theme of helping the less fortunate by solving algorithm problems using C++. Algorithm problems play an important role in developing our problem-solving skills and are often a topic that comes up in actual job interviews. Problem Description Every year, many &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, Helping the Underprivileged\"","og_url":"https:\/\/atmokpo.com\/w\/34202\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:25:27+00:00","article_modified_time":"2024-11-01T10:58:12+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":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34202\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34202\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, Helping the Underprivileged","datePublished":"2024-11-01T09:25:27+00:00","dateModified":"2024-11-01T10:58:12+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34202\/"},"wordCount":471,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34202\/","url":"https:\/\/atmokpo.com\/w\/34202\/","name":"C++ Coding Test Course, Helping the Underprivileged - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:25:27+00:00","dateModified":"2024-11-01T10:58:12+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34202\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34202\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34202\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, Helping the Underprivileged"}]},{"@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\/34202","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=34202"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34202\/revisions"}],"predecessor-version":[{"id":34203,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34202\/revisions\/34203"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}