diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-06-29 21:03:53 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-06-29 21:03:53 +0200 |
| commit | 37b7e815612dec5655d2ee2363835e2075701ae6 (patch) | |
| tree | 5c0b5e5fcf0c383c0e63c5c86524334630b35139 /codechef/EvenEqualOdd/main.cpp | |
| parent | 1b8f7c9d4eb8b767d32dbbbfd96662b73c037627 (diff) | |
| download | competitive-programming-37b7e815612dec5655d2ee2363835e2075701ae6.tar.xz competitive-programming-37b7e815612dec5655d2ee2363835e2075701ae6.zip | |
Solved the first 6 problems of codechef Starters
Diffstat (limited to 'codechef/EvenEqualOdd/main.cpp')
| -rw-r--r-- | codechef/EvenEqualOdd/main.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/codechef/EvenEqualOdd/main.cpp b/codechef/EvenEqualOdd/main.cpp new file mode 100644 index 0000000..9880c37 --- /dev/null +++ b/codechef/EvenEqualOdd/main.cpp @@ -0,0 +1,47 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n; + cin >> n; + vector<int> v(n * 2); + vector<int> even; + int ev = 0; + int odd = 0; + for(int &x : v) { + cin >> x; + ev += (x % 2 == 0); + odd += (x % 2 != 0); + if(x % 2 == 0) { + even.push_back(x); + } + } + vector<int> op; + for(int i = 0; i < even.size(); i++) { + int count = 1; + while((even[i] / 2 % 2) != 1) { + count++; + even[i] /= 2; + } + op.push_back(count); + } + sort(op.begin(), op.end()); + if(ev == odd) { + cout << 0 << endl; + } else if(ev > odd){ + int ans = 0; + for(int i = 0; i < (ev - odd) / 2; i++) { + ans += op[i]; + } + cout << ans << endl; + } else { + cout << abs(ev - odd) / 2 << endl; + } + } +} |
