Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin ("grup.in");
- ofstream fout ("grup.out");
- struct elev {
- int absente;
- bool pA, dB;
- int idx;
- bool operator < (const elev & el) const {
- return absente < el.absente;
- }
- };
- vector <elev> v, ans;
- string s1, s2;
- int absente[100005];
- priority_queue <elev> A, B;
- bool selectati[100005];
- bool cmp (elev a, elev b)
- {
- return a.absente < b.absente;
- }
- void raspuns (int n)
- {
- int nr = 0;
- for (int i = 0; i < n; i ++) {
- if (selectati[i]) nr += absente[i];
- }
- fout << nr;
- }
- int main()
- {
- int n, s, k1, k2;
- fin >> n >> s >> k1 >> k2;
- for (int i = 0; i < n; i ++) fin >> absente[i];
- fin >> s1 >> s2;
- for (int i = 0; i < n; i ++) {
- if (s1[i] - '0' == 1 || s2[i] - '0' == 1) v.push_back({absente[i], s1[i] - '0', s2[i] - '0', i});
- }
- sort(v.begin(), v.end(), cmp);
- int N = v.size();
- for (int i = 0; i < N; i ++) {
- if (v[i].pA == 1 && v[i].dB == 0) A.push(v[i]), selectati[v[i].idx] = 1;
- }
- for (int i = 0; i < N; i ++) {
- if (v[i].pA == 0 && v[i].dB == 1) B.push(v[i]), selectati[v[i].idx] = 1;
- }
- for (int i = 0; i < N; i ++) {
- if (v[i].pA == 1 && v[i].dB == 1) {
- if (A.empty() && B.empty()) {
- selectati[v[i].idx] = 1;
- continue;
- }
- else if (A.empty()) {
- selectati[B.top().idx] = 0, B.pop(), selectati[v[i].idx] = 1;
- continue;
- }
- else if (B.empty()) {
- selectati[A.top().idx] = 0, A.pop(), selectati[v[i].idx] = 1;
- continue;
- }
- if (v[i].absente < A.top().absente + B.top().absente) {
- selectati[A.top().idx] = 0, selectati[B.top().idx] = 0, A.pop(), B.pop();
- selectati[v[i].idx] = 1;
- }
- }
- }
- int prA = 0, dusB = 0, nr = 0;
- for (int i = 0; i < N; i ++) {
- if (selectati[v[i].idx] == 1) {
- nr ++;
- if (v[i].pA) prA ++;
- if (v[i].dB) dusB ++;
- }
- }
- if (nr == s && prA == k1 && dusB == k2) raspuns(n);
- else {
- if (nr < s) {
- if (prA < k1 && dusB < k2) {
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement