Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int test,i,j,battle,green,blue,a,mn;
- scanf("%d",&test);
- while(test--)
- {
- scanf("%d%d%d",&battle,&green,&blue);
- multiset<int>Gr,Bl;
- vector<int>SG,SB;
- for(i=1; i<=green; i++)
- {
- scanf("%d",&a);
- Gr.insert(a);
- }
- for(i=1; i<=blue; i++)
- {
- scanf("%d",&a);
- Bl.insert(a);
- }
- mn = min(Gr.size(),Bl.size());
- multiset<int>::iterator G_nd,B_nd;
- while(mn>0)
- {
- SG.clear();
- SB.clear();
- for(i=0; i<battle && mn>0; i++)
- {
- G_nd = Gr.end();
- G_nd--;
- B_nd = Bl.end();
- B_nd--;
- if(*G_nd > *B_nd)
- {
- Gr.erase(G_nd);
- Bl.erase(B_nd);
- SG.push_back(*G_nd - *B_nd);
- }
- else if(*G_nd < *B_nd)
- {
- Gr.erase(G_nd);
- Bl.erase(B_nd);
- SB.push_back(*B_nd - *G_nd);
- }
- else
- {
- Gr.erase(G_nd);
- Bl.erase(B_nd);
- }
- mn = min(Gr.size(),Bl.size());
- }
- for(j=0; j<SG.size(); j++)
- {
- Gr.insert(SG[j]);
- }
- for(j=0; j<SB.size(); j++)
- {
- Bl.insert(SB[j]);
- }
- mn = min(Gr.size(),Bl.size());
- }
- if(!Gr.size() && !Bl.size())
- {
- printf("green and blue died\n");
- }
- else if(Gr.size()>0)
- {
- printf("green wins\n");
- G_nd = Gr.end();
- G_nd--;
- for( ; G_nd!=Gr.begin();G_nd--)
- {
- printf("%d\n",*G_nd);
- }
- printf("%d\n",*G_nd);
- }
- else
- {
- printf("blue wins\n");
- B_nd = Bl.end();
- B_nd--;
- for( ; B_nd!=Bl.begin();B_nd--)
- {
- printf("%d\n",*B_nd);
- }
- printf("%d\n",*B_nd);
- }
- if(test>0)
- {
- puts("");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment