Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin ("grup.in");
  6. ofstream fout ("grup.out");
  7.  
  8. struct elev {
  9.     int absente;
  10.     bool pA, dB;
  11.     int idx;
  12.     bool operator < (const elev & el) const {
  13.         return absente < el.absente;
  14.     }
  15. };
  16.  
  17. vector <elev> v, ans;
  18. string s1, s2;
  19. int absente[100005];
  20. priority_queue <elev> A, B;
  21. bool selectati[100005];
  22.  
  23. bool cmp (elev a, elev b)
  24. {
  25.     return a.absente < b.absente;
  26. }
  27.  
  28. void raspuns (int n)
  29. {
  30.     int nr = 0;
  31.     for (int i = 0; i < n; i ++) {
  32.         if (selectati[i]) nr += absente[i];
  33.     }
  34.     fout << nr;
  35. }
  36.  
  37. int main()
  38. {
  39.     int n, s, k1, k2;
  40.     fin >> n >> s >> k1 >> k2;
  41.     for (int i = 0; i < n; i ++) fin >> absente[i];
  42.     fin >> s1 >> s2;
  43.     for (int i = 0; i < n; i ++) {
  44.         if (s1[i] - '0' == 1 || s2[i] - '0' == 1) v.push_back({absente[i], s1[i] - '0', s2[i] - '0', i});
  45.     }
  46.     sort(v.begin(), v.end(), cmp);
  47.     int N = v.size();
  48.     for (int i = 0; i < N; i ++) {
  49.         if (v[i].pA == 1 && v[i].dB == 0) A.push(v[i]), selectati[v[i].idx] = 1;
  50.     }
  51.     for (int i = 0; i < N; i ++) {
  52.         if (v[i].pA == 0 && v[i].dB == 1) B.push(v[i]), selectati[v[i].idx] = 1;
  53.     }
  54.     for (int i = 0; i < N; i ++) {
  55.         if (v[i].pA == 1 && v[i].dB == 1) {
  56.             if (A.empty() && B.empty()) {
  57.                 selectati[v[i].idx] = 1;
  58.                 continue;
  59.             }
  60.             else if (A.empty()) {
  61.                 selectati[B.top().idx] = 0, B.pop(), selectati[v[i].idx] = 1;
  62.                 continue;
  63.             }
  64.             else if (B.empty()) {
  65.                 selectati[A.top().idx] = 0, A.pop(), selectati[v[i].idx] = 1;
  66.                 continue;
  67.             }
  68.             if (v[i].absente < A.top().absente + B.top().absente) {
  69.                 selectati[A.top().idx] = 0, selectati[B.top().idx] = 0, A.pop(), B.pop();
  70.                 selectati[v[i].idx] = 1;
  71.             }
  72.         }
  73.     }
  74.     int prA = 0, dusB = 0, nr = 0;
  75.     for (int i = 0; i < N; i ++) {
  76.         if (selectati[v[i].idx] == 1) {
  77.             nr ++;
  78.             if (v[i].pA) prA ++;
  79.             if (v[i].dB) dusB ++;
  80.         }
  81.     }
  82.     if (nr == s && prA == k1 && dusB == k2) raspuns(n);
  83.     else {
  84.         if (nr < s) {
  85.             if (prA < k1 && dusB < k2) {
  86.  
  87.             }
  88.         }
  89.     }
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement