Sort by

recency

|

11 Discussions

|

  • + 0 comments

    scala:

    import scala.io.StdIn
    
    object Solution {
      private def solve(
          n: Int,
          m: BigInt,
          a: Seq[Int],
          h: Seq[Int]
      ): Int = {
        val ah = a zip h
    
        def canDistribute(k: Int): Boolean = {
          ah.map { case (ai, hi) =>
            ai + BigInt(k - 1) * hi
          }.sorted
            .take(k)
            .sum <= m
        }
    
        def binarySearch(low: Int, high: Int): Int = {
          if (low > high)
            return high
          val mid = (low + high) / 2
          if (canDistribute(mid))
            binarySearch(mid + 1, high)
          else
            binarySearch(low, mid - 1)
        }
    
        binarySearch(1, n)
      }
    
      def main(args: Array[String]): Unit = {
        val arr = Iterator
          .continually(StdIn.readLine())
          .takeWhile(null != _)
          .map(_.trim)
        val nm = arr.next().split(' ')
        val n = nm.head.toInt
        val m = BigInt(nm.last)
        val a = arr.next().split(' ').map(_.toInt).toSeq
        val h = arr.next().split(' ').map(_.toInt).toSeq
        println(solve(n, m, a, h))
      }
    }
    
  • + 0 comments

    Nutrition for Health-CBD Products based in the United States. It provides good quality green apple cbd gummies that are made with the highest quality grown herbs which are most useful for stress relief, anxiety, and many other purposes. All These CBD Products are highly recommended by CBD Registered Dietitian.

  • + 2 comments

    Mango Blast Pro You are given two N N matrices representing a field of mangoes say A and B. Each cell is one of three possible characters as follows. The two matrices are connected at cells (n-1,6-1) A(n-1, n-1) > B(n-1, 0) > B(0, n-1). Matrix B there is no valid path between two touchpoints, then no mangoes can be collected & hence return 0. Input: First line contains an integer N which represents the size of the matrix. Its a square matr Next N lines carry a string which represent the row Ri in the matrix where iis (0,n-1). Len is N btw. Constraints : 0

  • + 0 comments

    Indeed, I adored it in light of the fact that at whatever point I will look for something I get it from your site. Your site is providing cheapest essay writing service and I trust that this site will likewise be celebrated as your others. Much obliged to you for acquainting another stage with assistance individuals.

  • + 1 comment

    Hey guys, could anyone give me some hints how to approach this, I submitted 2 approaches using Scala and both timeouted from fifth test-case.

    I tried iterating through combinations but it did not work.

    Any help?

    Thanks