Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- #include <fstream>
- string bin(int x){
- string r="";
- while (x > 0){
- r += (x%2) + '0';
- x/=2;
- }
- reverse(r.begin(), r.end());
- return r;
- }
- int ans=-1,n;
- void f(vector <int> a){
- vector <int> r(2);
- int pf=0;
- for (int i = 0; i < n; ++i){
- pf += a[i];
- r[a[i]%2]++;
- }
- if (r[0] != r[1] && r[pf%2] == max(r[0], r[1])){
- ans = max(ans, pf);
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string t;
- ifstream fl("271.txt");
- getline (fl, t);
- n = stoi(t);
- cout<<n<<"\n";
- vector <pii> v;
- while (getline(fl, t)){
- int a,b;
- int i = find(t.begin(), t.end(), ' ') - t.begin();
- a = stoi(t.substr(0, i));
- b = stoi(t.substr(i+1, t.size() - i));
- //cout<<a<<' '<<b<<' '<<(a+b)<<"\n";
- v.push_back({a,b});
- }
- int k;
- for (int i = 0; i < pow(2, n); ++i){
- t=bin(i);
- vector <int> a(n);
- for (int j = 0; j < n; ++j){
- if (t[j] == '0'){
- a[j] = v[j].first;
- }
- else{
- a[j] = v[j].second;
- }
- }
- f(a);
- }
- cout<<ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement