Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io.StdIn.readLine
- object Task3 extends App {
- val n = readLine().split(' ').map(_.toLong).head
- def eating(n: Long, k: Long) = {
- var total = n
- var Vasya = 0L
- var Petya = 0L
- while (total > 0L) {
- val eatVasya = if (total > k) k else total
- total = total - eatVasya
- val eatPetya = math.floor(total * 0.1).toInt
- total = total - eatPetya
- Vasya = Vasya + eatVasya
- Petya = Petya + eatPetya
- }
- Vasya > Petya
- }
- def sol(n: Long) = {
- var left = 1L
- var right = n
- while ( left != right) {
- val now = (left+right)/2
- if (!eating(n, now)) left = now + 1 else right = now
- }
- left
- }
- println(sol(n))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement