You are viewing a single comment's thread. Return to all comments →
Arrays.sort(c); int i = 1; int res = 0; int count = 0; for(int j = c.length-1; j>=0; j--){ res += c[j] *i; count++; if(count >= k){ count = 0; i++; } } return res;
Seems like cookies are disabled on this browser, please enable them to open this website
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
Arrays.sort(c); int i = 1; int res = 0; int count = 0; for(int j = c.length-1; j>=0; j--){ res += c[j] *i; count++; if(count >= k){ count = 0; i++; } } return res;