{"id":167,"date":"2016-01-08T14:49:49","date_gmt":"2016-01-08T14:49:49","guid":{"rendered":"http:\/\/emacslisp.com\/?p=167"},"modified":"2016-01-21T11:48:26","modified_gmt":"2016-01-21T11:48:26","slug":"google-codejam-mushroom-monster","status":"publish","type":"post","link":"http:\/\/emacslisp.com\/?p=167","title":{"rendered":"Google CodeJam &#8211; Mushroom Monster"},"content":{"rendered":"<p>Question URL is https:\/\/code.google.com\/codejam\/contest\/4224486\/dashboard<\/p>\n<p>This question could be become two sub question.<br \/>\n<em><strong>1. less mushroom to eat.<\/strong><\/em><br \/>\nfor array 10 5 15 5, what is the sum of decreased numbers?<br \/>\n10 is decreased to 5, the decreased number is (10-5).<br \/>\n5 raises to 15, it will be ignored.<br \/>\n15 is decreased to 5, the decreased number is (15-5)<\/p>\n<p>the sum of all decreased numbers that is (10-5)+(15-5) will be the answer.<br \/>\n<em><strong><br \/>\n2. eating mushroom in static speed.<\/strong><\/em><br \/>\nfind the max gap of decreased numbers. (15-5) is the max speed in 10 seconds.<br \/>\nthere for, if mushroom number on the dish is greater than (15-5), Kaylin only eats(15-5).<\/p>\n<p>if mushroom number on the dish is less that (15-5), Kaylin will finish all of them and waiting for next refill.<\/p>\n<p>Here is Clang code.<\/p>\n<pre lang=\"c\" line=\"1\"> \r\n  int N;\r\n  int L;\r\n  int i,j,k;\r\n  int array[MAXSIZE];\r\n  int sum1 = 0;\r\n  int sum2 = 0;\r\n\r\n  scanf(\"%d\\n\",&N);\r\n\r\n  for(i=0;i<N;i++)\r\n  {\r\n    scanf(\"%d\",&#038;L);\r\n    memset(array,0,sizeof(int)*MAXSIZE);\r\n    sum1 = 0;\r\n    sum2 = 0;\r\n    for(j = 0;j<L;j++){\r\n      scanf(\"%d\",&#038;array[j]);\r\n    }\r\n\r\n    \/\/start\r\n    for(j = 0;j<L - 1;j++){\r\n      if(array[j]>array[j + 1])\r\n        sum1 += (array[j] - array[j + 1]); \r\n    }\r\n\r\n    int max = 0;\r\n\r\n    for(j = 0;j<L - 1;j++){\r\n      if(array[j]>array[j + 1]){\r\n        if(max<(array[j] - array[j + 1])){\r\n          max = array[j] - array[j + 1];\r\n        }\r\n      }\r\n    }\r\n\r\n    for(j = 0;j<L - 1;j++){\r\n      sum2 += (array[j]>max?max:array[j]); \r\n    }\r\n\r\n    printf(\"Case #%d: %d %d\\n\",(i + 1),sum1,sum2);\r\n  }\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Question URL is https:\/\/code.google.com\/codejam\/contest\/4224486\/dashboard This question could be become two sub question. 1. less mushroom to eat. for array 10 5 15 5, what is the sum of decreased numbers? 10 is decreased to 5, the decreased number is (10-5). 5 raises to 15, it will be ignored. 15 is decreased to 5, the decreased [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,9],"tags":[],"class_list":["post-167","post","type-post","status-publish","format-standard","hentry","category-algorithm","category-googlecodejam"],"_links":{"self":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":8,"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":175,"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/175"}],"wp:attachment":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}