SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     long long int n = 0;
  10.     cin >> n;
  11.  
  12.     long long int step = (n - 2) > 0 ? n - 2 : 1;
  13.     vector<long long int> in(n);
  14.     vector<long long int> to(n);
  15.     vector<long long int> temp(n);
  16.     long long int Sum = 0;
  17.     long long int Steps = 0;
  18.  
  19.     for (auto& item : in) {
  20.         cin >> item;
  21.     }
  22.     for (auto& item : to) {
  23.         cin >> item;
  24.     }
  25.  
  26.     for (int i = 0; i < n; ++i) {
  27.         Sum += (to[i] - in[i]);
  28.         temp[i] = in[i] - to[i];
  29.     }
  30.  
  31.     if (to == in) {
  32.         for (int i = 0; i < n; ++i) {
  33.             cout << 0 << " ";
  34.         }
  35.     }
  36.     else if (n == 1 && in[0] >= to[0]) {
  37.         cout << in[0] - to[0];
  38.     }
  39.     else if ((n == 2 && Sum == 0) || (Sum > 0 && Sum % step == 0)) {
  40.         Sum == 0 ? Steps = abs(to[0] - in[0]) : Steps = Sum / step;
  41.         for (int i = 0; i < n; ++i) {
  42.             cout << (temp[i] + Steps) / 2 << " ";
  43.         }
  44.     }
  45.     else {
  46.         cout << "-1";
  47.     }
  48.  
  49.  
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top