Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Make them equal codechef solution in c++

/*
   problem link: https://www.codechef.com/LP1TO202/problems/MAKEEQUAL
*/

#include<iostream>
#include<climits>
#define ll long long
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;

void solve()
{
	ll n;
	cin >> n;
	vector<ll> v(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	ll mn = INT_MAX, mx = INT_MIN;
	for (ll i = 0; i < n; i++)
	{
		mn = min(mn, v[i]);
		mx = max(mx, v[i]);
	}
	cout << mx - mn << "
";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Make #equal #codechef #solution
ADD COMMENT
Topic
Name
2+2 =