I'm new to Codeforces and have attempted for the first time today.
Following is the solution that I have found while solving the first question.
Here is my solution to the above question:
#include<bits/stdc++.h>
using namespace std;
int main(){
int no_of_times;
cin>>no_of_times;
for(int l = 0;l < no_of_times;l++){
int n,k;
cin>>n>>k;
if(n == 1 && k == 1){
cout<<1<<"\n";
}
else if(n == 1 && n > k){
cout<<1<<"\n";
}
else if(n > k){
if(n%2 == 0 && k%2 == 0){
cout<<0<<"\n";
}
else if(n%2 == 0 || k%2 == 0){
cout<<1<<"\n";
}
else{
cout<<0<<"\n";
}
}
else{
cout<<(k-n)<<"\n";
}
}
}
I've passed pre-test 1, but failed on pretest 2. May I know where was I wrong?
Aucun commentaire:
Enregistrer un commentaire