-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF.cpp
65 lines (62 loc) · 1.55 KB
/
F.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
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define Re register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define ROF(i,a,b) for(Re int i = a;i >= b;--i)
#define SFOR(i,a,b,c) for(Re int i = a;i <= b;i+=c)
#define SROF(i,a,b,c) for(Re int i = a;i >= b;i-=c)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 100000+5;
LL l[MAXN],N;
char str[MAXN];
LL ans = 0,power = 0,grass = 0;
bool water = false;
int main(){
scanf("%I64d",&N);
FOR(i,1,N) scanf("%I64d",l+i);
scanf("%s",str+1);
FOR(i,1,N){
if(str[i] == 'L'){
ans += l[i];
power -= l[i];
if(power < 0){
ans -= power * (water ? 3 : 5);
power = 0;
}
}
if(str[i] == 'W'){
water = true;
power += l[i];
ans += l[i]*3;
}
if(str[i] == 'G'){
power += l[i];
ans += l[i]*5;
grass += (l[i]<<1);
}
//DEBUG(power);
grass = std::min(grass,power);
}
//DEBUG(ans);DEBUG(power);
if(power > 0){
ans -= 4*grass/2;
ans -= 2*(power-grass)/2;
}
printf("%I64d\n",ans);
return 0;
}