can anyone help me in understanding this question . it was an easy question but still i was not able to get AC .

Правка en1, от pkpawan, 2019-12-29 20:58:50

Here is the question :-https://codeforces.net/contest/1270/problem/B

what i understood from the question that we need to find subarrays such that the difference of maximum and minimun element is equal to N (total emenets of array ) ,if it is not possible print "NO" else print "YES" and in next line print 1 and 'ending index' but if we are given an array 'A' and it is statifying condition max(A)-max(B)>=N then according to question answer should be 'YES' 1 N(size of array)

which we even need to check for subarray ?that's all I understood from question please help me out in understanding correctly

here's my code:- ```

include

include<bits/stdc++.h>

using namespace std;

int main() { int t; cin>>t; while(t--) { int n,f=0; cin>>n;

int A[n],i,j,min=0,max=0,l,r;
   for(i=0;i<n;++i)
   {
       cin>>A[i];
       if(max<A[i])
       {
           max=A[i];         //finding max
       }

   }
   min=A[0];
   for(i=1;i<n;++i)
   {
       if(min>A[i])
       { 
           min=A[i];               //finding min
       } 
   }


  if(max-min>=n)                   //checking condition max(A)-min(A)=n
  {
      for(i=0;i<n;++i)
      {
          if(A[i]==min)            //checking at what index is min and max present
          {
              l=i+1;                  //adding 1 in index as index taken from 0 to n-1
          }
          if(A[i]==max)
          {
              r=i+1;
          }
      }
      if(l<r)                           //checking which is greater and printing accordingly
      {
      cout<<"YES"<<endl;
      cout<<l<<" "<<r<<endl;
      }
      else
      {
          cout<<"YES"<<endl;
      cout<<r<<" "<<l<<endl;
      }

  }
  else
  {
      cout<<"NO"<<endl;
  }

}

return 0;

}```

Теги #c++, #help me, #contest

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский pkpawan 2019-12-29 21:00:41 21
en1 Английский pkpawan 2019-12-29 20:58:50 2202 Initial revision (published)