五一训练礼包B-2
You are given two sequences a1,a2,…,ana1,a2,…,an and b1,b2,…,bnb1,b2,…,bn. Each element of both sequences is either 00, 11 or 22. The number of elements 00, 11, 22 in the sequence aa is x1x1, y1y1, z1z1 respectively, and the number of elements 00, 11, 22 in the sequence bb is x2x2, y2y2, z2z2 respectively.
You can rearrange the elements in both sequences aa and bb however you like. After that, let's define a sequence cc as follows:
Ci={
ai bi ,ai>bi;
0 ,ai=bi;
-ai bi ,ai<bi;
}
You'd like to make ∑ni=1ci∑i=1nci (the sum of all elements of the sequence cc) as large as possible. What is the maximum possible sum?
由于只有0,1,2,ci的取值只有2,0,-2三个值。
1.ci=2时,ai=2(z1),bi=1(y2);
2.ci=-2时,ai=1(y1),bi=2(z2);
3.其余ci=0;
使分最高,则“1”要多,“2”要少。
#include<stdio.h> int main(){ int t,x1,y1,z1,x2,y2,z2,two,ftwo; scanf("%d",&t); while(t--){ scanf("%d %d %d %d %d %d",&x1,&y1,&z1,&x2,&y2,&z2); if(z1>y2) two = y2; else two = z1; y2-=two; z1-=two; if(y1-x2-y2>0) ftwo=y1-x2-y2; else ftwo=0; printf("%d\n",2*(two-ftwo)); } return 0; }
posted on 2021-05-05 21:03 wvellichor 阅读(24) 评论(0) 编辑 收藏 举报