Advertisement
O_Egor

Interactive

Nov 11th, 2019
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n,m;
  8.     cin>>n>>m;
  9.     vector <int> vp;
  10.     map <int, int> mp;
  11.     for(int i=0;i<2*n;++i)
  12.     {
  13.         int a;
  14.         cin>>a;
  15.         vp.push_back(a);
  16.         mp[i+1]=a;
  17.     }
  18.     sort(vp.begin(),vp.end());
  19.     for(int i=0;i<2*n;++i)
  20.         cout<<vp[i]<<' ';
  21.     cout<<'\n';
  22.     /*for(auto it=mp.begin();it!=mp.end();++it)
  23.         cout<<it->first<<' '<<it->second<<'\n';
  24.     cout<<max(mp[1],mp[6]);*/
  25.     vector <int> vs(2*n,-1);
  26.     int k=1;
  27.     for(int i=0;i<m;++i)
  28.     {
  29.         int a, b;
  30.         cin>>a>>b;
  31.         vs[a-1]=k;
  32.         vs[b-1]=k;
  33.         k++;
  34.     }
  35.     for(int i=0;i<2*n;++i)
  36.         cout<<vs[i];
  37.     int t;
  38.     cin>>t;
  39.     bool ff(1);
  40.     if(t%2)
  41.     {
  42.         for(int i=0;i<n;++i)
  43.         {
  44.             int pos1,pos2;
  45.             for(int o=0;o<2*n;++o)
  46.                 if(vs[o]>0)
  47.                 {
  48.                     ff=0;
  49.                     break;
  50.                 }
  51.             if(ff==0)
  52.             {
  53.                 for(int j=vs.size();j>-1;--j)
  54.                 {
  55.                     //cout<<"AAAAAAAA";
  56.                     bool f(0);
  57.                     if(vs[j]>0)
  58.                         pos1=j;
  59.                     for(int jj=0;jj<vs.size();++jj)
  60.                         if(vs[pos1]==vs[jj]&&jj!=pos1)
  61.                         {
  62.                             //cout<<"BBBBB";
  63.                             f=1;
  64.                             pos2=jj+1;
  65.                             break;
  66.                         }
  67.                     if(f)
  68.                         break;
  69.                 }
  70.             }
  71.             if(ff)
  72.             {
  73.                 for(int j=vp.size()-1;j>-1;++j)
  74.                 {
  75.                     bool fff(0);
  76.                     if(vp[j]>0)
  77.                         for(auto it=mp.begin();it!=mp.end();++it)
  78.                             if(vp[j]==it->second)
  79.                             {
  80.                                 fff=1;
  81.                                 vp[it->second - 1]=0;
  82.                                 cout<<it->first<<endl;
  83.                                 break;
  84.                             }
  85.                     if(fff)
  86.                         break;
  87.                 }
  88.  
  89.  
  90.             }
  91.             else
  92.             {
  93.                 pos1++;
  94.                 int mx=max(mp[pos1],mp[pos2]);
  95.                 //cout<<"ass"<<endl;
  96.                 if(mp[pos1]==mx)
  97.                 {
  98.                     cout<<pos1<<endl;
  99.                     vp[pos1-1]=0;
  100.                 }
  101.                 else
  102.                 {
  103.                     cout<<pos2<<endl;
  104.                     vp[pos2-1]=0;
  105.                 }
  106.                 vs[pos1-1]=0;
  107.                 vs[pos2-1]=0;
  108.             }
  109.             int g;
  110.             cin>>g;
  111.             vp[g-1]=0;
  112.         }
  113.     }
  114.     return 0;
  115. }
  116. /**
  117. 3 3
  118. 700 50 500 60 30 48
  119. 1 6
  120. 2 5
  121. 3 4
  122.  
  123. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement