Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector < int > contenitori;
- vector < int > copia;
- vector <int> list_B;
- vector < int> list_A;
- bool myfunction (int i,int j) { return (j<i); }
- int ricerca (int a)
- {
- int lunghezza = list_A.size();
- for (int i=0;i<lunghezza;i++)
- {
- if(a==list_A.at(i))
- {
- return 0;
- }
- }
- lunghezza = list_B.size();
- for (int i=0;i<lunghezza;i++)
- {
- if(a==list_B.at(i))
- {
- return 1;
- }
- }
- return 2;
- }
- int main() {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- int A, B , N;
- cin>>A;
- cin>>B;
- cin>>N;
- for(int i = 0; i<N;i++)
- {
- int temp;
- cin>>temp;
- contenitori.push_back(temp);
- copia.push_back(temp);
- }
- sort(copia.begin(),copia.end(),myfunction);
- int i=0;
- while(B>0)
- {
- B -= copia.at(i);
- list_B.push_back(copia.at(i));
- i++;
- }
- i=0;
- while(A>0)
- {
- A -= copia.at(N-1-i);
- list_A.push_back(copia.at(N-1-i));
- i++;
- }
- for(int i = 0; i<N;i++)
- {
- int temp = contenitori.at(i);
- if(ricerca(temp)==0)
- {
- cout<<temp<<" "<<0<<endl;
- }
- else if (ricerca(temp)==1)
- {
- cout<<0<<" "<<temp<<endl;
- }
- else
- {
- cout<<0<<" "<<0<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement