Advertisement
bibaboba12345

ЕБАНАЯ D

Oct 24th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <cmath>
  6. #include<iomanip>
  7. using namespace std;
  8.  
  9. int n, t, I, totalsum;
  10. vector<int> a, b;
  11.  
  12.  
  13. int main()
  14. {
  15. ios::sync_with_stdio(false);
  16. cin.tie(0);
  17. cin >> t;
  18. for (I = 0; I < t; I++) {
  19. cin >> n;
  20. a.resize(n);
  21. b.resize(n);
  22. totalsum = 0;
  23. for (int i = 0; i < n; i++) {
  24. cin >> a[i];
  25. totalsum += a[i];
  26. b[i] = a[i];
  27. }
  28. reverse(b.begin(), b.end());
  29. bool fl = 1;
  30. for (int i = 0; i < n; i++) {
  31. if (totalsum - a[i] != 0 && abs(a[i] - totalsum) + (n-1) * abs(a[i]) <= 1e9) {
  32. for (int j = 0; j < n; j++) {
  33. if (j == i) {
  34. cout << -1 * (totalsum - a[i]) << " ";
  35. }
  36. else {
  37. cout << a[i] << " ";
  38. }
  39. }
  40. cout << "\n";
  41. fl = 0;
  42. break;
  43. }
  44. }
  45. if (fl) {
  46. if (n % 2 == 0) {
  47. for (int i = 0; i < n; i++) {
  48. if (i < n / 2) {
  49. cout << -1 * b[i] << " ";
  50. }
  51. else {
  52. cout << b[i] << " ";
  53. }
  54. }
  55. }
  56. else {
  57. for (int i = 0; i < n; i++) {
  58. if (i == n / 2 - 1) {
  59. if (a[i] <= a[i + 1] && a[i] <= a[i + 2]) {
  60. cout << -1 * (a[i + 1] + a[i + 2]) << " " << a[i] << " " << a[i] << " ";
  61. }else if (a[i+1] <= a[i] && a[i + 1] <= a[i + 2]) {
  62. cout << a[i+1] << " " << -1 * (a[i] + a[i+2]) << " " << a[i + 1] << " ";
  63. }
  64. else {
  65. cout << a[i + 2] << " " << a[i + 2] << " " << -1 * (a[i + 1] + a[i]) << " ";
  66. }
  67. i+=2;
  68. continue;
  69. }
  70. if (i < n / 2) {
  71. cout << -1 * b[i] << " ";
  72. }
  73. else {
  74. cout << b[i] << " ";
  75. }
  76.  
  77. }
  78.  
  79. }
  80. cout << "\n";
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement