You are not logged in. Please login at www.codechef.com to post your questions!

×

CHEGLOVE - Editorial

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[i] \le G[i]$ 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[i] \le G[i]$ 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[i] \le G[i]$ 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

This question is marked "community wiki".

asked 11 Mar, 17:56

adkroxx's gravatar image

7★adkroxx
306719
accept rate: 7%

edited 13 Mar, 15:29

admin's gravatar image

0★admin ♦♦
19.6k349497539


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&lt;n;j++)" {="" for(k="0;k&lt;n;k++)" {="" if(j="=n)" count="2;" }="" for(k="n-1;k">=0;k--) { if(j==n) count++; } if(count==0) printf("none\n"); if(count==1) printf("back\n"); if(count==2) printf("front\n"); if(count==3) printf("equal"\n); } return 0; }

link

answered 14 Sep, 10:41

avaneesh_3069's gravatar image

0★avaneesh_3069
1
accept rate: 0%

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&lt;n;j++)" {="" for(k="0;k&lt;n;k++)" {="" if(j="=n)" count="2;" }="" for(k="n-1;k">=0;k--) { if(j==n) count++; } if(count==0) printf("none\n"); if(count==1) printf("back\n"); if(count==2) printf("front\n"); if(count==3) printf("equal"\n); } return 0; }

link

answered 14 Sep, 10:42

avaneesh_3069's gravatar image

0★avaneesh_3069
1
accept rate: 0%

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[i]); for(i=0;i<n;i++) scanf("%d",&g[i]); for(i=0;i<n;i++) { if(a[i]<=g[i]) count1++; } for(i=0;i<n;i++) { if(a[i]<=g[n-1-i]) count2++; } if(count1==n && count2==n ) printf("both\n"); else if(count1==n) printf("front\n"); else if(count2==n) printf("back\n"); else printf("none\n"); } return 0; }

link

answered 08 Oct, 10:57

kl_30574's gravatar image

0★kl_30574
1
accept rate: 0%

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[i]);

     for(i=0;i<n;i++)
    scanf("%d",&g[i]);

    for(i=0;i<n;i++)
    {


         if(l[i]<=g[i])
          f++;
         }
      for(i=0;i<n;i++)
    {

      if(l[i]<=g[n-i-1])
          b++;



    }

    if(f==n && b==n)
      printf("both\n");

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

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

        else
        printf("none\n");


}


return 0;

}

link

answered 09 Oct, 20:39

devi_asapu13's gravatar image

0★devi_asapu13
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,198
×1,132
×795
×265
×5

question asked: 11 Mar, 17:56

question was seen: 838 times

last updated: 09 Oct, 20:39