-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2000D.cpp
More file actions
47 lines (46 loc) · 927 Bytes
/
2000D.cpp
File metadata and controls
47 lines (46 loc) · 927 Bytes
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
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> arr(n);
ll sum = 0;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum += arr[i];
}
string s;
cin >> s;
ll score = 0;
int st = 0, ed = n - 1;
while (st < ed)
{
if (s[st] == 'L' && s[ed] == 'R')
{
score += sum;
sum -= arr[st++] + arr[ed--];
}
if (s[st] != 'L')
{
sum -= arr[st];
st++;
}
if (s[ed] != 'R')
{
sum -= arr[ed];
ed--;
}
}
cout << score << '\n';
}
return 0;
}