#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
const ll MOD=1000000007;
void solve(){
ll a,b,c;cin>>a>>b>>c;
ll m;cin>>m;
ll tc=0,ans=0;
vi usb,ps;
for(int i=0;i<m;i++){
string s;ll x;cin>>x>>s;
if(s=="USB"){
usb.push_back(x);
}
else{
ps.push_back(x);
}
}
sort(usb.begin(),usb.end());
sort(ps.begin(),ps.end());
ll i=0,j=0;
while(a>0 && usb.size()>i){
ans+=usb[i];
i++;
a--;
tc++;
}
while(b>0 &&ps.size()>j){
ans+=ps[j];
j++;
b--;
tc++;
}
//cout<<ans<<" ";
if(a==0 || b==0){
vi d;
for(int k=i;k<usb.size();k++){
d.push_back(usb[k]);
}
for(int k=j;k<ps.size();k++){
d.push_back(ps[k]);
}
sort(d.begin(),d.end());
int v=0;
while(c>0 && d.size()>v){
ans+=d[v];
tc++;
c--;
v++;
}
cout<<tc<<" "<<ans<<"\n";
}
else{
cout<<tc<<" "<<ans<<"\n";
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t=1;
while(t--){
solve();
}
return 0;
}
1516B - AGAGA XOOORRR | 1515A - Phoenix and Gold |
1515B - Phoenix and Puzzle | 155A - I_love_username |
49A - Sleuth | 1541A - Pretty Permutations |
1632C - Strange Test | 673A - Bear and Game |
276A - Lunch Rush | 1205A - Almost Equal |
1020B - Badge | 1353A - Most Unstable Array |
770A - New Password | 1646B - Quality vs Quantity |
80A - Panoramix's Prediction | 1354B - Ternary String |
122B - Lucky Substring | 266B - Queue at the School |
1490A - Dense Array | 1650B - DIV + MOD |
1549B - Gregor and the Pawn Game | 553A - Kyoya and Colored Balls |
1364A - XXXXX | 1499B - Binary Removals |
1569C - Jury Meeting | 108A - Palindromic Times |
46A - Ball Game | 114A - Cifera |
776A - A Serial Killer | 25B - Phone numbers |