fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long ilosc[1000007];
  4. long long przea[1000007];
  5. long long przeb[1000007];
  6. int n;
  7. bool czy(long long x){
  8. //cout << x << endl;
  9. pair<long long, long long> akt, pom;
  10. akt.first=0;
  11. akt.second=x;
  12. for(int i=0; i<n; i++){
  13. long long a=przea[i], b=przeb[i], s=ilosc[i];
  14. if((min(a, b)*x)>s)return 0;
  15. else if(a==b){
  16. pom.first=0;
  17. pom.second=x;
  18. }
  19. else if(a>b){
  20. pom.first=x-((s-(x*b))/(a-b));
  21. pom.second=x;
  22. }
  23. else{
  24. pom.first=0;
  25. pom.second=(s-(x*a))/(b-a);
  26. }
  27. if(akt.first>pom.second)return 0;
  28. else if(akt.second<pom.first)return 0;
  29. else{
  30. akt.first=max(akt.first, pom.first);
  31. akt.second=min(akt.second, pom.second);
  32. }
  33. }
  34. return 1;
  35. }
  36. int main(){
  37. ios_base::sync_with_stdio(0);
  38. cin.tie(0);
  39. cin >> n;
  40. for(int i=0; i<n; i++)cin >> ilosc[i];
  41. for(int i=0; i<n; i++)cin >> przea[i];
  42. for(int i=0; i<n; i++)cin >> przeb[i];
  43. long long p=0, k=1000000000, s;
  44. while(p<k){
  45. //cout << s << endl;
  46. s=(p+k+1)/2;
  47. if(czy(s))p=s;
  48. else k=s-1;
  49. }
  50. cout << p;
  51. }
Success #stdin #stdout 0.01s 7544KB
stdin
1
2
1
2
stdout
2