VISA - Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Practice

Setter: Daanish Mahajan
Tester & Editorialist: Taranpreet Singh

DIFFICULTY

Cakewalk

PREREQUISITES

None

PROBLEM

Ash is trying to get visa to Chefland. For the visa to be approved, he needs to satisfy the following three criteria:

  • Solve at least x_1 problems on Codechef.
  • Have at least y_1 current rating on Codechef.
  • Make his last submission at most z_1 months ago.

You are given the number of problems solved by Chef (x_2), his current rating (y_2) and the information that he made his last submission z_2 months ago. Determine whether he will get the visa.

QUICK EXPLANATION

Ash can go to chefland if and only if x_2 \geq x_1, y_2 \geq y_1 and z_2 \leq z_1 holds.

EXPLANATION

This problem is just meant to test users familiarity with the programming language constructs, we just need to implement the mentioned conditions.

We need to check

  • If the number of problems solved x_2 is at least x_1, implying we need to check whether x_2 \geq x_1 holds.
  • If the current rating is at least y_2 is at least y_1, implying we need to check whether y_2 \geq y_1 holds.
  • If the number of months since last submission z_2 is at most z_1, implying we need to check whether z_2 \leq z_1

If and only if all of the conditions are satisfied, Ash can go to Chefland.

One way to implement this would be using AND operator, denoted by && in most languages.

if x2 >= x1 && y2 >= y1 && z2 <= z1: YES
else: NO

Another way without AND operator is as follows, by making a count variable, storing the number of conditions satisfied.

count = 0
if x2 >= x1: count++
if y2 >= y1: count++
if z2 <= z1: count++

if count == 3: YES
else: NO

TIME COMPLEXITY

The time complexity is O(1) per test case.

SOLUTIONS

Setter's Solution
#include<bits/stdc++.h>
# define pb push_back 
#define pii pair<int, int>
#define mp make_pair
# define ll long long int

using namespace std;
const int maxt = 5000;
const string newln = "\n", space = " ";
int main()
{   
    int t, x, x1, y, y1, z, z1; cin >> t; 
    while(t--){
        cin >> x >> x1 >> y >> y1 >> z >> z1;
        string ans = (x1 >= x && y1 >= y && z1 <= z) ? "YeS" : "No";
        cout << ans << endl;            
    }
} 
Tester's Solution
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
  
  
long long readInt(long long l,long long r,char endd){
    long long x=0;
    int cnt=0;
    int fi=-1;
    bool is_neg=false;
    while(true){
	    char g=getchar();
	    if(g=='-'){
		    assert(fi==-1);
		    is_neg=true;
		    continue;
	    }
	    if('0'<=g && g<='9'){
		    x*=10;
		    x+=g-'0';
		    if(cnt==0){
			    fi=g-'0';
		    }
		    cnt++;
		    assert(fi!=0 || cnt==1);
		    assert(fi!=0 || is_neg==false);
		    
		    assert(!(cnt>19 || ( cnt==19 && fi>1) ));
	    } else if(g==endd){
		    if(is_neg){
			    x= -x;
		    }
		    assert(l<=x && x<=r);
		    return x;
	    } else {
		    assert(false);
	    }
    }
}
string readString(int l,int r,char endd){
    string ret="";
    int cnt=0;
    while(true){
	    char g=getchar();
	    assert(g!=-1);
	    if(g==endd){
		    break;
	    }
	    cnt++;
	    ret+=g;
    }
    assert(l<=cnt && cnt<=r);
    return ret;
}
long long readIntSp(long long l,long long r){
    return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
    return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
    return readString(l,r,'\n');
}
string readStringSp(int l,int r){
    return readString(l,r,' ');
}
  
int main(){
    int T = readIntLn(1, 5000);
    while(T-->0){
        int x1 = readIntSp(20, 50), x2 = readIntSp(20, 50);
        int y1 = readIntSp(1900, 2100), y2 = readIntSp(1900, 2100);
        int z1 = readIntSp(1, 6), z2 = readIntLn(1, 6);

        int count = 0;
        if(x2 >= x1)count++;
        if(y2 >= y1)count++;
        if(z2 <= z1)count++;
        if(count == 3)cout<<"YES\n";
        else cout<<"NO\n";
    }
    assert(getchar()==-1);
    cerr<<"SUCCESS\n";
}

Feel free to share your approach. Suggestions are welcomed as always. :slight_smile:

WHy is the sever not allowing to submit some of these questions as practice

1 Like

I’m having same issue, missed the contest and not able to practice now…

Exactly! its weird
@admin please have a look over it