Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long m,n,t[25];
  5.  
  6. bool check(long long x)
  7. {
  8.     int S=0;
  9.     for(int i=1;i<=n;i++)
  10.     {
  11.         S+=x/t[i];
  12.     }
  13. //  cout<<x<<" "<<S<<endl;
  14.     if(S>=m)
  15.     {
  16.         return true;
  17.     }
  18.     return false;
  19. }
  20.  
  21. main()
  22. {
  23.  freopen("pancake.inp","r",stdin);
  24. freopen("pancake.out","w",stdout);
  25.     cin>>m>>n;
  26.     for(int i=1;i<=n;i++)
  27.     {
  28.         cin>>t[i]; 
  29.     }
  30.    
  31.     long long dau=0,cuoi=t[1]*n;
  32.     long long giua=(dau+cuoi)/2;
  33.     long long ans;
  34.     while(dau<=cuoi)
  35.     {
  36.         int giua=(dau+cuoi)/2;
  37.         if(check(giua)==true)
  38.         {
  39.             ans=giua;
  40.             cuoi=giua-1;
  41.         }
  42.         else
  43.         {
  44.             dau=giua+1;
  45.         }
  46.     }
  47.     cout<<ans;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement