|
| 1 | +```java |
| 2 | +class Solution { |
| 3 | + static int maxCnt = 0; |
| 4 | + static int maxSell = 0; |
| 5 | + public int[] solution(int[][] users, int[] emoticons) { |
| 6 | + saleCase(users, emoticons, 0, 0, new int[emoticons.length]); |
| 7 | + return new int[]{maxCnt,maxSell}; |
| 8 | + } |
| 9 | + public void saleCase(int[][] users, int[] emoticons, int start, int count, int[] selected){ |
| 10 | + if(count == emoticons.length){ |
| 11 | + int curCnt = 0; |
| 12 | + int curSell = 0; |
| 13 | + int[] adaption = adaptSale(emoticons,selected); |
| 14 | + for(int[] user : users){ |
| 15 | + int userTotal = 0; |
| 16 | + for(int i=0;i<count;i++){ |
| 17 | + if(selected[i] >= user[0]){ |
| 18 | + userTotal += adaption[i]; |
| 19 | + } |
| 20 | + } |
| 21 | + if(userTotal >= user[1]){ |
| 22 | + curCnt++; |
| 23 | + }else{ |
| 24 | + curSell += userTotal; |
| 25 | + } |
| 26 | + } |
| 27 | + if(maxCnt < curCnt){ |
| 28 | + maxCnt = curCnt; |
| 29 | + maxSell = curSell; |
| 30 | + }else if(maxCnt == curCnt){ |
| 31 | + maxSell = Math.max(maxSell,curSell); |
| 32 | + } |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + for(int i=1;i<=4;i++){ |
| 37 | + selected[start] = i*10; |
| 38 | + saleCase(users,emoticons,start+1,count+1,selected); |
| 39 | + } |
| 40 | + } |
| 41 | + public int[] adaptSale(int[] price, int[] rate){ |
| 42 | + int[] adaption = new int[price.length]; |
| 43 | + for(int i=0;i<adaption.length;i++){ |
| 44 | + adaption[i] = (price[i]*(100-rate[i]))/100; |
| 45 | + } |
| 46 | + return adaption; |
| 47 | + } |
| 48 | +} |
| 49 | +``` |
0 commit comments