-
Notifications
You must be signed in to change notification settings - Fork 3
/
A.cpp
92 lines (92 loc) · 1.41 KB
/
A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// LUOGU_RID: 158289059
//ANMHLIJKTJIY!
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,a[N],lft=0,rht=0;
bool res=true;
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll i,j,k;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
cin>>s;
k=1;
for(i=1;i<s.size();i++)
{
if(s[i]!=s[i-1])
{
k++;
}
}
j=n-k;
reverse(a,a+j);
k=0;
for(i=0;i<n;i++)
{
if(i==0||s[i]!=s[i-1])
{
cout<<a[j]<<" "<<s[i]<<endl;
if(s[i]=='L')
{
lft+=a[j];
}
else
{
rht+=a[j];
}
j++;
}
else
{
cout<<a[k]<<" ";
if(s[i]=='L')
{
if(lft>rht+a[k])
{
cout<<"R\n";
rht+=a[k];
}
else
{
cout<<"L\n";
lft+=a[k];
}
}
else
{
if(rht>lft+a[k])
{
cout<<"L\n";
lft+=a[k];
}
else
{
cout<<"R\n";
rht+=a[k];
}
}
k++;
}
}
return 0;
}