 # DIVARRAY - EDITORIAL

Author: Pratik Suryawanshi

Editorialist: Pratik Suryawanshi

Simple

STACK

# PROBLEM:

You have given an Array of length N , Write program to find out second Highest number
from array to which after dividing by X reminder should be Y

# QUICK EXPLANATION:

Print second highest number of array to which after dividing by X we get reminder Y

# EXPLANATION:

at first we will sort array in incresing order then check each element of array from left
to right is it giving reminder Y after dividing by X, if it is giving reminder Y then
increment the count by 1, if count=2 then print address of i.

# SOLUTIONS:

Setter's Solution

#pragma GCC optimize(“Ofast”)
#pragma GCC target(“avx,avx2,fma”)
#pragma GCC optimization(“unroll-loops”)
#include <bits/stdc++.h>
using namespace std;
#define tc ll t sc cin >> t sc while (t–)
#define ff first
#define vp vector<pair<ll,ll>>
#define sc ;
#define ss second
#define srt sort
#define endl ‘\n’
#define pb push_back
#define pp pop_back
#define mp make_pair
#define modulo 1e9+7
#define ll long long int
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define INF 1001001001
const long double pi = 3.141592653;

typedef unsigned int ui;
typedef unsigned long long int ul;

int main()
{

``````#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("errorf.txt" , "w" , stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

tc
{
int n,x,y;
cin >> n>> x >> y;
int arr[n];
int cnt=0;
for(int i=0;i<n;i++){
cin >> arr[i];
}
srt(arr,arr+n);
for(int i=0;i<n;i++){
if(((arr[i])%x)==y){
cnt++;
}
if(cnt==2){
cout << arr[i] << endl;
break;
}
}
}
return 0;
``````

}