×

# Getting WA - unable to understand why-MAXDIFF- Mock Exam-1- CCDSAP

 0 https://www.codechef.com/FLMOCK01/problems/MAXDIFF Hello, I think this is a pretty simple question, and the solution that i have come up with is - store the weights in an array, sort them in ascending, pick the first K for the kid; add them; the remaining n-k go to the dad, add them- find the diff and thats the answer. Can someone please point out where am i going wrong? here is the code for your reference - / package codechef; // don't place package name! / import java.util.; import java.lang.; import java.io.*; / Name of the class has to be "Main" only if the class is public. / class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here int numTestCases; Scanner sc = new Scanner(System.in); numTestCases = sc.nextInt(); while(numTestCases>0) { int n,k; n= sc.nextInt(); k = sc.nextInt(); int a[] = new int[n]; for(int i=0;i

 0 5 4 8 4 5 2 10 Your output is 9 but the correct output is 25. Hope you can find and fix the error by yourself now. answered 02 Jan, 10:41 65●7 accept rate: 8% yes, realised my mistake, thanks a lot :) (02 Jan, 14:20) digicode2★
 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:

×847