1271A - Suits - CodeForces Solution


brute force greedy math *800

Please click on ads to support us..

Python Code:

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())

print(max(min(b,c,d)*f + min(a,(d-min(b,c,d)))*e,min(a,d)*e + min((d-min(a,d)),b,c)*f))

C++ Code:

#include<stdio.h>
int main()
{
	int a,b,c,d,e,f,s=0,k;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	b=b<c?b:c;
	if(f>e)
	{
		if(d>b)
		{
			s+=b*f;
			d-=b;
			k=a<d?a:d;
			s+=k*e;
		}
		else
		{
			s+=d*f;
		}
	}
	else
	{
		if(d>a)
		{
			s+=a*e;
			d-=a;
			k=b<d?b:d;
			s+=k*f;
		}
		else
		{
			s+=d*e;
		}
	}
	printf("%d\n",s);
	return 0;
}
    	  	  			 	 		  		 	 			 	


Comments

Submit
0 Comments
More Questions

265A - Colorful Stones (Simplified Edition)
296A - Yaroslav and Permutations
967B - Watering System
152A - Marks
1398A - Bad Triangle
137A - Postcards and photos
1674D - A-B-C Sort
334A - Candy Bags
855A - Tom Riddle's Diary
1417A - Copy-paste
1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh
1721E - Prefix Function Queries
977E - Cyclic Components
1140D - Minimum Triangulation
75C - Modified GCD
1722A - Spell Check
1722B - Colourblindness
1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes