cf B. Vasya and Public Transport
http://codeforces.com/contest/355/problem/B
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 int a[1001],b[1001]; 6 int c1,c2,c3,c4; 7 int n,m; 8 int main() 9 { 10 while(scanf("%d%d%d%d",&c1,&c2,&c3,&c4)!=EOF) 11 { 12 scanf("%d%d",&n,&m); 13 for(int i=1; i<=n; i++) 14 { 15 scanf("%d",&a[i]); 16 } 17 for(int i=1; i<=m; i++) 18 { 19 scanf("%d",&b[i]); 20 } 21 int sum=0; 22 for(int i=1; i<=n; i++) 23 { 24 sum+=min(a[i]*c1,c2); 25 } 26 if(sum>c3) 27 { 28 sum=c3; 29 } 30 int sum1=0; 31 for(int i=1; i<=m; i++) 32 { 33 sum1+=min(b[i]*c1,c2); 34 } 35 if(sum1>c3) 36 { 37 sum1=c3; 38 } 39 int ans=sum1+sum; 40 if(sum1+sum>c4) 41 { 42 ans=c4; 43 } 44 printf("%d\n",ans); 45 } 46 return 0; 47 }