Advertisement
Ankit_132

C

Jun 27th, 2024
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5.  
  6. signed main() {
  7.   int t;
  8.   cin >> t;
  9.   while (t--) {
  10.     int n;
  11.     cin >> n;
  12.     vector<int> a(n), b(n);
  13.     for (int i = 0; i < n; i++) {
  14.         cin >> a[i];
  15.     }
  16.     for (int i = 0; i < n; i++) {
  17.         cin >> b[i];
  18.     }
  19.     int sa = 0, sb = 0, pos = 0, neg = 0;
  20.     for (int i = 0; i < n; i++) {
  21.         if (a[i] == 1 && b[i] == 1) pos++;
  22.         else if (a[i] == -1 && b[i] == -1) neg++;
  23.         else {
  24.             if (a[i] >= b[i]) {
  25.                 sa += a[i];
  26.             } else {
  27.                 sb += b[i];
  28.             }
  29.         }
  30.     }
  31.     while (pos--) {
  32.         if (sa <= sb) sa++;
  33.         else sb++;
  34.     }
  35.     while (neg--) {
  36.         if (sa <= sb) sb--;
  37.         else sa--;
  38.     }
  39.     cout << min(sa, sb) << "\n";
  40.   }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement