Advertisement
Josif_tepe

Untitled

Feb 18th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int m,n,l;
  8.     cin>>m>>n;
  9.     int u,d;
  10.     cin>>u>>d>>l;
  11.     int maks,x,zbir,a[l],y;
  12.     maks=0;
  13.     zbir=2e9;
  14.     for(int i=0;i<l;i++)
  15.     {
  16.         cin>>a[i];
  17.     }
  18.     for(int i=0;i<l;i++)
  19.     {
  20.         if(a[i]<m)
  21.         {
  22.             maks=(m-a[i])*d;
  23.         }else
  24.         {
  25.             maks=(a[i]-m)*u;
  26.         }
  27.         for(int j=0;j<l;j++)
  28.         {
  29.             if(a[j]<n)
  30.             {
  31.                 x=(n-a[j])*u;
  32.             } else
  33.             {
  34.                 x=(a[j]-n)*d;
  35.             }
  36.             if(x+maks<zbir)
  37.                 zbir=x+maks;
  38.         }
  39.  
  40.     }
  41.     if(m>n)
  42.     {
  43.         y=(m-n)*d;
  44.     }else
  45.     {
  46.         y=(n-m)*u;
  47.     }
  48.     if(zbir>y)
  49.         cout<<y;
  50.     else
  51.         cout<<zbir;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement