CHEGLOVE - Editorial

cheglove
editorial
implementation
march18
simple

#1

PROBLEM LINK:

Div1, Div2
Practice

Author: Praveen Dhinwa
Tester: Triveni Mahatha
Editorialist: Adarsh Kumar

DIFFICULTY:

Simple

PREREQUISITES:

None

PROBLEM:

You are given two array's $L$ and $G$ of $N$ integers. You need to check if $L* \le G*$ for all $1 \le i \le N$. You need to repeat this task after reversing $G$ too.

EXPLANATION:

This problem is really simple. You just need to implement whatever the problem states.

For chef to wear the glove in “front” position, check if L* \le G* for all 1 \le i \le N. This can be done using a linear traversal of both the array. Similarly, for chef to wear the glove in “back” position just reverse the array G and check if L* \le G* for all 1 \le i \le N.

Now you just need to output “front”, “back”, “both”, or “none” depending upon the conditions fulfilled.

Time Complexity:

$O(N)$

AUTHOR'S AND TESTER'S SOLUTIONS

Setter's solution
Tester's solution


#2

#include<stdio.h>
int main()
{
int i,T,count;
scanf("%d",&T);
for(i=0;i<T;i++)
int j,k,n;
scanf("%d",&n);
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
if(j==n)
count=2;
}
for(k=n-1;k>=0;k–)
{
if(j==n)
count++;
}
if(count==0)
printf("none
");
if(count==1)
printf("back
");
if(count==2)
printf("front
");
if(count==3)
printf(“equal”
);
}
return 0;
}


#3

#include<stdio.h>
int main()
{
int i,T,count;
scanf("%d",&T);
for(i=0;i<T;i++)
int j,k,n;
scanf("%d",&n);
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
if(j==n)
count=2;
}
for(k=n-1;k>=0;k–)
{
if(j==n)
count++;
}
if(count==0)
printf("none
");
if(count==1)
printf("back
");
if(count==2)
printf("front
");
if(count==3)
printf(“equal”
);
}
return 0;
}


#4

#include<stdio.h>
#include<math.h>
int main() { int t; scanf("%d",&t); while(t–) { int n,i,count1=0,count2=0; scanf("%d",&n); int a[n],g[n]; for(i=0;i<n;i++) scanf("%d",&a*); for(i=0;i<n;i++) scanf("%d",&g*); for(i=0;i<n;i++) { if(a*<=g*) count1++; } for(i=0;i<n;i++) { if(a*<=g[n-1-i]) count2++; } if(count1==n && count2==n ) printf("both
"); else if(count1==n) printf("front
"); else if(count2==n) printf("back
"); else printf("none
"); } return 0; }


#5

#include <stdio.h>

int main(void) {

int t,n,i;

int l[100000000],g[100000000];
scanf("%d",&t);
while(t–!=0)
{
int b=0,bo=0,f=0;
scanf("%d",&n);

    for(i=0;i<n;i++)
    scanf("%d",&l*);
   
     for(i=0;i<n;i++)
    scanf("%d",&g*);
   
    for(i=0;i<n;i++)
    {
      
         
         if(l*<=g*)
          f++;
         }
      for(i=0;i<n;i++)
    {
      
      if(l*<=g[n-i-1])
          b++;
         

       
    }
   
    if(f==n && b==n)
      printf("both

");

       else if(f==n)
      printf("front

");

      else if(b==n)
       printf("back

");

        else
        printf("none

");

}


return 0;

}