Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct info{
- int k,da,db,dif;
- char m;
- };
- bool comp(info a, info y){
- return a.dif>=y.dif;
- }
- int main(){
- int n,a,b;
- vector <info> times;
- times.resize(1005);
- while(scanf("%d%d%d", &n,&a,&b)){
- times.clear();
- int soma=0;
- if(n==0 && a==0 && b==0) break;
- for(int i=0;i<n;i++){
- scanf("%d%d%d", ×[i].k,×[i].da,×[i].db);
- if(times[i].da>=times[i].db){
- times[i].m='b';
- times[i].dif=(times[i].da-times[i].db);
- }
- else{
- times[i].m='a';
- times[i].dif=(times[i].db-times[i].da);
- }
- }
- sort(times.begin(), times.begin()+n, comp);
- for(int i=0;i<n;i++){
- if(times[i].m=='b' && b>=times[i].k){
- soma=soma+times[i].k*times[i].db;
- b=b-times[i].k;
- }
- else if(times[i].m=='a' && a>=times[i].k){
- soma=soma+times[i].k*times[i].da;
- a=a-times[i].k;
- }
- else if(times[i].m=='b' && b<times[i].k){
- soma=soma+b*times[i].db+(times[i].k-b)*times[i].da;
- a=a-(times[i].k-b);
- b=0;
- }
- else if(times[i].m=='a' && a<times[i].k){
- soma=soma+a*times[i].da+(times[i].k-a)*times[i].db;
- b=b-(times[i].k-a);
- a=0;
- }
- }
- printf("%d\n", soma);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement