ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1144. The Emperor's Riddle

Algo
Posted by xurshid_n 19 Jan 2012 18:52
A[] - values.
B[] - rewards.

1. sort A[] by not increasing order.
2. i=1..n    B[j] += A[i],  which B[j] - minimal value of B[].
3. while ( not <= K)
     try to equate with minimal of B[] and all other B[]s.
     try to equate with maximal of B[] and all other B[]s.
4. print.

only how to equate ? use simple DP!
Re: Algo
Posted by Erop [USU] 27 Mar 2012 13:29
if M=2 we get knapsack problem, and how to solve it faster than N*sum(A[i])?
or your solution uses fact that a B[]s are approximately equal?