Advertisement
Korotkodul

егэ

Sep 9th, 2022 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a){
  44.     for (auto p: a){
  45.         cout<<p.first<<' '<<p.second<<"\n";
  46.     }
  47.     cout<<"\n";
  48. }
  49.  
  50. #include <fstream>
  51.  
  52. string bin(int x){
  53.     string r="";
  54.     while (x > 0){
  55.         r += (x%2) + '0';
  56.         x/=2;
  57.     }
  58.     reverse(r.begin(), r.end());
  59.     return r;
  60. }
  61.  
  62. int ans=-1,n;
  63.  
  64. void f(vector <int> a){
  65.     vector <int> r(2);
  66.     int pf=0;
  67.     for (int i = 0; i < n; ++i){
  68.         pf += a[i];
  69.         r[a[i]%2]++;
  70.     }
  71.     if (r[0] != r[1] && r[pf%2] == max(r[0], r[1])){
  72.         ans = max(ans, pf);
  73.     }
  74. }
  75.  
  76. int main()
  77. {
  78.     ios::sync_with_stdio(0);
  79.     cin.tie(0);
  80.     cout.tie(0);
  81.  
  82.     string t;
  83.     ifstream fl("271.txt");
  84.     getline (fl, t);
  85.     n = stoi(t);
  86.     cout<<n<<"\n";
  87.     vector <pii> v;
  88.     while (getline(fl, t)){
  89.         int a,b;
  90.         int i = find(t.begin(), t.end(), ' ') - t.begin();
  91.         a = stoi(t.substr(0, i));
  92.         b = stoi(t.substr(i+1, t.size() - i));
  93.         //cout<<a<<' '<<b<<' '<<(a+b)<<"\n";
  94.         v.push_back({a,b});
  95.     }
  96.     int k;
  97.     for (int i = 0; i < pow(2, n); ++i){
  98.         t=bin(i);
  99.         vector <int> a(n);
  100.         for (int j = 0; j < n; ++j){
  101.             if (t[j] == '0'){
  102.                 a[j] = v[j].first;
  103.             }
  104.             else{
  105.                 a[j] = v[j].second;
  106.             }
  107.         }
  108.         f(a);
  109.     }
  110.     cout<<ans;
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement