Problem 62 min

Source: Internet
Author: User

$des $
There are $n $ items, the first $i $ items have two attributes $k _i, b_i$, which represents it at the moment $x $ 's value for $k _i
\times x + b_i$.
Currently at the moment $0$, you can choose not to exceed $m $ items, making the existence of an integer moment $t $, $t >= 0$
, the total value of all items you select is greater than or equal to $S $.
Given $S $, the minimum value for $t $.

$sol $
Select any of the collections, and the resulting gain and all can be represented as a function of a single form. Only care about these
The maximum value of a function can be found that the maximum value must be decreased first (when T is very large, $k _i \times t > b_i$, it may be monotonically increasing or monotonically decreasing).
So just check to see if the 0-hour meeting is eligible, and if not, two points.
Note that the check is only needed to find the largest m, so you can do O (n), the specific way is to quickly
In the process of recursion only one side. Directly with the STL nth_element ().
Time complexity $O (nlog10^9) $

$code $

#include <bits/stdc++.h>#defineRep (I, J, K) for (int i = j; I <= K; i++)using namespacestd;intRead () {Charc = GetChar ();intx =0; intsig =1;  while(C <'0'|| C >'9') {if(c = ='-') sig =-1; c =GetChar ();}  while(c >='0'&& C <='9') x = x *Ten+ C-'0', C =GetChar (); returnX *Sig;}Const intN = 1e6 +Ten; typedefLong LongLL;intN, M; LL S;intK[n], b[n]; LL Val[n];BOOLCheckintx) {Rep (I,1, n) val[i] = 1LL * K[i] * x +B[i]; Nth_element (Val+1, Val + M, Val + n +1, greater<ll>()); LL sum=0; Rep (i,1, m)if(Val[i] >0&& (sum + = Val[i]) >= S)return true; return false;}intMain () {n= Read (), M = Read (); scanf"%lld", &S); Rep (i,1, n) k[i] = Read (), b[i] =Read (); if(Check (0) {puts ("0");return 0;} intL =1, R =1e9, Ans;  while(L <=R) {intMid = (L + R)/2; if(Check (mid)) Ans = Mid, R =mid; ElseL = mid +1; } printf ("%d\n", Ans); return 0;}

Problem 62 min

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.