×

# plz check [MAXDIFF]

 0 what was the error in this code??? http://www.codechef.com/viewsolution/1984132 asked 15 Apr '13, 20:00 198●10●25●35 accept rate: 0%

 2 after scanning b and c, add if(c>(b-c)) c=b-c; That should get you AC :) answered 15 Apr '13, 20:23 420●6●12●24 accept rate: 3% This is the logic I also used and wanted to share. More precisely, if(2*K>N){ K = N - K; } Meanwhile try to use some meaningful variable names like the ones given in codechef questions. (19 Apr '13, 08:36) 1 @aichemzee suggested the changes to @hitesh091 code who used such weird names. (19 Apr '13, 14:28) ^exactly. As in general you could do k=Math.min(k,n-k); to get AC. (19 Apr '13, 15:54)
 0 There's 2 possibilities, and you've got to check them both. eg. K = 2, for list [1,2,3,...,98,99,100] either: [1,2] [3,...,98,99,100] or: [99,100] [1,2,3,...,98] answered 15 Apr '13, 20:05 3★evandrix 165●1●4●8 accept rate: 0% @evandrix: still not clear sir... (15 Apr '13, 20:21)
 0 @evandrix: not clear sir.. answered 15 Apr '13, 20:13 198●10●25●35 accept rate: 0% 1 @hitesh091: Take for example the case K=2 and list is 1 1 1 1 3 the two possible arrangements would be (1)+(1,1,1,3) and (1,1,1,1)+(3) you have to take the one with maximum difference. here, in first case the difference is 5 and in the second case, difference is 1. so, you select the first arrangement. (15 Apr '13, 20:30) @manasvi: am i wrong with my logic.. http://www.codechef.com/viewsolution/1984132 (15 Apr '13, 21:09) 1 @hitesh091: yes, there is an error in your logic. the error being, you are only considering first k small elements. Now consider this example. let K=4 and the list be 1 1 1 1 9. the ways your program is running is, it is picking first 4 elements for the kid, thus making the distribution 4 for the kid and 9 for the chef. Difference = 5. but the correct way of doing this would be giving the last 4 elements to the chef and first element to the kid thus the distribution would be 1 for kid and 12 for the chef. Difference = 11. (15 Apr '13, 21:32) (15 Apr '13, 21:32) in addition to that if you would have done if(k>(n/2)) k=n-k; you would have got it accepted. (16 Apr '13, 09:55) thanks.. now i got it.. :) (16 Apr '13, 19:25) showing 5 of 6 show all
 0 Hi Can anyone check this code http://www.codechef.com/viewsolution/2059067 and tell me why am I getting "wrong answer". As I check, the output and input format and answers are exactly the same. Thanks answered 19 Apr '13, 21:55 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,490
×858
×58

question asked: 15 Apr '13, 20:00

question was seen: 1,233 times

last updated: 19 Apr '13, 21:55