Skip to content

Instantly share code, notes, and snippets.

@qjatn0120
Created November 21, 2022 17:44
Show Gist options
  • Save qjatn0120/bd6ab1391b10a2dde8ce18fcba7f3ef0 to your computer and use it in GitHub Desktop.
Save qjatn0120/bd6ab1391b10a2dde8ce18fcba7f3ef0 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
int t, n, arr[MX];
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
cin >> t;
while(t--){
cin >> n;
for(int i = 0; i < n; i++) cin >> arr[i];
int idx = max_element(arr, arr + n) - arr;
int num = 0;
for(int i = 0; i < n; i++){
if(idx == i) continue;
num = max(num, arr[i]);
}
for(int i = 0; i < n; i++){
if(i == idx) cout << (arr[i] - num) << " ";
else cout << (arr[i] - arr[idx]) << " ";
}
cout << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment