In this Codechef Rating Improvement problem solution Chef's current rating is XX, and he wants to improve it. It is generally recommended that a person with rating XX should solve problems whose difficulty lies in the range [X, X+200][X,X+200], i.e, problems whose difficulty is at least XX and at most X+200X+200.
You find out that Chef is currently solving problems with a difficulty of YY.
Is Chef following the recommended practice or not?
Problem solution in Python.
# cook your dish here
T = int(input())
for i in range(T):
X,Y = map(int,input().split())
if (X<=Y<=X+200):
print("Yes")
else:
print("No")
Problem solution in Java.
import java.io.*;
import java.util.*;
class codechef {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new PrintWriter(System.out)));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
while (t --> 0) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
sb.append((y >= x && y <= x + 200 ? "Yes" : "No") + "\n");
}
pw.println(sb.toString().trim());
pw.close();
}
}
Problem solution in C++.
#include <iostream>
using namespace std;
int main() {
// your code goes here
int T;
cin >> T;
for(int i =0; i < T; i++){
int X,Y,Z;
(cin >> X ) >> Y;
Z = X+200;
if(X <= Y && Z >= Y){
cout << "YES";
}else{
cout << "NO";
}
cout << "\n";
}
return 0;
}
Problem solution in C.
#include <stdio.h>
int main(void) {
// your code goes here
int P;
scanf("%d",&P);
int S,F;
while(P--)
{
scanf("%d %d",&S,&F);
if(F>=S && F<=(S+200))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

0 Comments