Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,m;
- cin>>n>>m;
- vector <int> vp;
- map <int, int> mp;
- for(int i=0;i<2*n;++i)
- {
- int a;
- cin>>a;
- vp.push_back(a);
- mp[i+1]=a;
- }
- sort(vp.begin(),vp.end());
- for(int i=0;i<2*n;++i)
- cout<<vp[i]<<' ';
- cout<<'\n';
- /*for(auto it=mp.begin();it!=mp.end();++it)
- cout<<it->first<<' '<<it->second<<'\n';
- cout<<max(mp[1],mp[6]);*/
- vector <int> vs(2*n,-1);
- int k=1;
- for(int i=0;i<m;++i)
- {
- int a, b;
- cin>>a>>b;
- vs[a-1]=k;
- vs[b-1]=k;
- k++;
- }
- for(int i=0;i<2*n;++i)
- cout<<vs[i];
- int t;
- cin>>t;
- bool ff(1);
- if(t%2)
- {
- for(int i=0;i<n;++i)
- {
- int pos1,pos2;
- for(int o=0;o<2*n;++o)
- if(vs[o]>0)
- {
- ff=0;
- break;
- }
- if(ff==0)
- {
- for(int j=vs.size();j>-1;--j)
- {
- //cout<<"AAAAAAAA";
- bool f(0);
- if(vs[j]>0)
- pos1=j;
- for(int jj=0;jj<vs.size();++jj)
- if(vs[pos1]==vs[jj]&&jj!=pos1)
- {
- //cout<<"BBBBB";
- f=1;
- pos2=jj+1;
- break;
- }
- if(f)
- break;
- }
- }
- if(ff)
- {
- for(int j=vp.size()-1;j>-1;++j)
- {
- bool fff(0);
- if(vp[j]>0)
- for(auto it=mp.begin();it!=mp.end();++it)
- if(vp[j]==it->second)
- {
- fff=1;
- vp[it->second - 1]=0;
- cout<<it->first<<endl;
- break;
- }
- if(fff)
- break;
- }
- }
- else
- {
- pos1++;
- int mx=max(mp[pos1],mp[pos2]);
- //cout<<"ass"<<endl;
- if(mp[pos1]==mx)
- {
- cout<<pos1<<endl;
- vp[pos1-1]=0;
- }
- else
- {
- cout<<pos2<<endl;
- vp[pos2-1]=0;
- }
- vs[pos1-1]=0;
- vs[pos2-1]=0;
- }
- int g;
- cin>>g;
- vp[g-1]=0;
- }
- }
- return 0;
- }
- /**
- 3 3
- 700 50 500 60 30 48
- 1 6
- 2 5
- 3 4
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement