Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. There is an infinate number of boxes, numbered with consecutive integer values. Initially, there are *N* different boxes with cats in it. The position of i-th box is *X[i]* and it contains a cat with label *P[i]*. All the other boxes are empty. At any moment of time, there can be no two or more cats in the same box.
  2.  
  3. In a single turn, you can choose any two cats *a* and *b*, where cat with label *b* is located to the right of cat with label *a*. The only restriction is that there should be no other cats in any box between them. The following process occures:
  4.  
  5. - The cat with label *b* moves *D[b]* boxes to the left, but he stops if its impossible to move anymore because of an occupied box on this way.
  6. - Cats *a* and *b* swap their labels.
  7.  
  8. You can perform this operation no more than *K* times.
  9.  
  10. You are interested in two values. The first one is the number of inversions of cats labels after all operations, let's call it *A*. The other value is the total sum of squared distances between consecutive cats, lets call it *B*. Your score for a test case the value of *A/B*, and your task is to minimize the score.
  11.  
  12. **Input format**
  13.  
  14. The first line of the input contains two integers *N* and *K*. The second line contains *N* space separated integers *X[i]* (sorted in increasing order) - the initially occupied positions. The third line contains *N* space separated integers *P[i]* - the inital label of cat at position *X[i]*. Finally, the fouth line contains *N* space separated integers *D[i]* - the maximal amount of position a cat with label i can move.
  15.  
  16. **Output format**
  17.  
  18. For each event of the second type print the answer to the corresponding event.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement