fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. const int N = 2e5+10;
  7. int n, p;
  8. ll a[N];
  9.  
  10. bool check(ll t) {
  11. ll rs = 0;
  12. for(int i=0; i<n; i++) {
  13. rs += t/a[i];
  14. if(rs >= p) return true;
  15. }
  16. return rs >= p;
  17. }
  18.  
  19. int32_t main() {
  20. ios::sync_with_stdio(false);
  21. cin.tie(nullptr);
  22.  
  23. cin >> n >> p;
  24. for(int i=0; i<n; i++) {
  25. cin >> a[i];
  26. }
  27. ll l=0, r=1e18;
  28. ll rs=r;
  29. while(l<=r) {
  30. ll mid = (l+r)/2;
  31. if(check(mid)){
  32. rs=mid;
  33. r=mid-1;
  34. }
  35. else{
  36. l=mid+1;
  37. }
  38. }
  39. cout<<rs<<endl;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
0