Education + Jobs Hiring Website - 2025
0 like 0 dislike
436 views

in Online Assessments by Expert (139,850 points) | 436 views

1 Answer

0 like 0 dislike
#include <bits/stdc++.h>

using namespace std;

 

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

 

struct fastio

{

    fastio()

    {

        ios::sync_with_stdio(false);

        cin.tie(nullptr);

        cout.tie(nullptr);

    }

};

 

int main()

{

    fastio _;

 

    int n;

    cin >> n;

 

    vector<int> cst(n);

 

    for (int i = 0; i < n; i++)

    {

        cin >> cst[i];

    }

 

    vector<string> ftr(n);

 

    for (int i = 0; i < n; i++)

    {

        cin >> ftr[i];

    }

 

    vector<vector<int>> t(3);

 

    for (int i = 0; i < n; i++)

    {

        if (ftr[i] == "01")

        {

            t[0].push_back(cst[i]);

        }

        else if (ftr[i] == "10")

        {

            t[1].push_back(cst[i]);

        }

        else if (ftr[i] == "11")

        {

            t[2].push_back(cst[i]);

        }

    }

 

    sort(t[0].begin(), t[0].end());

    sort(t[1].begin(), t[1].end());

    sort(t[2].begin(), t[2].end());

 

    int m = min((int)t[0].size(), (int)t[1].size());

 

    vector<int> p;

 

    for (int i = 0; i < m; i++)

    {

        p.push_back(t[0][i] + t[1][i]);

    }

 

    int r = t[2].size();

 

    for (int i = 0; i < r; i++)

    {

        p.push_back(t[2][i]);

    }

 

    sort(p.begin(), p.end());

 

    int q = p.size();

 

    for (int i = 1; i < q; i++)

    {

        p[i] += p[i - 1];

    }

 

    p.resize(n, -1);

 

    for (int i = 0; i < n; i++)

    {

        cout << p[i] << ' ';

    }

 

    cout << endl;

 

    return 0;

}
ago by (140 points)