Codeforces Bear and Five Cards
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef vector<int>vii;
typedef map<int, int>mpii;
int ar[1100];
struct my
{
int num, velo;
};
my myar[1100];
bool cmp(my a, my b)
{
return a.velo > b.velo;
}
int main()
{
mpii mp;
int x,i;
while(cin >> x)
{
int arlen=0;
mp.clear();
if(mp.count(x) == 0)
{
ar[arlen++] = x;
mp[x] = 1;
}
else
{
mp[x]++;
}
for(i=1; i<5; i++)
{
cin >> x;
if(mp.count(x) == 0)
{
ar[arlen++] = x;
mp[x] = 1;
}
else
{
mp[x]++;
}
}
// for(i=0; i<arlen; i++)
// {
// cout << ar[i] << " " << mp[ar[i]] << "\n";
// }
int sum=0;
bool normal=false;
for(i=0; i<arlen; i++)
{
if(mp[ar[i]] == 1)
{
sum+=ar[i];
normal=true;
}
else
{
sum=0;
normal=false;
break;
}
}
if(normal)
{
cout << sum << "\n";
}
else
{
bool threep=false;
for(i=0; i<arlen; i++)
{
if(mp[ar[i]] > 3)
{
threep=true;
break;
}
}
if(threep)
{
int t , ts=0;
for(i=0; i<arlen; i++)
{
if(mp[ar[i]] > 3)
{
t = mp[ar[i]] - 3;
t = t*ar[i];
}
else
{
ts+=ar[i];
}
}
cout << ts+t << "\n";
}
else
{
int mylen=0;
for(i=0; i<arlen; i++)
{
myar[mylen].num=ar[i];
myar[mylen++].velo=mp[ar[i]];
}
sort(myar, myar+mylen, cmp);
// for(i=0; i<mylen; i++)
// {
// cout << myar[i].num << " " << myar[i].velo << "\n";
// }
int mini=100000 , tts=0 , maxi = myar[0].velo;
if(myar[0].velo==3 and myar[1].velo==1)
{
int t1 = (myar[1].num*myar[1].velo) + (myar[2].num*myar[2].velo);
cout << t1 << "\n";
}
else if(myar[0].velo==3 and myar[1].velo==2)
{
int t1 = (myar[1].num*myar[1].velo);
int t2 = (myar[0].num*myar[0].velo);
cout << min(t1, t2) << "\n";
}
else if(myar[0].velo==maxi and myar[1].velo==maxi)
{
int t1 = (myar[1].num*myar[1].velo) + (myar[2].num*myar[2].velo);
int t2 = (myar[0].num*myar[0].velo) + (myar[2].num*myar[2].velo);
cout << min(t1, t2) << "\n";
}
else if(myar[0].velo==maxi and myar[1].velo!=maxi)
{
int t1 = (myar[1].num*myar[1].velo) + (myar[2].num*myar[2].velo) + ((myar[3].num*myar[3].velo));
cout << t1 << "\n";
}
}
}
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef vector<int>vii;
typedef map<int, int>mpii;
int ar[1100];
struct my
{
int num, velo;
};
my myar[1100];
bool cmp(my a, my b)
{
return a.velo > b.velo;
}
int main()
{
mpii mp;
int x,i;
while(cin >> x)
{
int arlen=0;
mp.clear();
if(mp.count(x) == 0)
{
ar[arlen++] = x;
mp[x] = 1;
}
else
{
mp[x]++;
}
for(i=1; i<5; i++)
{
cin >> x;
if(mp.count(x) == 0)
{
ar[arlen++] = x;
mp[x] = 1;
}
else
{
mp[x]++;
}
}
// for(i=0; i<arlen; i++)
// {
// cout << ar[i] << " " << mp[ar[i]] << "\n";
// }
int sum=0;
bool normal=false;
for(i=0; i<arlen; i++)
{
if(mp[ar[i]] == 1)
{
sum+=ar[i];
normal=true;
}
else
{
sum=0;
normal=false;
break;
}
}
if(normal)
{
cout << sum << "\n";
}
else
{
bool threep=false;
for(i=0; i<arlen; i++)
{
if(mp[ar[i]] > 3)
{
threep=true;
break;
}
}
if(threep)
{
int t , ts=0;
for(i=0; i<arlen; i++)
{
if(mp[ar[i]] > 3)
{
t = mp[ar[i]] - 3;
t = t*ar[i];
}
else
{
ts+=ar[i];
}
}
cout << ts+t << "\n";
}
else
{
int mylen=0;
for(i=0; i<arlen; i++)
{
myar[mylen].num=ar[i];
myar[mylen++].velo=mp[ar[i]];
}
sort(myar, myar+mylen, cmp);
// for(i=0; i<mylen; i++)
// {
// cout << myar[i].num << " " << myar[i].velo << "\n";
// }
int mini=100000 , tts=0 , maxi = myar[0].velo;
if(myar[0].velo==3 and myar[1].velo==1)
{
int t1 = (myar[1].num*myar[1].velo) + (myar[2].num*myar[2].velo);
cout << t1 << "\n";
}
else if(myar[0].velo==3 and myar[1].velo==2)
{
int t1 = (myar[1].num*myar[1].velo);
int t2 = (myar[0].num*myar[0].velo);
cout << min(t1, t2) << "\n";
}
else if(myar[0].velo==maxi and myar[1].velo==maxi)
{
int t1 = (myar[1].num*myar[1].velo) + (myar[2].num*myar[2].velo);
int t2 = (myar[0].num*myar[0].velo) + (myar[2].num*myar[2].velo);
cout << min(t1, t2) << "\n";
}
else if(myar[0].velo==maxi and myar[1].velo!=maxi)
{
int t1 = (myar[1].num*myar[1].velo) + (myar[2].num*myar[2].velo) + ((myar[3].num*myar[3].velo));
cout << t1 << "\n";
}
}
}
}
return 0;
}
Comments
Post a Comment