Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- #include<iomanip>
- using namespace std;
- int n, t, I, totalsum;
- vector<int> a, b;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(0);
- cin >> t;
- for (I = 0; I < t; I++) {
- cin >> n;
- a.resize(n);
- b.resize(n);
- totalsum = 0;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- totalsum += a[i];
- b[i] = a[i];
- }
- reverse(b.begin(), b.end());
- bool fl = 1;
- for (int i = 0; i < n; i++) {
- if (totalsum - a[i] != 0 && abs(a[i] - totalsum) + (n-1) * abs(a[i]) <= 1e9) {
- for (int j = 0; j < n; j++) {
- if (j == i) {
- cout << -1 * (totalsum - a[i]) << " ";
- }
- else {
- cout << a[i] << " ";
- }
- }
- cout << "\n";
- fl = 0;
- break;
- }
- }
- if (fl) {
- if (n % 2 == 0) {
- for (int i = 0; i < n; i++) {
- if (i < n / 2) {
- cout << -1 * b[i] << " ";
- }
- else {
- cout << b[i] << " ";
- }
- }
- }
- else {
- for (int i = 0; i < n; i++) {
- if (i == n / 2 - 1) {
- if (a[i] <= a[i + 1] && a[i] <= a[i + 2]) {
- cout << -1 * (a[i + 1] + a[i + 2]) << " " << a[i] << " " << a[i] << " ";
- }else if (a[i+1] <= a[i] && a[i + 1] <= a[i + 2]) {
- cout << a[i+1] << " " << -1 * (a[i] + a[i+2]) << " " << a[i + 1] << " ";
- }
- else {
- cout << a[i + 2] << " " << a[i + 2] << " " << -1 * (a[i + 1] + a[i]) << " ";
- }
- i+=2;
- continue;
- }
- if (i < n / 2) {
- cout << -1 * b[i] << " ";
- }
- else {
- cout << b[i] << " ";
- }
- }
- }
- cout << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement