Advertisement
Guest User

Untitled

a guest
Dec 15th, 2012
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #include <string.h>
  7. #include <queue>
  8. #include <map>
  9. #include <set>
  10. #include <cmath>
  11. #include <sstream>
  12. #include <stack>
  13. #include <cassert>
  14.  
  15. #define pb push_back
  16. #define mp make_pair
  17. #define PI 3.1415926535897932384626433832795
  18. #define sqr(x) (x)*(x)
  19. #define forn(i, n) for(int i = 0; i < n; ++i)
  20. #define ALL(x) x.begin(), x.end()
  21. #define F first
  22. #define S second
  23. #define m0(x) memset(x,0,sizeof(x))
  24. #define m1(x) memset(x,-1,sizeof(x))
  25. #define CC(x) cout << (x) << "\n"
  26. #define pw(x) (1ull<<(x))
  27.  
  28. using namespace std;
  29. typedef long long ll;
  30. typedef unsigned long long ull;
  31. typedef long double ld;
  32. typedef pair<int,int> pii;
  33. const int INF = 2147483647;
  34. const ll LLINF = 9223372036854775807LL;
  35.  
  36. ll t[100500];
  37. ll n,m;
  38.  
  39. bool check(ll ti) {
  40.   ll can = 0;
  41.   for (int i=0;i<n;i++) {
  42.     can+=(ti/t[i]);
  43.     if (can>=m) return true;
  44.   }
  45.   return false;
  46. }
  47.  
  48. int main() {
  49.   //freopen("input.txt", "r", stdin);
  50.   //freopen("output.txt", "w", stdout);
  51.   cin >> n >> m;
  52.   for (int i=0;i<n;i++) scanf("%lld", &t[i]);
  53.  
  54.   ll l=0, r=ll(2*1e18);  
  55.   while (r-l>1) {
  56.     ll mid = (l+r)/2;
  57.     if (check(mid)) r=mid; else l=mid;
  58.   }
  59.   cout << r << "\n";
  60.   return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement