Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- vector<ll> arr(n);
- vector<ll> brr(n);
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- for (int i = 0; i < n; i++) {
- cin >> brr[i];
- }
- if (n == 1) {
- if (arr[0] >= brr[0]) {
- cout << arr[0] - brr[0] << endl;
- return 0;
- } else {
- cout << -1 << endl;
- return 0;
- }
- }
- ll dlt = n - 2;
- ll sum1 = accumulate(all(arr), 0LL);
- ll sum2 = accumulate(all(brr), 0LL);
- if (n == 2) {
- if (sum1 != sum2) {
- cout << -1 << endl;
- return 0;
- } else {
- cout << max(arr[0] - brr[0], 0LL) << ' ' << max(arr[1] - brr[1], 0LL) << endl;
- return 0;
- }
- }
- if (sum2 < sum1 || (sum2 - sum1) % dlt != 0) {
- cout << -1 << endl;
- return 0;
- }
- ll countOfTabs = (sum2 - sum1) / dlt;
- for (int i = 0; i < n; i++) {
- arr[i] += countOfTabs;
- }
- vector<ll> ans(n, 0);
- for (int i = 0; i < n; i++) {
- if (arr[i] > brr[i]) {
- ll curDelta = arr[i] - brr[i];
- if (curDelta & 1) {
- cout << -1 << endl;
- return 0;
- }
- countOfTabs -= (arr[i] - brr[i]) / 2;
- ans[i] = (arr[i] - brr[i]) / 2 ;
- } else if (arr[i] < brr[i]) {
- cout << -1 << endl;
- return 0;
- }
- }
- if (countOfTabs != 0) {
- cout << -1 << endl;
- return 0;
- } else {
- for (auto& val : ans) {
- cout << val << ' ';
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment