ALEXROSE has judged wrongly?

Email codechef regarding it. i don’t think they will publish editorials for DEC-16 challenge now.

Hello srd091,please let me know where it is failing

@jawa2code for test case


1
6 3
1 2 3 4 4 5

you program is giving 4 while the correct answer is 3.

@jawa2code

Sir, I would say that instead of posting code, if you can explain your approach/algo or include some comments in your code as such what that statement/variable/loop is doing, we will be able to help you better.

Because coding is quite weird in this sense. A programmer wouldn’t be able to understand HIS OWN code if he sees it after a month, (he wont be able to deduce what he did or thought while writing it if he includes no comment.)

Don’t take it in wrong sense, I admire your dedication to solving this problem alone for this long! Its really nice! But I would say, if you explain your approach, we might be able to give you the correct deductions/logic or even a correct code which will help you learn.

Cause if you get stuck with a problem, then its bad! It will take your time where you could solve many more problems which would make you learn many more things!

So, I will request, that if you find it agreeable, please explain how you are approaching the problem.

With Regards and Wishes.

Vijju/

1 Like

Exactly! Posting a code like that doesn’t seem to be good. Even the solutions of all programmers has been out then he can take a estimation about why and where his code is failing.

See if someone could not debug their own code then how can he/she survive in industry where he/she deals with such a large amount of codes.

1 Like

@bansal1232 - I think you misunderstood where I meant “A programmer wouldn’t be able to understand HIS OWN code if he sees it after a month” , perhaps I should had worded it better.

I simply meant to imply that, at least at this stage (where we are learning coding), we sometimes just…forget what we did or thought while solving the question XD.

I am sorry if it sounds confusing. I just wanted to imply that comments or telling approach is appreciated when requesting others to check your code. :slight_smile: (thanks for pointing out the ambiguity of my statement tho!)

Hello srd091 Thanks a lot
i have fixed that issues,it is working for some testcases tested,but still getting WA

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.TreeMap;

public class Main {

public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int n = 0, k = 0;
String key = null;
Integer value = 0, reqCnt = 0, demand = 0;
TreeMap<Integer, Integer> table = new TreeMap<Integer, Integer>();
HashMap<Integer, Integer> reqCntTable = new HashMap<Integer, Integer>();
String data[] = null;

    for (int i = 0; i < t; i++) {
        reqCntTable.clear();
        table.clear();
        data = br.readLine().split(" ");
        n = Integer.parseInt(data[0]);
        k = Integer.parseInt(data[1]);

        data = br.readLine().split(" ");
        if (k == 1) {
            System.out.println(0);
            continue;
        }
        for (int j = 0; j < n; j++) {
            key = data[j].trim();
            value = table.get(Integer.parseInt(key));
            if (value == null) {
                value = 0;

            }
            value++;
            value = value % k;
            table.put(Integer.parseInt(key), value);

        }
        Collection<Integer> boquey = table.values();
        ArrayList<Integer> heights = new ArrayList<Integer>(boquey);
        int hlen = heights.size();

        Set keys = table.keySet();
        Iterator iterator = keys.iterator();
        Integer keyStr = 0;

        while (iterator.hasNext()) {
            keyStr = (Integer) iterator.next();
            demand = (k - table.get(keyStr));
            reqCnt = reqCntTable.get(demand);
            if (reqCnt == null) {
                reqCnt = 1;
            } else {
                reqCnt++;
            }
            reqCntTable.put(demand, reqCnt);
        }

        long result = 0L;
        int len = heights.size();
        int freePool = 0, cpool = 0;
        Integer available = 0;
        int j = 0;
        int bqCnt = 0;
        int reqAux = 0, req = 0;

        for (j = len - 1; j > 0; j--) {
            cpool = heights.get(j);
            reqAux = k - cpool;
            available = reqCntTable.get(cpool);
             int index = heights.indexOf(reqAux);
            if ((available != null) && (available > 0)&&(index<j)) {                  
                heights.set(index, 0);
                result += cpool;
                available--;
                reqCntTable.put(cpool, available);
                reqAux = k - cpool;
                available = reqCntTable.get(reqAux);
                available--;
                reqCntTable.put(reqAux, available);
				continue;
            } 
			if(reqAux<=freePool){
			freePool-=reqAux;
			 result += reqAux;
			 continue;
			}
			 freePool += cpool;
                bqCnt = freePool / k;
                freePool = freePool % k;
                result += (k - 1) * bqCnt;
        }

        bqCnt = freePool / k;
        freePool = freePool % k;
        result += (k - 1) * bqCnt;

        result += freePool;
        table.clear();
        System.out.println(result);
    }
} catch (IOException ex) {
}

}

}

Already talked to Rudreh,they told that soon they publish,alredy 2week over

Hello srd091,please fail my code…

Hello srd091,please let me know where it is failing

Hello srd091 ,can i wait for you response or not please let me know

oh please stop spamming the discussion session. If he is not replying then may be the reason is that he is busy in other stuff and have not seen that message. So i request you to be please be patience.

Hello bansal1232,if you have the time and willing to test where it is failing please let me know the test case
Regards
Samuel

is it just me or that code just doesn’t compile on codechef ide…I tried removing blank space and stuff. It says " > expected" in each of-
TreeMap<String, Integer> table = new TreeMap<String, Integer>();
HashMap<Integer, Integer> reqCntTable = new HashMap<Integer, Integer>();

take code from “https://www.codechef.com/viewsolution/12751008

1 Like

@jawa2code

I ran your code on hackerrank compiler (cause idk why codechef still gave me errors. Worked on hackerrank tho) and what I saw was-

For inputs <= 10^9, code worked all fine.

But when I entered 10^10 -

Runtime error
Input (stdin)
1
8 2
10000000000 25 25 30 30 30 30 25
Your Output
~ no response on stdout ~
Error
Exception in thread "main" java.lang.NumberFormatException: For input string: "10000000000"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:583)
	at java.lang.Integer.parseInt(Integer.java:615)
	at Main.main(Main.java:26)

I will say that take some time off this problem, and solve some other. Because the key points of problem sometimes strike randomly. Don’t stress over it dear!

Thank you vijju123
but for first sub tasks

Subtask #1 (5 points) 1 ≤ T ≤ 10, 2 ≤ N ≤ 12, 1 ≤ Ai ≤ 50

it should work
Regards
Samuel

@jawa

 Compilation Successful
Input (stdin)
1
6 3
50 1 40 2 50 40
Your Output
4

Expected output -

Group roses like 40,40,50 & 50,1,2.

Number of roses to be cut is 3. Your code gives 4.

Thanks a lot vijju123

np dear :slight_smile: