Easy O(n)
\n# Code\ncpp []\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nums2) {\n       ios::sync_with_stdio(false);\n       cin.tie
\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nums2) {\n       ios::sync_with_stdio(false);\n       cin.tie(nullptr);\n       cout.tie(nullptr);\n        long long s1 = accumulate(nums1.begin(),nums1.end(), 0LL);\n         long long s2 = accumulate(nums2.begin(),nums2.end(),0LL);\n\n            long long z1=0,z2=0;\n\n            for(long long it:nums1){\n                if(it == 0)\n                z1++;\n\n            }\n\n        for(long long it : nums2){\n            if(it == 0)\n            z2++;\n        }\n\n        if(s1 == s2){\n            if(z1 == z2){\n                return s1 + z1;\n            }\n\n            else{\n                if(z1==0 || z2 ==0){\n                    return -1;\n\n                }\n\n                else{\n                    return max(s1+z1, s2+z2);\n                }\n            }\n        }\n\n        if(s2 > s1){\n       long long s3 = s1;\n            s1 = s2;\n            s2 = s3;\n\n     long long z3 = z1;\n            z1 = z2;\n            z2 = z3;\n        }\n            if(z1 == 0){\n                if(z2==0)\n                return -1;\n\n                if(s2 + z2 > s1){\n                    return -1;\n                }\n\n                else{\n                    return s1;\n                }\n            }\n\n            else if(z2!=0){\n                return max(s1+z1 , s2+z2);\n            }\n\n        \nreturn -1;\n\n    }\n};\n```
['C++']