A. New Year and the Christmas Ornament
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Alice and Bob are decorating a Christmas Tree.
Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue ornaments and r red ornaments.
In Bob’s opinion, a Christmas Tree will be beautiful if:
the number of blue ornaments used is greater by exactly 1than the number of yellow ornaments, and the number of red ornaments used is greater by exactly 1than the number of blue ornaments. That is, if they have 8yellow ornaments, 13blue ornaments and 9red ornaments, we can choose 4yellow, 5blue and 6red ornaments (5=4+1 and 6=5+1).Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob’s opinion.
In the example two paragraphs above, we would choose
7yellow, 8blue and 9
red ornaments. If we do it, we will use 7+8+9=24ornaments. That is the maximum number.Since Alice and Bob are busy with preparing food to the New Year’s Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree! It is guaranteed that it is possible to choose at least 6(1+2+3=6) ornaments.
Input
The only line contains three integers y, b, r(1≤y≤100, 2≤b≤100, 3≤r≤100) — the number of yellow, blue and red ornaments.
It is guaranteed that it is possible to choose at least
6(1+2+3=6) ornaments.
Output
Print one number — the maximum number of ornaments that can be used.
Examples
Input
Copy
8 13 9
Output
Copy
24
Input
Copy
13 3 6
Output
Copy
9
Note
In the first example, the answer is
7+8+9=24
In the second example, the answer is
2+3+4=9
.
题解:找出黄蓝红中最小的一个,进行分类,当黄为最小是,检测红是否大于等于2。
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int i,j,k,n,num=0,min=100,sum=0;
int a[3];
for(i=0;i<3;i++)
{
cin>>a[i];
if(a[i]<=min)
{
min=a[i];
num=i;
}
}
if(num==0)
{
if((a[num]+2)<=a[2])
{
sum=a[0]*3+3;
}
else
{
sum=a[2]*3-3;
}
}
if(num==1)
{
sum=a[1]*3;
}
if(num==2)
{
sum=a[2]*3-3;
}
cout<<sum<<'\n';
return 0;
}