fork download
  1. B. Alice in Candyland
  2. Points: 100 Limits: 1s, 512 MB
  3.  
  4. Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
  5.  
  6. Alice can collect candies only once from a cell. So, even if a cell belongs to both a selected row and a selected column, she can only collect candies once from that cell.
  7.  
  8. Given the number of chocolates in each cell and the value of K, tell Alice what is the maximum number of chocolates she can collect if she plays optimally.
  9.  
  10. Input
  11.  
  12. The first line of input contains an integer T. Here, T is the number of test cases. T test cases follow.
  13.  
  14. The first line of each test case contains two space separated integers, N and K which have been defined in the statement above.
  15.  
  16. Each of the following N lines contains N space separated integers. Let Aij be the jth integer on the ith line. Then Aij represents the number of chocolates in the jth cell of the ith row of the grid.
  17.  
  18. Constraints:
  19.  
  20. 1 ≤ T ≤ 100
  21. 1 ≤ N ≤ 8
  22. 1 ≤ K ≤ 2N
  23. 0 ≤ Aij ≤ 106
  24.  
  25. Output
  26.  
  27. For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
  28.  
  29. Sample
  30.  
  31. Input Output
  32. 2
  33. 3 2
  34. 1 2 3
  35. 2 0 6
  36. 7 8 9
  37. 3 2
  38. 1 2 3
  39. 2 0 6
  40. 7 8 9 33
  41. 33
  42. Explanation:
  43.  
  44. Since we can choose up to 2 different rows or columns [there are 15 possible choices], it would be optimal to choose the 3rd row and the 3rd column. We collect 3 + 6 +7 + 8 + 9 = 33 chocolates this way. We will not get a better result for any other choice of rows and columns.
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:52: error: stray ‘\342’ in program
 Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
                                                    ^
prog.cpp:4:53: error: stray ‘\200’ in program
 Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
                                                     ^
prog.cpp:4:54: error: stray ‘\234’ in program
 Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
                                                      ^
prog.cpp:4:66: error: stray ‘\342’ in program
 Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
                                                                  ^
prog.cpp:4:67: error: stray ‘\200’ in program
 Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
                                                                   ^
prog.cpp:4:68: error: stray ‘\235’ in program
 Alice came up with a new game. In this game called “Candy Quest”, there is a NxN size 2D grid. In each of the cells in this grid, there are some chocolates. Alice is given an integer K. She can choose up to K different rows and columns. Then she gets to collect all the chocolates from the cells in those rows and columns.
                                                                    ^
prog.cpp:20:3: error: stray ‘\342’ in program
 1 ≤ T ≤ 100
   ^
prog.cpp:20:4: error: stray ‘\211’ in program
 1 ≤ T ≤ 100
    ^
prog.cpp:20:5: error: stray ‘\244’ in program
 1 ≤ T ≤ 100
     ^
prog.cpp:20:9: error: stray ‘\342’ in program
 1 ≤ T ≤ 100
         ^
prog.cpp:20:10: error: stray ‘\211’ in program
 1 ≤ T ≤ 100
          ^
prog.cpp:20:11: error: stray ‘\244’ in program
 1 ≤ T ≤ 100
           ^
prog.cpp:21:3: error: stray ‘\342’ in program
 1 ≤ N ≤ 8
   ^
prog.cpp:21:4: error: stray ‘\211’ in program
 1 ≤ N ≤ 8
    ^
prog.cpp:21:5: error: stray ‘\244’ in program
 1 ≤ N ≤ 8
     ^
prog.cpp:21:9: error: stray ‘\342’ in program
 1 ≤ N ≤ 8
         ^
prog.cpp:21:10: error: stray ‘\211’ in program
 1 ≤ N ≤ 8
          ^
prog.cpp:21:11: error: stray ‘\244’ in program
 1 ≤ N ≤ 8
           ^
prog.cpp:22:3: error: stray ‘\342’ in program
 1 ≤ K ≤ 2N
   ^
prog.cpp:22:4: error: stray ‘\211’ in program
 1 ≤ K ≤ 2N
    ^
prog.cpp:22:5: error: stray ‘\244’ in program
 1 ≤ K ≤ 2N
     ^
prog.cpp:22:9: error: stray ‘\342’ in program
 1 ≤ K ≤ 2N
         ^
prog.cpp:22:10: error: stray ‘\211’ in program
 1 ≤ K ≤ 2N
          ^
prog.cpp:22:11: error: stray ‘\244’ in program
 1 ≤ K ≤ 2N
           ^
prog.cpp:23:3: error: stray ‘\342’ in program
 0 ≤ Aij ≤ 106
   ^
prog.cpp:23:4: error: stray ‘\211’ in program
 0 ≤ Aij ≤ 106
    ^
prog.cpp:23:5: error: stray ‘\244’ in program
 0 ≤ Aij ≤ 106
     ^
prog.cpp:23:11: error: stray ‘\342’ in program
 0 ≤ Aij ≤ 106
           ^
prog.cpp:23:12: error: stray ‘\211’ in program
 0 ≤ Aij ≤ 106
            ^
prog.cpp:23:13: error: stray ‘\244’ in program
 0 ≤ Aij ≤ 106
             ^
prog.cpp:27:141: error: stray ‘\342’ in program
 For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
                                                                                                                                             ^
prog.cpp:27:142: error: stray ‘\200’ in program
 For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
                                                                                                                                              ^
prog.cpp:27:143: error: stray ‘\234’ in program
 For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
                                                                                                                                               ^
prog.cpp:27:155: error: stray ‘\342’ in program
 For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
                                                                                                                                                           ^
prog.cpp:27:156: error: stray ‘\200’ in program
 For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
                                                                                                                                                            ^
prog.cpp:27:157: error: stray ‘\235’ in program
 For each test case, print one line of output which consists of one integer: the maximum number of chocolates Alice can collect if she plays “Candy Quest” optimally.
                                                                                                                                                             ^
prog.cpp:1:1: error: ‘B’ does not name a type
 B. Alice in Candyland
 ^
stdout
Standard output is empty