Advertisement
Diene

Untitled

Jan 23rd, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct info{
  6.     int k,da,db,dif;
  7.     char m;
  8. };
  9.  
  10. bool comp(info a, info y){
  11.     return a.dif>=y.dif;
  12. }
  13.  
  14. int main(){
  15.  
  16.     int n,a,b;
  17.     vector <info> times;
  18.     times.resize(1005);
  19.     while(scanf("%d%d%d", &n,&a,&b)){
  20.         times.clear();
  21.         int soma=0;
  22.         if(n==0 && a==0 && b==0) break;
  23.         for(int i=0;i<n;i++){
  24.             scanf("%d%d%d", &times[i].k,&times[i].da,&times[i].db);
  25.             if(times[i].da>=times[i].db){
  26.                 times[i].m='b';
  27.                 times[i].dif=(times[i].da-times[i].db);
  28.             }
  29.             else{
  30.                 times[i].m='a';
  31.                 times[i].dif=(times[i].db-times[i].da);
  32.             }
  33.         }
  34.         sort(times.begin(), times.begin()+n, comp);
  35.  
  36.         for(int i=0;i<n;i++){
  37.             if(times[i].m=='b' && b>=times[i].k){
  38.                 soma=soma+times[i].k*times[i].db;
  39.                 b=b-times[i].k;
  40.             }
  41.             else if(times[i].m=='a' && a>=times[i].k){
  42.                 soma=soma+times[i].k*times[i].da;
  43.                 a=a-times[i].k;
  44.             }
  45.             else if(times[i].m=='b' && b<times[i].k){
  46.                 soma=soma+b*times[i].db+(times[i].k-b)*times[i].da;
  47.                 a=a-(times[i].k-b);
  48.                 b=0;
  49.             }
  50.             else if(times[i].m=='a' && a<times[i].k){
  51.                 soma=soma+a*times[i].da+(times[i].k-a)*times[i].db;
  52.                 b=b-(times[i].k-a);
  53.                 a=0;
  54.             }
  55.         }
  56.         printf("%d\n", soma);
  57.  
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement