题目链接:http://codeforces.com/contest/706/problem/C
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+3;
const ll INF=1e18;
ll dp[N][2];
string a[N],b[N];
int c[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",c+i);
for(int i=0;i<n;i++)
{
cin>>a[i];
b[i]=a[i];
reverse(b[i].begin(),b[i].end());
}
for(int i=1;i<n;i++)
dp[i][0]=dp[i][1]=INF;
dp[0][1]=c[0];
int i;
for(i=1;i<n;i++)
{
if(a[i]>=a[i-1])
dp[i][0]=dp[i-1][0];
if(b[i]>=a[i-1])
dp[i][1]=dp[i-1][0]+c[i];
if(a[i]>=b[i-1])
dp[i][0]=min(dp[i][0],dp[i-1][1]);
if(b[i]>=b[i-1])
dp[i][1]=min(dp[i][1],dp[i-1][1]+c[i]);
if(dp[i][0]==INF&&dp[i][1]==INF)
break;
}
if(i==n)
printf("%I64d\n",min(dp[n-1][0],dp[n-1][1]));
else
printf("-1\n");
return 0;
}