Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int m,n,l;
- cin>>m>>n;
- int u,d;
- cin>>u>>d>>l;
- int maks,x,zbir,a[l],y;
- maks=0;
- zbir=2e9;
- for(int i=0;i<l;i++)
- {
- cin>>a[i];
- }
- for(int i=0;i<l;i++)
- {
- if(a[i]<m)
- {
- maks=(m-a[i])*d;
- }else
- {
- maks=(a[i]-m)*u;
- }
- for(int j=0;j<l;j++)
- {
- if(a[j]<n)
- {
- x=(n-a[j])*u;
- } else
- {
- x=(a[j]-n)*d;
- }
- if(x+maks<zbir)
- zbir=x+maks;
- }
- }
- if(m>n)
- {
- y=(m-n)*d;
- }else
- {
- y=(n-m)*u;
- }
- if(zbir>y)
- cout<<y;
- else
- cout<<zbir;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement