Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Maximum Pairwise Modular Sum codechef solution in c++

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

void solve()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> v(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	ll mx = INT_MIN;
	for (ll i = 0; i < n; i++)
	{
		mx = max(mx, v[i] - v[n - 1] + ((v[i] + v[n - 1] % m) + m));
	}
	cout << mx << "
";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: gtest assert not equal 
Cpp :: building native binary with il2cpp unity 
Cpp :: heapsort 
Cpp :: store arbitrarly large vector of doubles c++ 
Cpp :: C# adding numbers 
Cpp :: c++ *agrs 
Cpp :: c++ file handiling 
Cpp :: simple program for sign in and sign up in c++ 
Cpp :: no of balanced substrings 
Cpp :: Road sign detection and recognition by OpenCV in c 
Cpp :: find n unique integers sum up to zero 
Cpp :: cap phat dong mang 2 chieu trong c++ 
Cpp :: convert string to double arduino 
Cpp :: jquery datepicker default date not working 
Cpp :: how to find common divisors of two numbers in cpp 
Cpp :: permutation in c++ with backtracking 
Cpp :: txt to pdf CPP 
Cpp :: and condtion c++ 
Cpp :: how to point to next array using pointer c++ 
Cpp :: como copiar codigo de c++ con numeros de fila en docs 
Cpp :: assegnare valori in c++ 
Cpp :: max of 3 numbers in c++ 
Cpp :: statement that causes a function to end in c++ 
Cpp :: MPI_PUT 
Cpp :: how to refresh multiple command lines in C++ stream 
Cpp :: online compiler c++ with big O calculatorhttps://www.codegrepper.com/code-examples/cpp/how+to+convert+string+to+wchar_t+in+c%2B%2B 
Cpp :: c++ copy with transform 
Cpp :: c++ How can I make a std::vector of function pointers 
Cpp :: Studying Alphabet codechef solution in c++ 
Cpp :: why do men drink liquor 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =