-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSBvsPS-2.cpp
More file actions
61 lines (60 loc) · 1.09 KB
/
USBvsPS-2.cpp
File metadata and controls
61 lines (60 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int usb,ps2,usb_ps2;
cin>>usb>>ps2>>usb_ps2;
int choices;
cin>>choices;
vector<int> USB;
vector<int> PS2;
for(int i=0;i<choices;i++)
{
int x;
string y;
cin>>x>>y;
if(y=="USB")
USB.push_back(x);
else PS2.push_back(x);
}
sort(USB.begin(),USB.end());
sort(PS2.begin(),PS2.end());
int i=0;
int j=0;
int price = 0;
int computers = 0;
vector<int> leftover;
for(int k=0;k<usb && k<USB.size();k++)
{
price+=USB[k];
computers++;
i++;
}
for(;i<USB.size();i++)
leftover.push_back(USB[i]);
for(int k=0;k<ps2 && k<PS2.size();k++)
{
price+=PS2[k];
computers++;
j++;
}
for(;j<PS2.size();j++)
leftover.push_back(PS2[j]);
sort(leftover.begin(),leftover.end());
i = 0;
while(usb_ps2>0 && i<leftover.size())
{
price+=leftover[i];
i++;
usb_ps2--;
computers++;
}
cout<<computers<<" "<<price<<endl;
return 0;
}