Monday, August 8, 2016

Codeforces 703B Mishka and trip

Unknown
#include<cstdio>
#include<string.h>
using namespace std;
typedef long long unsigned int llu;

int main()
{
    int n,k;
    while (scanf("%d%d",&n,&k)!=EOF)
    {
        int c[n+1];
        int d[k];
        bool cap[n+1];
        memset(cap,false,sizeof(cap));
        llu sum=0,ans=0;
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&c[i]);
            sum+=c[i];
        }
        for (int i=0;i<k;i++)
        {
            scanf("%d",&d[i]);
            cap[d[i]]=true;
        }
        for (int i=0;i<k;i++)
        {
            ans+=c[d[i]]*(sum-c[d[i]]);
            sum-=c[d[i]];
        }
        for (int i=1;i<n;i++)
            if (!cap[i] && !cap[i+1])
                ans+=c[i]*c[i+1];
        if (!cap[1] && !cap[n])
            ans+=c[1]*c[n];
        printf("%llu\n",ans);
    }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,