I was trying out this problem and tried the following code in c++:
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int T;
cin >> T;
for(int i = 0; i < T; i++){
int N;
long long minX, maxX;
scanf("%lld",&minX);
scanf("%lld",&maxX);
int weight_bias[N][2];
cin >> N;
for(int i = 0; i < N; i ++)
{
long long w_i, b_i;
scanf("%lld",&w_i);
scanf("%lld",&b_i);
weight_bias[i][0] = (w_i%2);
weight_bias[i][1] = (b_i%2);
}
int k = 0;
for(int t = N-1; t >= 0; t--)
{
if(weight_bias[k][0] % 2 == 0){
k = t;
break;
}
}
int tester;
for(int t = k; t < N; t++)
{
tester = tester + weight_bias[k][1];
}
int spam = 0;
int nonspam = 0;
for(int i = minX; i <= maxX; i++)
{
if((i + tester)%2 == 0)
{
nonspam++;
}
else{spam++;}
}
cout << nonspam << " " << spam << "\n";
}
return 0;
}
But I am getting wrong results.
Could anyone point out where I am wrong??
If something is not clear, please do point out.