# Codeforces Round #386 (Div. 2)

/Tag: Codeforces Round #386 (Div. 2)

## Codeforces Round #386 (Div. 2), problem: (G) New Roads Solution in C/C++

By |2017-04-07T22:11:46+06:00January 6th, 2017|Categories: C/C++, Programming||

Codeforces Round #386 (Div. 2), problem: (G) New Roads Solution in C/C++ #include<stdio.h> #include<stdlib.h> typedef unsigned u; u D[222222],H[222222],P[222222],A[222222]; int main() { u n,d,x,i=-1,j,k,mi=0,ma=1; for(scanf("%u%u%u",&n,&d,&x);++i<d;)scanf("%u",D+i); for(i=d;i--;ma+=D[i]-1)if(D[i]>D[i+1])mi+=D[i]-D[i+1]; if(x<mi||x>ma){printf("-1\n");return 0;} for(A[i=0]=2;i++<d;)A[i]=A[i-1]+D[i-1]; for(i=1;++i<A[1];)P[i]=1; for(i=0;++i<d;) { k=D[i-1]-1; if(k>D[i]-1)k=D[i]-1; j=ma-x; if(j>k)j=k; ma-=j; j=A[i]-1-j; for(k=A[i]-1;++k<A[i+1];) { P[k]=j; if(j+1<A[i])++j; } } [...]

## Codeforces Round #386 (Div. 2), problem: (F) Music in Car Solution in C/C++

By |2017-04-07T22:11:46+06:00January 6th, 2017|Categories: C/C++, Programming||

Codeforces Round #386 (Div. 2), problem: (F) Music in Car Solution in C/C++   #include <stdio.h> #include <string.h> #define MAX(X,Y) ((X)>(Y) ? (X) : (Y)) int n,w,k,a[200010],t[200010],sz[2],heap[2][200010],ind[200010],pos[200010]; void push(int k,int opt); int pop(int opt); void del(int u,int opt); void up(int u,int opt); void down(int [...]

## Codeforces Round #386 (Div. 2), problem: (E) Numbers Exchange Solution in C/C++

By |2017-04-07T22:11:46+06:00January 6th, 2017|Categories: C/C++, Programming||

Codeforces Round #386 (Div. 2), problem: (E) Numbers Exchange Solution in C/C++     #include<stdio.h> #include<stdlib.h> typedef unsigned u; u N[222222],X[222222],C[222222],H[222222]; int F(const void*x,const void*y) { if(N[*(u*)x]>N[*(u*)y])return 1; if(N[*(u*)x]<N[*(u*)y])return-1; return 0; } int main() { u n,m,i,o,e,h,os=1,es=2,g=0; scanf("%u%u",&n,&m);h=n>>1; if(n&1){printf("-1\n");return 0;} for(i=-1;++i<n;X[i]=i)scanf("%u",N+i); qsort(X,n,sizeof(u),F); for(i=o=e=0;++i<n;)if(N[X[i]]==N[X[i-1]])C[X[i]]=1; for(i=n;i--;)if(!C[X[i]]) [...]

## Codeforces Round #386 (Div. 2), problem: (C) Tram Solution in C/C++

By |2017-04-07T22:11:46+06:00January 6th, 2017|Categories: C/C++, Programming||

Codeforces Round #386 (Div. 2), problem: (C) Tram Solution in C/C++ #include<stdio.h> typedef unsigned u; u x1,x2,s; u F(u p,u d,u k) { if(k==2)return-1; if(!p&&d==-1u)return F(p,-d,k); if(p==s&&d==1)return F(p,-d,k); if(k==1&&p==x2)++k; if(k==0&&p==x1)++k; return 1+F(p+d,d,k); } int main() { u t1,t2,p,d,a,b; scanf("%u%u%u%u%u%u%u",&s,&x1,&x2,&t1,&t2,&p,&d); a=F(p,d,0)*t1; b=(x1>x2?x1-x2:x2-x1)*t2; printf("%u\n",a>b?b:a); return 0; [...]

## Codeforces Round #386 (Div. 2), problem: (B) Decoding Solution in C/C++

By |2017-01-06T18:14:38+06:00January 6th, 2017|Categories: Blog, C/C++||

Codeforces Round #386 (Div. 2), problem: (B) Decoding Solution in C/C++   #include<stdio.h> int main(){ int n,i;char a[2001]; scanf("%d",&n); scanf("%s",a); n-=1; for(i=n-1;i>=0;i-=2) { printf("%c",a[i]); } if(n%2==0) i=0; else i=1; for(i;i<=n;i+=2) printf("%c",a[i]); return 0; }

## Codeforces Round #386 (Div. 2), problem: (A) Compote Solution in C/C++

By |2017-04-07T22:11:46+06:00January 6th, 2017|Categories: C/C++, Programming||

Codeforces Round #386 (Div. 2), problem: (A) Compote Solution in C/C++ #include<stdio.h> int main() { int a,b,c,i; scanf("%d%d%d",&a,&b,&c); for(i=a;i>=1;i--) if(b>=2*i&&c>=4*i) break; printf("%d",7*i); }