Advertisement
Josif_tepe

Untitled

Mar 16th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a,b,desno,levo,l,l1,a1,a2,low;
  8.     a1=0;
  9.     a2=0;
  10.     low=2000000000;
  11.     cin>>a >> b >>desno >>levo >>l;
  12.     int high = 2000000000;
  13.     int niza[l];
  14.     for(int i=0;i<l;i++)
  15.     {
  16.         cin>>l1;
  17.         niza[i]=l1;
  18.     }
  19.     if(l == 0) {
  20.         if(a < b) {
  21.             cout << (b - a) * desno << endl;
  22.         }
  23.         else {
  24.             cout << (a - b) * levo << endl;
  25.        
  26.         }
  27.         return 0;
  28.     }
  29.    for(int i=0;i<l;i++)
  30.    {
  31.    
  32.              if(niza[i]>=a)
  33.              {
  34.                  a1=(niza[i]-a)*desno;
  35.                  if(a1<low)
  36.                  {
  37.                      low=a1;
  38.                  }
  39.              }
  40.              if(niza[i]<=a)
  41.              {
  42.                  a2=(a-niza[i])*levo;
  43.                  if(a2<low)
  44.                  {
  45.                      low=a2;
  46.                  }
  47.              }
  48.    }
  49.     for(int i = 0; i < l; i++) {
  50.         if(niza[i] >= b) {
  51.             a1 = (niza[i] - b) * levo;
  52.             if(a1 < high) {
  53.                 high = a1;
  54.             }
  55.         }
  56.         if(niza[i] <= b) {
  57.             a2 = (b - niza[i]) * desno;
  58.             if(a2 < high)  {
  59.                 high = a2;
  60.             }
  61.         }
  62.     }
  63.     int R = low + high;
  64.     int b1;
  65.     if(a <= b) {
  66.         b1 = (b - a) * desno;
  67.         if(R > b1) {
  68.             R = b1;
  69.         }
  70.     }
  71.     if(a >= b) {
  72.         b1 = (a - b) * levo;
  73.         if(R > b1) {
  74.             R = b1;
  75.         }
  76.     }
  77.     cout<<R<< endl;;
  78.     return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement