#include<iostream>
using namespace std;
const int MAX_N = 100;
int max(int x,int y);
int main()
{
int n, a[MAX_N], ans = 0,x;//ans是组成三角形的情况,n是边数
cin >> n ;
for ( x= 0; x < n; x++)
cin >> a[x];
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
for (int k = j + 1; k < n; k++)
{
int len = a[i] + a[j] + a[k];
int ma = max(a[i], max(a[j],a[k]));//最长棍子的长度
int rest = len - ma;//其余两根棍子的长度之和
if (ma < rest)
{
ans = max(ans, len);
}
}
}
}
cout << ans;
return 0;
}
int max(int x,int y )
{
if (x > y)
return x;
else
return y;
}
网友评论