A-Cabbages
# include "iostream" # include "cstdio" using namespace std; int N,A,X,Y; int main(){ scanf("%d%d%d%d",&N,&A,&X,&Y); printf("%d",N>=A?A*X+(N-A)*Y:N*X); return 0; }
B-Bouzu Mekuri
# include "iostream" # include "cstdio" using namespace std; const int maxm=1e5+10; int N; char S[maxm]; int main(){ register int i; scanf("%d",&N); scanf("%s",S+1); for(i=1;i<=N;i++){ if(S[i]=='1'){ printf("%s",i&1?"Takahashi":"Aoki"); break; } } return 0; }
C-Colorful Candies
# include "iostream" # include "algorithm" # include "cstdio" using namespace std; const int maxm=3e5+10; int N,K; int C[maxm],A[maxm],B[maxm]; int Visit[maxm]; inline int Find(int X){ register int Left=1,Right=N,Mid; while(Left<Right){ Mid=(Left+Right)>>1; if(A[Mid]>=X) Right=Mid; else Left=Mid+1; } return Left; } int main(){ register int i,Ans=0,Now=0; scanf("%d%d",&N,&K); for(i=1;i<=N;i++){ scanf("%d",&C[i]); A[i]=C[i]; } sort(A+1,A+1+N); for(i=1;i<=N;i++){ B[i]=Find(C[i]); } for(i=1;i<=N;i++){ Visit[B[i]]++; if(Visit[B[i]]==1) Now++; if(i-K>0){ Visit[B[i-K]]--; if(Visit[B[i-K]]==0) Now--; } Ans=max(Ans,Now); } printf("%d",Ans); return 0; }
D-National Railway
# include "iostream" # include "cstdio" using namespace std; const int maxm=1e3+10; int H,W; long long C; long long A[maxm][maxm]; long long DP[maxm][maxm]; int main(){ register int i,j; register long long Ans=1ll<<60; scanf("%d%d%lld",&H,&W,&C); for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ scanf("%lld",&A[i][j]); DP[i][j]=1ll<<60; } } for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ if(i!=1){ DP[i][j]=min(DP[i][j],A[i][j]+A[i-1][j]+C); DP[i][j]=min(DP[i][j],DP[i-1][j]-A[i-1][j]+A[i][j]+C); } if(j!=1){ DP[i][j]=min(DP[i][j],A[i][j-1]+A[i][j]+C); DP[i][j]=min(DP[i][j],DP[i][j-1]-A[i][j-1]+A[i][j]+C); } Ans=min(Ans,DP[i][j]); } } for(i=1;i<=(H>>1);i++){ for(j=1;j<=W;j++){ swap(A[i][j],A[H-i+1][j]); } } for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ DP[i][j]=1ll<<60; } } for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ if(i!=1){ DP[i][j]=min(DP[i][j],A[i][j]+A[i-1][j]+C); DP[i][j]=min(DP[i][j],DP[i-1][j]-A[i-1][j]+A[i][j]+C); } if(j!=1){ DP[i][j]=min(DP[i][j],A[i][j-1]+A[i][j]+C); DP[i][j]=min(DP[i][j],DP[i][j-1]-A[i][j-1]+A[i][j]+C); } Ans=min(Ans,DP[i][j]); } } printf("%lld",Ans); return 0; }
E-Ring MST
# include "algorithm" # include "iostream" # include "cstdio" using namespace std; const int maxm=1e5+10; int N,M; long long DP[maxm],Ans; struct node{ int A; long long C; # define A(x) Node[x].A # define C(x) Node[x].C }Node[maxm]; inline bool Comp(node x,node y){ return x.C<y.C; } inline long long GCD(long long X,long long Y){ return Y?GCD(Y,X%Y):X; } int main(){ register int i; scanf("%d%d",&N,&M); for(i=1;i<=M;i++) scanf("%d%lld",&A(i),&C(i)); sort(Node+1,Node+M+1,Comp); DP[0]=N; for(i=1;i<=M;i++){ DP[i]=GCD(DP[i-1],A(i)); Ans=(Ans+(DP[i-1]-DP[i])*C(i)); } printf("%lld",DP[M]==1?Ans:-1); return 0; }