Advertisement
a53

panou

a53
May 12th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <iostream>
  5. using namespace std;
  6. ifstream fin("panou.in");
  7. ofstream fout("panou.out");
  8. int hmax,P[100009],Q,h,H,h1,h2,hh,d,p,i,c,c1,c2;
  9. int T[21][100009],w[100009];
  10. long long pr,pmax,pmax1,pmax2;
  11.  
  12. int main(){
  13. ///test();
  14. fin>>hmax>>Q;
  15. p=0;d=1;
  16. for(h=1;h<=hmax;h++){
  17. fin>>P[h];
  18. T[0][h]=P[h];
  19. if(2*d<=h){
  20. d=d+d; p++;
  21. }
  22. w[h]=p;
  23. }
  24. d=1;
  25. for(p=1;(1<<p)<=hmax;p++){
  26. d=d+d;
  27. for(i=1;i+d-1<=hmax;i++){
  28. T[p][i]=max(T[p-1][i],T[p-1][i+d/2]);
  29. }
  30. }
  31. for(i=1;i<=Q;i++){
  32. fin>>H;
  33. hh=min(hmax,H);
  34. pmax1=0;
  35. for(h=1;h*h<=H && h<=hmax;h++){
  36. pr=(long long)(H/h)*P[h];
  37. if(pr>pmax1){
  38. pmax1=pr;
  39. }
  40. }
  41.  
  42. pmax2=0;
  43. while(h<=hmax && h<=H){
  44. c=H/h;
  45. h1=min(h*c+h-1,H)/c;
  46. p=w[h1-h+1];d=(1<<p);
  47. pr=max(T[p][h],T[p][h1-d+1]);
  48. if(pr*c>pmax2){
  49. pmax2=pr*c;
  50. }
  51. h=h1+1;
  52. }
  53. pmax=max(pmax1,pmax2);
  54. fout<<pmax<<"\n";
  55. }
  56. fout.close();
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement