Skip to content

Instantly share code, notes, and snippets.

@akhilesh-kumar-verma
Created March 17, 2024 09:56
Show Gist options
  • Save akhilesh-kumar-verma/cbd14088c239730685364e5b0e8cdd93 to your computer and use it in GitHub Desktop.
Save akhilesh-kumar-verma/cbd14088c239730685364e5b0e8cdd93 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<utility>
#include<vector>
using namespace std;
int main() {
size_t n; cin >> n;
vector<tuple<int,int, char, bool, size_t>> heros(n);
for (size_t i=0; i<n; ++i) { cin >> get<0>(heros[i]); }
for (size_t i=0; i<n; ++i) { cin >> get<1>(heros[i]); }
string str; cin >> str; for (size_t i=0; i<n; ++i) { get<2>(heros[i])=str[i]; }
for (size_t i=0; i<n; ++i) { get<3>(heros[i])=true; get<4>(heros[i])=i; }
sort(heros.begin(), heros.end());
for (size_t i=1; i<n;++i) {
for (size_t j=i-1; i<n and j>=0 and get<2>(heros[i])=='D' and get<2>(heros[j])=='R';) {
if (get<1>(heros[i])==get<1>(heros[j])) { get<3>(heros[i++])=get<3>(heros[j--])=false; continue; }
if (get<1>(heros[i])<get<1>(heros[j])) { get<3>(heros[i++])=false; get<1>(heros[j])--; }
else { get<3>(heros[j--])=false; get<1>(heros[i])--; } } }
sort(heros.begin(), heros.end(), [](tuple<int,int, char, bool, size_t> &x, tuple<int,int, char, bool, size_t> &y) {
return get<4>(x)<get<4>(y); });
for (size_t i=0; i<n; ++i) { if (get<3>(heros[i])) { cout << get<1>(heros[i]) << " " << flush; } } cout << endl;
return 0; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment