question link: https://www.codechef.com/LTIME57/problems/HILLS
the code is giving WA in codechef, but giving correct output in dev c++. can u please tell me where i am wrong ?
#include<iostream> using namespace std; int main() { long long int a[103],u,d; int t,n,c=0,i; cin>>t; while(t--) { cout<<"\n"; cin>>n>>u>>d; for(i=0;i<n;i++) cin>>a[i]; i=0; while(i<(n-1)) { if((a[i+1]==(a[i]+u)) || (a[i+1]==(a[i]-d)) || (a[i+1]==a[i])) i++; else if((a[i+1]<a[i]) && c==0) { c=1; i++; } else break; } cout<<"\n"<<(i+1); c=0; } return 0; }
Asked by: Samrat_De on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.