Problem Statement: 

You are conducting a contest .... while purchasing balloons.

Detailed Problem Statement: Cost of Ballons

Solution Code in Java :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.BufferedReader;
import java.io.InputStreamReader;
class TestClass {
  public static void main(String args[]) throws Exception {

    //testCases t
    BufferedReader br = new BufferedReader(new InputStreamReader(System. in ));
    int t = Integer.parseInt(br.readLine());
    if (t >= 1 && t <= 10) {
      for (int q = 0; q < t; q++) {
        int x1 = 0,
        x2 = 0,
        n = 0,
        counterCol0 = 0,
        counterCol1 = 0,
        result = 0;
        int[] a = new int[2];
        int[][] arr = new int[10][2];

        String lines = br.readLine();

        String[] strs = lines.trim().split("\\s+");

        for (int i = 0; i < strs.length; i++) {
          a[i] = Integer.parseInt(strs[i]);
        }
        x1 = a[0]; //ballon numbers
        x2 = a[1]; // ballons numbers

        //n number of participants
        n = Integer.parseInt(br.readLine());
        if (n >= 1 && n <= 10) {

          for (int i = 0; i < n; i++) {
            String line2 = br.readLine();

            String[] str2 = line2.trim().split("\\s+");
            for (int y = 0; y < 2; y++) {
              arr[i][y] = Integer.parseInt(str2[y]);
              //storing input as 1 1
              //				  1 0
              //now logic comes
            }
          }
        }
        //here reading the participant answer from arr error
        for (int i = 0; i < n; i++) {
          for (int y = 0; y < 2; y++) {
            if (y == 0) {
              if (arr[i][y] == 1) counterCol0++;
              //System.out.println(counterCol0 + ""+arr[i][y]);
            }
            if (y == 1) {
              if (arr[i][y] == 1) counterCol1++;
              //	System.out.println(counterCol1 + ""+arr[i][y]);
            }

          }
        }
        //
        if (counterCol0 >= counterCol1) {
          //col0 is max
          if (x1 <= x2) {
            result = (x2 * counterCol1) + (x1 * counterCol0);

          }
          else {
            //x1 is max
            result = (x1 * counterCol1) + (x2 * counterCol0);
          }
        }
        else if (counterCol0 < counterCol1) {
          if (x1 <= x2) {
            //x2 is max
            result = (x2 * counterCol0) + (x1 * counterCol1);

          }
          else {
            //x1 is max
            result = (x1 * counterCol0) + (x2 * counterCol1);
          }
        }
        System.out.println(result);
      }
    }

  }

}
Hello Everyone i hope your Code works,i had test it on my PC using open JDK 1.8 and on HackerEarth open JDK 1.7 version. Comment down for any query, errors and new Problems.