|
| 1 | +```java |
| 2 | +class Solution { |
| 3 | + static final int MAX_EMOTICON = 7; |
| 4 | + static int MAX_USER = 0; |
| 5 | + static int MAX_PRICE = 0; |
| 6 | + static int[] discountRate = new int[MAX_EMOTICON]; |
| 7 | + |
| 8 | + public int[] solution(int[][] users, int[] emoticons) { |
| 9 | + |
| 10 | + setDiscountRate(0,users, emoticons); |
| 11 | + int[] answer = {MAX_USER ,MAX_PRICE}; |
| 12 | + return answer; |
| 13 | + } |
| 14 | + |
| 15 | + public void setDiscountRate(int curIdx, int[][] users, int[] emoticons) { |
| 16 | + if(curIdx == emoticons.length) { |
| 17 | + calcPrice(users,emoticons); |
| 18 | + return; |
| 19 | + } |
| 20 | + for(int i = 10; i<= 40 ; i+=10) { |
| 21 | + discountRate[curIdx] = i; |
| 22 | + setDiscountRate(curIdx+1, users, emoticons); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + public void calcPrice(int[][] users, int[] emoticons) { |
| 27 | + |
| 28 | + int emoticonPlus=0; |
| 29 | + int emoticonPrice=0; |
| 30 | + |
| 31 | + for(int[] user : users) { |
| 32 | + int price=0; |
| 33 | + int userDiscountRate = user[0]; |
| 34 | + int userPlusPrice = user[1]; |
| 35 | + for(int idx=0; idx<emoticons.length; idx++) { |
| 36 | + if(discountRate[idx] >= userDiscountRate) { |
| 37 | + price += (emoticons[idx]/100) * (100-discountRate[idx]); |
| 38 | + } |
| 39 | + } |
| 40 | + if(price >= userPlusPrice) { |
| 41 | + emoticonPlus++; |
| 42 | + } else { |
| 43 | + emoticonPrice += price; |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + if(emoticonPlus > MAX_USER) { |
| 48 | + MAX_USER = emoticonPlus; |
| 49 | + MAX_PRICE = emoticonPrice; |
| 50 | + } |
| 51 | + else if ( emoticonPlus == MAX_USER && emoticonPrice >= MAX_PRICE) MAX_PRICE = emoticonPrice; |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
0 commit comments