## Algorithm

Sample Input 2 100 5 3 A:1,10 B:2,5 C:3,1 1123 1122 5 B:50,300 A:1,1000 C:10,10 D:1,50 E:0,0

Sample Output Case 1 C 7 B 22 A 37 Case 2 E 0 A 1 D 1 C 10 B 50

## Code Examples

### #1 Code Example with C Programming

```Code - C Programming```

`````` #include <bits/stdc++.h>
using namespace std;

int minCost(int n,int m,int a,int b){
int res = INT_MAX;
for(int i=0;n>=m;i++,n/=2){
int remain = n - m;
int cost = remain*a + i*b;
res = min(cost,res);
}
return res;
}

int main() {
int t,n,m,l,a,b,tc=1;
string in;
cin >> t;
while(t--){
cin >> n >> m >> l;
cin.ignore();
vector < pair& a,const pair& b){
if(a.second!=b.second) return a.second < b.second;
return a.first  <  b.first;
};
sort(agencies.begin(),agencies.end(),cmp);
printf("Case %d\n",tc++);
for(auto& p : agencies>
cout << p.first << " " << p.second << endl;
}
}
``````
Copy The Code &

Input

cmd
2
100 5 3
A:1,10
B:2,5
C:3,1
1123 1122 5
B:50,300
A:1,1000
C:10,10
D:1,50
E:0,0

Output

cmd
Case 1
C 7
B 22
A 37
Case 2 E 0
A 1
D 1
C 10
B 50