# PROBLEM LINK:

*Author:* Pritish Priyatosh Nayak

*Tester:* Sibasish Ghosh

*Editorialist:* Pritish Priyatosh Nayak

# DIFFICULTY:

Simple

# PREREQUISITES:

None

# PROBLEM:

The problem basically boils down to checking whether after simulating the turn-based gameplay , the player manages to defeat the enemy or not.

# QUICK EXPLANATION:

If you observe carefully, you can notice that only the sum of attack values and sum of health values can determine the end result of the game.

# EXPLANATION:

If you read the rules of the fight you can notice that each party-member of the player can cause a total damage equal to his attack value to the enemy team.

A simple proof of this is that the party-member is able to attack the enemy party until his attack-value become 0.

And his attack value will become 0 only after he has done damage equal to his attack-value.

So it’s sufficient to just check if the sum of attack-values in the player team is greater than or equal to the sum of health values in the opponent team.

We don’t need to simulate the entire process to get the answer.

The tester solution ,however, has the simulation code incase anyone is curious.

# SOLUTIONS:

## Setter's/Editorialist's Solution

```
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
long long s1=0,s2=0;
for(int i=0;i<n;i++){
int x;
cin>>x;
s1+=x;
}
for(int i=0;i<n;i++){
int x;
cin>>x;
s2+=x;
}
if(s1>=s2){
cout<<"win\n";
}
else cout<<"lose\n";
}
return 0;
}
```

## Tester's Solution

```
#include<bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
typedef long long int ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;
cin>>t;
while(t--)
{
ll n,m,i,x;
cin>>n>>m;
multiset<ll> ms1,ms2;
for(i=0;i<n;i++)
{
cin>>x;
ms1.insert(-x);
}
for(i=0;i<m;i++)
{
cin>>x;
ms2.insert(-x);
}
while(ms1.size() && ms2.size())
{
auto it1=ms1.begin();
auto it2=ms2.begin();
ms1.erase(it1);
ms2.erase(it2);
ll val=-((*it1)-(*it2));
if(val > 0)
ms1.insert(-val);
else if(val < 0)
ms2.insert(val);
}
if(!ms2.size())
cout<<"win\n";
else cout<<"lose\n";
}
return 0;
}
```