Advertisement
xDefo

Chimico(risolto)

Nov 7th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>    
  4. using namespace std;
  5. vector < int > contenitori;
  6. vector < int > copia;
  7. vector <int> list_B;
  8. vector < int> list_A;
  9. bool myfunction (int i,int j) { return (j<i); }
  10. int ricerca (int a)
  11. {
  12.     int lunghezza = list_A.size();
  13.     for (int i=0;i<lunghezza;i++)
  14.     {
  15.         if(a==list_A.at(i))
  16.         {
  17.             return 0;
  18.         }
  19.     }
  20.     lunghezza = list_B.size();
  21.     for (int i=0;i<lunghezza;i++)
  22.     {
  23.         if(a==list_B.at(i))
  24.         {
  25.             return 1;
  26.         }
  27.     }
  28.     return 2;
  29. }
  30. int main() {
  31.     freopen("input.txt","r",stdin);
  32.     freopen("output.txt","w",stdout);
  33.     int A, B , N;
  34.     cin>>A;
  35.     cin>>B;
  36.     cin>>N;
  37.     for(int i = 0; i<N;i++)
  38.     {
  39.         int temp;
  40.         cin>>temp;
  41.         contenitori.push_back(temp);
  42.         copia.push_back(temp);
  43.     }
  44.     sort(copia.begin(),copia.end(),myfunction);
  45.     int i=0;
  46.     while(B>0)
  47.     {
  48.         B -= copia.at(i);
  49.         list_B.push_back(copia.at(i));
  50.         i++;
  51.     }
  52.     i=0;
  53.     while(A>0)
  54.     {
  55.         A -= copia.at(N-1-i);
  56.         list_A.push_back(copia.at(N-1-i));
  57.         i++;
  58.     }
  59.     for(int i = 0; i<N;i++)
  60.     {
  61.         int temp = contenitori.at(i);
  62.         if(ricerca(temp)==0)
  63.         {
  64.             cout<<temp<<" "<<0<<endl;
  65.         }
  66.         else if (ricerca(temp)==1)
  67.         {
  68.             cout<<0<<" "<<temp<<endl;
  69.         }
  70.         else
  71.         {
  72.             cout<<0<<" "<<0<<endl;
  73.         }
  74.     }
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement