B - Vitamins
brute force
inf不能0x3f3f3f3f
# include <iostream>
# include <string>
# include <cstring>
const int inf =0x3f3f3f;
int cost, ans=inf;
std::string str;
int main(){
using namespace std;
int n;
cin>>n;
int a=inf, b=inf, c=inf, ab=inf, bc=inf, ac=inf, abc=inf;
for(int i=0; i<n; i++){
cin>>cost>>str;
if(str=="A")
a=min(a,cost);
if(str=="B")
b=min(b, cost);
if(str=="C")
c=min(c,cost);
if(str=="AB" || str=="BA")
ab=min(ab, cost);
if(str=="BC" || str=="CB")
bc=min(bc, cost);
if(str=="AC" || str=="CA")
ac=min(ac, cost);
if(str=="ABC" || str=="BAC" || str=="ACB" || str=="BCA" || str=="CAB" || str=="CBA")
abc=min(abc, cost);
}
ans=min(ans, a+b+c);
ans=min(ans, ab+c);
ans=min(ans, ac+b);
ans=min(ans, bc+a);
ans=min(ans, abc);
ans=min(ans, ab+ac);
ans=min(ans, ab+bc);
ans=min(ans, ac+bc);
if(ans==inf)
cout << -1<<endl;
else
cout <<ans<<endl;
return 0;
}