#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; }
Monday, August 8, 2016
Published August 08, 2016 by Sourav Chowdhury with 0 comment
Published August 08, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> using namespace std; int main() { int n; while (scanf("%d",&n)!=EOF) { for (int i=1;i<=n;i++) { if (i%2) printf("I hate "); else printf("I love "); if (i==n) printf("it\n"); else printf("that "); } } return 0; }
Published August 08, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cmath> using namespace std; int main() { int n; while (scanf("%d",&n)!=EOF) { int a,temp=0; while (n--) { scanf("%d",&a); temp=(temp+a-1)%2; if (temp) printf("1\n"); else printf("2\n"); } } return 0; }
Saturday, August 6, 2016
Published August 06, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cstring> #include<list> using namespace std; int main() { char s[100001]; while (gets(s)) { list <char> l; list <char> ::iterator it=l.begin(); int len=strlen(s); for (int i=0;i<len;i++) { if (s[i]=='[') it =l.begin(); else if (s[i]==']') it =l.end(); else l.insert(it,s[i]); } for (it=l.begin();it!=l.end();it++) printf("%c",*it); printf("\n"); } return 0; }
Tuesday, August 2, 2016
Published August 02, 2016 by Sourav Chowdhury with 0 comment
#include<iostream> #include<cstdio> #include<string> #include<algorithm> using namespace std; int main() { int n; while (scanf("%d",&n)!=EOF) { getchar(); string s[n]; for (int i=0;i<n;i++) cin>>s[i]; sort (s,s+n); int len[n],max=0; for (int i=0;i<n;i++) { len[i]=s[i].size(); if (max<len[i]) max=len[i]; } int col=62/(max+2); int row=n/col+(n%col>0); for (int i=0;i<60;i++) printf("-"); printf("\n"); for (int i=0;i<row;i++) { for (int j=i;j<n;) { cout<<s[j]; int l=max-len[j]; while (l--) printf(" "); j+=row; if (j<n) printf(" "); } printf("\n"); } } return 0; }
Monday, August 1, 2016
Published August 01, 2016 by Sourav Chowdhury with 0 comment
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; int main() { while(1) { char s[55]; gets(s); if(s[0] == '#') break; if (!next_permutation(s,s+strlen(s))) { puts("No Successor"); continue; } puts(s); } return 0; }
Published August 01, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<bitset> using namespace std; long convert_endian(long x){ bitset<32> b(x); long res = 0; for (int j=0; j<32; j++) if (b[j]) res |= 1<<(3-j/8)*8+(j%8); return res; } int main(){ long x; while(scanf("%ld", &x)==1) printf("%ld converts to %ld\n", x, convert_endian(x)); return 0; }
Subscribe to:
Posts (Atom)