Problem Code:FFL. In this question, my code is perfectly working in my Pycharm. But it showing runtime error when I am submitting it. When I try for custom output, the code is running. Please check and reply back.

Maybe you ignored the case when there is NO attacker or NO defender

Link your solution from next time.

Try

```
1
1 90
3
0
```

In fact any time the minimum is the last index you’ll get a runtime error.

The mistake is that you are popping `index`

and the using `player[index]`

. Your approach has way too many edge cases.

I would recommend just iterating over all the players and calculate the minimum price of a defender and attacker.

## Like this

```
for _ in range(int(input())):
n, s = map(int, input().split())
price=list(map(int, input().split()))
type=list(map(int, input().split()))
minattack=1000
mindefend=1000
for i in range(n):
if(type[i]==0):
mindefend=min(mindefend, price[i])
elif(type[i]==1):
minattack=min(minattack, price[i])
print("yes" if s+minattack+mindefend<=100 else "no")
```

I have used the exact same logic as @everule1 but still i got wrong answer.

minattack=INT_MAX mindefend=INT_MAX the only diffrence in my code and yours is i use INT_MAX as the initializers.

Plz Help.

-------------------------------- Code ----------------------------------------------------------

#include <bits/stdc++.h>

using namespace std;

int main() {

int t;

cin>>t;

assert(t>=1 and t<=100);

while(t–)

{

int n,s;

cin>>n>>s;

std::vectorcost ;

std::vectorplayers ;

assert(s>=13 and s<=100);

assert(n>=1 and n<=100);

for(int i=0;i<n;i++)

{

int temp;

cin>>temp;

assert(temp >= 1 and temp <= 100);

cost.push_back(temp);

}

```
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
players.push_back(temp);
}
int max = 100;
int def = INT_MAX;
int forw = INT_MAX;
for(int i=0;i<n;i++)
{
if(players[i]==0)
{
if(cost[i]<def)
{
def = cost[i];
}
}
else
{
if(players[i] == 1)
{
if(cost[i] < forw)
{
forw = cost[i];
}
}
}
}
int res = def + forw + s;
//std::cout << res << std::endl;
if(res <= max)
{
std::cout << "yes" << std::endl;
}
else
{
std::cout << "no" << std::endl;
}
}
return 0;
```

}

Adding int max to another number will overflow.

I’m assuming you are using C++.

When pasting code always Format it.

Yes bro .

Iam new to this competitive programming so iam trying to learn new things and lease forgive me for my silly mistakes.

@everule1 the tip you gave it works bro.Thanx

But i have a question when i use this code in cpp.sh website it runs perfectly and does not give me any errors why is that can anyone please explain?

Firstly, C++ assumes you are correct and won’t inform you about any overflows. You need to specify

`pragma GCC optimize "trapv"`

, which will abort your code on any overflow. Secondly, That overflow will only happen when there is no defender or attacker.

```
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
std::vector<long>arr ;
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
arr.push_back(temp);
}
for(int i=0;i<=n-k;i++)
{
if(arr[i]>arr[i+k])
{
int temp = arr[i];
arr[i]=arr[i+k];
arr[i+k] = temp;
}
for(int j=i%k;j<=n-k;j+=k)
{
if(arr[j]>arr[j+k])
{
int temp = arr[j];
arr[j]=arr[j+k];
arr[j+k] = temp;
}
}
}
int flag = 0;
for(int i=0;i<n;i++)
{
if(arr[i]>arr[i+1] and (i+1)<n)
{
flag = 1;
break;
}
}
if(flag == 0)
{
std::cout << "yes" << std::endl;
}
else
{
std::cout << "no" << std::endl;
}
}
return 0;
}
```

```
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k,flag1=0;
cin>>n>>k;
long int a[n+1]= {};
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=n-k; i++)
{
if(a[i]>a[i+k])
{
int temp=a[i+k];
a[i+k]=a[i];
a[i]=temp;
}
for(int j=i%k; j<=n-k; j+=k)
{
if(a[j]>a[j+k])
{
int temp=a[j+k];
a[j+k]=a[j];
a[j]=temp;
}
}
}
for(int i=1; i<n; i++)
if(a[i]>a[i+1])
{
flag1=1;
break;
}
if(flag1==0)
cout<<"yes"<<"\n";
else
cout<<"no"<<"\n";
}
return 0;
}
```

First One is my code which is giving wrong answer in codechef and second one is the code which is compiling fine and passing all the test cases .

Can anyone please tell me why iam not passing the test cases as my logic is same as the second code /