NUCLEARREAC - Editorial
Problem link : NUCLEARREAC
Author : shyam1909
Tester : shyam1909
Editorialist : shyam1909
Difficulty Level : Easy
Approach:
Greedy.
Under the given constraints, we can run a brute force solution for every possible pair of reactors and check the total radiation by performing the given operation on the two reactors.
Solution:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
int n;
cin >> n;
int arr[n];
ll sm = 0;
for(int i = 0; i < n; i++){
cin >> arr[i];
sm += arr[i];
}
int mn = INT_MAX;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 1;k <= arr[i]; k++){
if(arr[i]%k == 0){
ll temp = sm;
temp = temp - arr[i] + (arr[i]/k);
temp = temp - arr[j] + (arr[j] * k);
if(temp < mn){
mn = temp;
}
}
}
for(int k = 1;k <= arr[j]; k++){
if(arr[j]%k == 0){
ll temp = sm;
temp = temp - arr[j] + (arr[j]/k);
temp = temp - arr[i] + (arr[i] * k);
if(temp < mn){
mn = temp;
}
}
}
}
}
cout << mn << "\n";
return;
}
int main()
{
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}